Created
May 1, 2022 03:00
-
-
Save comdet/441591ec39327a6611fbd9b68d381549 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=4 | |
//Original Script > @DonovanWall | |
// Actual Version > @guikroth | |
// EDIT > @comdet | |
strategy(title="RFF Gambling", overlay=false) | |
// ==== for Range Filter ====// | |
startDate = input(title="Start Date", type=input.integer, | |
defval=1, minval=1, maxval=31) | |
startMonth = input(title="Start Month", type=input.integer, | |
defval=1, minval=1, maxval=12) | |
startYear = input(title="Start Year", type=input.integer, | |
defval=2022, minval=1800, maxval=2100) | |
afterStartDate = (time >= timestamp(syminfo.timezone, | |
startYear, startMonth, startDate, 0, 0)) | |
// Source | |
src = input(defval=close, title="Source", group="Range Filter") | |
// Sampling Period | |
// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters | |
per = input(defval=100, minval=1, title="Sampling Period", group="Range Filter") | |
// Range Multiplier | |
mult = input(defval=3.0, minval=0.1, title="Range Multiplier", group="Range Filter") | |
// ==== for MACD 4C ==== // | |
// MACD 4C | |
fastMA = input(title="Fast moving average", defval = 12, minval = 7, group="MACD 4C Filter") | |
slowMA = input(title="Slow moving average", defval = 26, minval = 7, group="MACD 4C Filter") | |
// ==== for TSD ==== // | |
// ################## Range Filter ###################// | |
// Smooth Average Range | |
smoothrng(x, t, m) => | |
wper = t * 2 - 1 | |
avrng = ema(abs(x - x[1]), t) | |
smoothrng = ema(avrng, wper) * m | |
smoothrng | |
smrng = smoothrng(src, per, mult) | |
// Range Filter | |
rngfilt(x, r) => | |
rngfilt = x | |
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r : | |
x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r | |
rngfilt | |
filt = rngfilt(src, smrng) | |
// Filter Direction | |
upward = 0.0 | |
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1]) | |
downward = 0.0 | |
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1]) | |
// Target Bands | |
hband = filt + smrng | |
lband = filt - smrng | |
// Colors | |
filtcolor = upward > 0 ? color.lime : downward > 0 ? color.red : color.orange | |
barcolor = src > filt and src > src[1] and upward > 0 ? color.lime : | |
src > filt and src < src[1] and upward > 0 ? color.green : | |
src < filt and src < src[1] and downward > 0 ? color.red : | |
src < filt and src > src[1] and downward > 0 ? color.maroon : color.orange | |
filtplot = plot(filt, color=filtcolor, linewidth=3, title="Range Filter") | |
// // Target | |
hbandplot = plot(hband, color=color.aqua, transp=10, title="High Target") | |
lbandplot = plot(lband, color=color.fuchsia, transp=10, title="Low Target") | |
// Fills | |
//fill(hbandplot, filtplot, color=color.aqua, title="High Target Range") | |
//fill(lbandplot, filtplot, color=color.fuchsia, title="Low Target Range") | |
// Bar Color | |
barcolor(barcolor) | |
// MACD | |
[currMacd,_,_] = macd(close[0], fastMA, slowMA, 9) | |
// Break Outs | |
longCond = bool(na) | |
shortCond = bool(na) | |
longCond := src > filt and src > src[1] and upward > 0 or src > filt and src < src[1] and upward > 0 | |
shortCond := src < filt and src < src[1] and downward > 0 or src < filt and src > src[1] and downward > 0 | |
//plot(filt, color=color.green, transp=0, title="High Target") | |
CondIni = 0 | |
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1] | |
longCondition = longCond and CondIni[1] == -1 | |
shortCondition = shortCond and CondIni[1] == 1 | |
//// Indicators | |
// MFI | |
mfi_upper = sum(volume * (change(hlc3) <= 0 ? 0 : hlc3), 58) | |
mfi_lower = sum(volume * (change(hlc3) >= 0 ? 0 : hlc3), 58) | |
_mfi_rsi(mfi_upper, mfi_lower) => | |
if mfi_lower == 0 | |
100 | |
if mfi_upper == 0 | |
0 | |
100.0 - (100.0 / (1.0 + mfi_upper / mfi_lower)) | |
mf = _mfi_rsi(mfi_upper, mfi_lower) | |
mfi = (mf - 50) * 3 | |
//// Plots | |
mfi_color = mfi > 0 ? #4CAF50 : #FF5252 | |
//plot(mfi, "MFI Line", style=plot.style_line, color=mfi_color, linewidth = 2) | |
//Alerts | |
//plotshape(longCondition, title="Buy Signal", text="BUY", textcolor=color.black, style=shape.labelup, size=size.normal, location=location.belowbar, color=color.green, transp=70) | |
//plotshape(shortCondition, title="Sell Signal", text="SELL", textcolor=color.black, style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.red, transp=70) | |
buysignal = afterStartDate and ((longCondition and currMacd > 0 and mfi > 0) or (longCond and currMacd[0] > 0 and currMacd[1] < 0 and mfi > 0) or (longCond and currMacd > 0 and mfi[0] > 0 and mfi[1] < 0)) | |
sellsignal = afterStartDate and ((shortCondition and currMacd < 0 and mfi < 0) or (shortCond and currMacd[0] < 0 and currMacd[1] > 0 and mfi < 0) or (shortCond and currMacd < 0 and mfi[0] < 0 and mfi[1] > 0)) | |
plotshape(buysignal, title="Buy Signal", text="BUY", textcolor=color.white, style=shape.labelup, size=size.normal, location=location.belowbar, color=color.green, transp=0) | |
plotshape(sellsignal, title="Sell Signal", text="SELL", textcolor=color.white, style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.red, transp=0) | |
//plotshape(longCondition and currMacd > 0, style=shape.triangleup) | |
//plotshape(shortCondition and currMacd < 0, style=shape.triangledown) | |
//For use like Strategy, | |
//1. Change the word "study" for "strategy" at the top | |
//2. Remove the "//" below | |
var float long_tp = 0.0 | |
var float long_sl = 0.0 | |
var float short_tp = 0.0 | |
var float short_sl = 0.0 | |
if afterStartDate and longCondition and currMacd > 0 and mfi > 0 | |
long_tp := close + (abs(close - lband) * 1) | |
long_sl := close - (abs(close - lband) * 1) | |
strategy.entry( id = "Long", long = true, comment = "tp="+tostring(long_tp,".#") + "\nsl=" + tostring(long_sl,".##") + "\nop=" + tostring(open,".#") + "\ncl=" + tostring(close,".#")) | |
if afterStartDate and longCond and currMacd[0] > 0 and currMacd[1] < 0 and mfi > 0 | |
long_tp := close + (abs(close - lband) * 1) | |
long_sl := close - (abs(close - lband) * 1) | |
strategy.entry( id = "Long", long = true) | |
if afterStartDate and longCond and currMacd > 0 and mfi[0] > 0 and mfi[1] < 0 | |
long_tp := close + (abs(close - lband) * 1) | |
long_sl := close - (abs(close - lband) * 1) | |
strategy.entry( id = "Long", long = true) | |
if strategy.position_size > 0 | |
strategy.exit("TP/SL", from_entry="Long", limit = long_tp, stop = long_sl) | |
if afterStartDate and shortCondition and currMacd < 0 and mfi < 0 | |
short_tp := close - abs(hband - close) | |
short_sl := close + abs(hband - close) | |
strategy.entry( id = "Short", long = false) | |
if strategy.position_size < 0 | |
strategy.exit("TP/SL", from_entry="Short", limit =short_tp, stop =short_sl) | |
if strategy.position_size > 0 and shortCondition | |
strategy.close("Long", comment="conflic, sell signal alert") | |
if strategy.position_size < 0 and longCondition | |
strategy.close("Short", comment="conflic, buy signal alert") | |
plotshape( strategy.position_size > 0 and shortCondition, title="Conflic Signal", text="CONF", textcolor=color.white, style=shape.labelup, size=size.normal, location=location.belowbar, color=color.blue, transp=0) | |
plotshape( strategy.position_size < 0 and longCondition, title="Conflic Signal", text="CONF", textcolor=color.white, style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.blue, transp=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As I understand it, this code is related to trading on the stock market. It's quite an interesting topic and can evoke the same excitement as playing in a casino, which undoubtedly brings pleasure to many players, including myself. I can only say that it's essential to play only on trusted platforms, such as foreign online casinos available for players from Estonia, which are selected by the service https://valismaa-kasiinod.com/ based on the criteria that an authoritative online gaming platform should possess. Modern payment methods, licensing, a wide selection of games, quality customer support - these are all important aspects to consider. If you're interested in this topic, I highly recommend checking it out.