Hi gang,
I need som help code a strategy using the DC (Donchain Channels) ADX (Average Directional Index) and 200 ema.
This is how i want it to work.
Long position : When price crosses midle of DC 20 and ADX is 25+ and price is over 200 EMA then buy. Stop loss goes on the lower band of DC(or a few pips under) and tak profitt is 1,5
Short position: When price crosses midle of DC 20 and ADX is 25+ and price is under 200 EMA then sell. Stop loss goes on the uper band of DC(or a few pips over) and tak profitt is 1,5 more the the sl.
If any one coud help me get this working it would be very nice 🙂
If some thing is un clear please let me know.
Have a great day
There you go (not tested);
p = 20
Upper = HIGHEST[p](High[1])
Lower = LOWEST[p](Low[1])
Middle= (Upper + Lower) / 2
Ema = average[200,1]
MyAdx = adx[14]
//
L1 = close CROSSES OVER Middle
L2 = close > Ema
L3 = MyAdx >= 25
LS = (close - Lower) + 3*PipSize
LT = LS * 1.5
//
S1 = close CROSSES UNDER Middle
S2 = close < Ema
S3 = L3
SS = (Upper - close) + 3*PipSize
ST = SS * 1.5
//
// Long
IF L1 and L2 and L3 and Not LongOnMarket THEN
BUY 1 Contract at Market
SET TARGET PROFIT LT
SET STOP LOSS LS
ENDIF
//
// Short
IF S1 and S2 and S3 and Not ShortOnMarket THEN
SELLSHORT 1 Contract at Market
SET TARGET PROFIT ST
SET STOP LOSS SS
ENDIF
Thanks for the quick answer 🙂 Is there a way to integrate trailing SL? It would be nice to have the SL follow the DC.
My struggle is here is. When in a long position and price going up. the DC also moves up and when the Price starts going down and the DC goes down the stop loss also moves causing the exit to be wrong.
Note: I want the TP to be the same *1.5 just the trailing stop loss to follow the lower band of DC when going in one direction.
This might be bad explained but hope you under stand 🙂
And thanks again for your help.
There you go:
p = 20
Upper = HIGHEST[p](High[1])
Lower = LOWEST[p](Low[1])
Middle= (Upper + Lower) / 2
Ema = average[200,1]
MyAdx = adx[14]
//
L1 = close CROSSES OVER Middle
L2 = close > Ema
L3 = MyAdx >= 25
LS = (close - Lower) + 3*PipSize
LT = LS * 1.5
//
S1 = close CROSSES UNDER Middle
S2 = close < Ema
S3 = L3
SS = (Upper - close) + 3*PipSize
ST = SS * 1.5
//
// Long
IF L1 and L2 and L3 and Not LongOnMarket THEN
BUY 1 Contract at Market
SET TARGET PROFIT LT
SET STOP LOSS LS
StopLoss = Lower - 3*PipSize
ENDIF
//
// Short
IF S1 and S2 and S3 and Not ShortOnMarket THEN
SELLSHORT 1 Contract at Market
SET TARGET PROFIT ST
SET STOP LOSS SS
StopLoss = Upper + 3*PipSize
ENDIF
IF LongOnMarket THEN
StopLoss = max(StopLoss,Lower)
SELL AT StopLoss STOP
ELSIF ShortOnMarket THEN
StopLoss = min(StopLoss,Upper)
EXITSHORT AT StopLoss STOP
ENDIF
kalleklovn – Topic moved to ProOrder forum which is the correct place for strategy coding questions.
- Post your topic in the correct forum:
_ ProRealTime Platform Support: only platform related issues.
_ ProOrder: only strategy topics.
_ ProBuilder: only indicator topics.
_ ProScreener: only screener topics
_ General Discussion: any other topics.
_ Welcome New Members: for new forum members to introduce themselves.
Actually I don’t know, since it’s kalleklovn‘s idea, but it seems a general strategy that may suit multiple markets.
I hope he may want to reply to your post 🙂
Hi sorry for the late reply.
Thanks for the setup.
I trade this on DAX, GBPUSD and EURJPY
Cant get the same results as when I manually take the trades. I have used this strategy for some time and I know it works. I might be a bit more picky on some trades and that’s why the results are different. I’m running it on a demo account a comparing the results with what I get when placing manually.
So far the Demo is down but I’m up. I se that some trades taken are a bit off. But then again the best trading way is alway manually 🙂
I will try some tweaking and let you know what time frame is the best on what market 🙂