'Double SAR strategy
I am trying to implement a double sar strategy but couldn't find any answers (maybe I got the answer somewhere but as I am not a coder, I may miss it)
My conditions to open a trade 1)check for PSAR1 if its in uptrend or downtrend 2)check for PSAR2 if it makes a crossover
as per the code, it looks for crossovers on both PSAR1 and PSAR2. I want that the strategy should check for PSAR1 if its in uptrend or downtrend (not if it makes a cross)
Many thanks for any answers.
//@version=4
strategy(title="Double Parabolic SAR", overlay=true)
start1 = input(title="Start1", type=input.float, defval=0.001, step=0.01)
inc1 = input(title="Inc1", type=input.float, defval=0.001, step=0.01)
max1 = input(title="Max1", type=input.float, defval=0.001, step=0.01)
start2 = input(title="Start2", type=input.float, defval=0.001, step=0.01)
inc2 = input(title="Inc2", type=input.float, defval=0.002, step=0.01)
max2 = input(title="Max2", type=input.float, defval=0.005, step=0.01)
PSAR1 = sar(start1, inc1, max1)
PColor1 = PSAR1 < low? color.red:color.red
plot(PSAR1, "ParabolicSAR2", style=plot.style_cross, color=PColor1)
plotshape(crossover(close,PSAR1), style=shape.labelup, location=location.belowbar, color=color.green, size=size.tiny, title="", text="", textcolor=color.white)
plotshape(crossunder(close,PSAR1), style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, title="", text="", textcolor=color.white)
PSAR2 = sar(start2, inc2, max2)
PColor2 = PSAR2 < low? color.blue:color.green
plot(PSAR2, "ParabolicSAR2", style=plot.style_cross, color=PColor2)
plotshape(crossover(close,PSAR2), style=shape.labelup, location=location.belowbar, color=color.green, size=size.tiny, title="", text="", textcolor=color.white)
plotshape(crossunder(close,PSAR2), style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, title="", text="", textcolor=color.white)
tp=input(defval=500.0,title="TARGET IN POINTS")
sl=input(defval=500.0,title="STOP LOSS IN POINTS")
Buy1 = crossunder(close,PSAR1)
Sell1 = crossover(close,PSAR1)
Buy2 = crossunder(close,PSAR2)
Sell2 = crossover(close,PSAR2)
if Buy1 and Sell2
strategy.entry("BUY", strategy.long)
alert("BUY", alert.freq_once_per_bar)
strategy.exit("Buy Exit", from_entry="BUY", profit = tp,loss = sl)
if (Sell1 and Buy2)
strategy.entry("SELL", strategy.short)
alert("SELL", alert.freq_once_per_bar)
strategy.exit("Sell Exit", from_entry="SELL", profit = tp,loss = sl)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
