Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- strategy("SugarBot_V4[BETA](6hr)", shorttitle="SugarBot_V4[BETA](6hr)", overlay=true, initial_capital=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=2)
- //**********************************************************************************************************************************************************************************
- length = input(title="Length of SWMA", type=input.integer, defval=65) // Best Value: 65 &&& DRAWDOWN MIN: UNKNOWN
- highlightMovements = input(title="Highlight Movements ?", type=input.bool, defval=true)
- src = input(title="Source", type=input.source, defval=close)
- PI = 2 * asin(1)
- sum = 0.0
- weightSum = 0.0
- for i = 0 to length - 1 by 1
- weight = sin((i + 1) * PI / (length + 1))
- sum := sum + nz(src[i]) * weight
- weightSum := weightSum + weight
- weightSum
- swma = sum / weightSum
- swmaColor = highlightMovements ? swma > swma[1] ? color.green : color.red : #6D1E7F
- plot(swma, title="SWMA", linewidth=2, color=swmaColor, transp=0)
- // I have the Sine Weighted Moving average function (above) here as a basis for a primary entry indicator later
- //*********************************************************************************************************************************************************************************
- ema1 = input(title="lenght ema1", defval=66) // Best Value: 66 &&& DRAWDOWN MIN: 66
- roc1 = input(title="lenght roc of ema1", defval=66) // Best Value: 68 &&& DRAWDOWN MIN: 66
- ema2 = input(title="lenght ema2 on roc1", defval=43) // Best value: 53, 32 &&& DRAWDOWN MIN: 45
- ema3 = input(title="lenght ema3 on roc1", defval=25) // best Value: 26 &&& DRAWDOWN MIN: 22
- roc3 = input(title="lenght roc on swma", defval=101) // Best value: UNKNOWN &&& DRAWDOWN MIN: UNKNOWN
- ema4 = input(title="lenght ema4 on roc of SWMA", defval=37) // Best value: 32 &&& DRAWDOWN MIN: 37
- roc2 = input(title="lenght roc on roc", defval=101) // Best value: 70, 68 &&& DRAWDOWN MIN: 101
- //roc1 is used to determine when price action is changing direction.
- //roc2 is used later to determine parabolic moments of inflection that are useful in selling tops or covering bottoms
- //roc3 is used to maintain a level of abstraction from the SWMA, which is useful in trading choppy markets
- //ema4 is used in our analysis of the abstracted data obtained from SWMA
- ema1Val = ema(close, ema1)
- roc1Val = roc(ema1Val, roc1)
- roc2Val = roc(roc1Val, roc2)
- roc3Val = roc(swma, roc3)
- ema2Val = ema(roc1Val, ema2)
- ema3Val = ema(roc1Val, ema3)
- ema4Val = ema(roc3Val, ema4)
- conditionBuy1 = crossover(roc1Val, ema2Val)
- conditionSell1 = crossunder(roc1Val, ema2Val)
- conditionBuy2 = crossover(roc1Val, ema3Val)
- conditionSell2 = crossunder(roc1Val, ema3Val)
- conditionBuy3 = crossover(roc3Val, ema4Val)
- conditionSell3 = crossunder(roc3Val, ema4Val)
- conditionCloseLong = crossunder(roc2Val, roc1Val)
- conditionCloseShort = crossover(roc2Val, roc1Val)
- startDay = input(defval=1, title="Start Day")
- startMonth = input(defval=1, title="Start Month")
- startYear = input(defval=2018, title="Start Year")
- endDay = input(defval=31, title="End Day")
- endMonth = input(defval=12, title="End Month")
- endYear = input(defval=2019, title="End Year")
- start = timestamp(startYear, startMonth, startDay, 00, 00) // backtest start window
- finish = timestamp(endYear, endMonth, endDay, 23, 59) // backtest finish window
- window() => // create function "within window of time"
- time >= start and time <= finish ? true : false
- if window()
- strategy.entry("buy", strategy.long, when=conditionBuy1[1] or conditionBuy2[1] or conditionBuy3[1])
- strategy.entry("sell", strategy.short, when=conditionSell1[1] or conditionSell2[1] or conditionSell3[1])
- strategy.close_all(when=conditionCloseLong)
- strategy.close_all(when=conditionCloseShort)
- //alertcondition(conditionBuy, "LONG", "roc crossover ema -> long")
- //alertcondition(conditionSell, "SHORT", "roc crossunder ema -> short")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement