So…the end result with cycle highs and lows :-).
I tested it and it works for 90%. I just see one more last thing. See the attached image.
I have some parameters which you can fill in yourself. like the MACD, Moving Average, and in the signal in the chart I have chosen to set 2 targets and 1 stoploss. So yo can see of the TA or SL will be reached first.
.
It would be great to have one green arrow up above the bar with the signal when the Target1 has reached first, to have 2 green arrows up when Target2 has been reached, and to have a red arrow down when the Stoploss has been reached first.
.
My gratitude is BIG. Thank you Vonasi
DEFPARAM calculateonlastbars = 1000
macdl = macdline[ShortTermMA,LongTermMA,Periods]
macds = exponentialaverage[Periods](macdl)
//start of cycle low
If macdl =< macds and macdl[1] > macds[1] then
macdlowest2 = macdlowest
lowestprice2 = lowestprice
incyclelow = 1
macdlowest = macdl
LowestPrice = low
endif
//End of cycle
If macdl > macds and macdl[1] < macds[1] then
incyclelow = 0
endif
//lowest macd and price in cycle
if incyclelow then
macdlowest = min(macdlowest, macdl)
lowestPrice = min(lowestprice, low)
c1 = open < average[ma]
c2 = close > average[ma]
c3 = macdlowest > macdlowest2
c4 = lowestprice > lowestprice2
if c1 and c2 and c3 and c4 then
DRAWSEGMENT (barindex, close+target1, barindex, close+target2)COLOURED(0,250,0)
DRAWSEGMENT (barindex, close+target1, barindex+1, close+target1)COLOURED(0,250,0)
DRAWTEXT("TA1", barindex-1, close+target1, Dialog, Standard, 10) COLOURED(0,0,0)
DRAWSEGMENT (barindex, close+target2, barindex+1, close+target2)COLOURED(0,250,0)
DRAWTEXT("TA2", barindex-1, close+target2, Dialog, Standard, 10) COLOURED(0,0,0)
DRAWSEGMENT (barindex, close-stoploss, barindex+1, close-stoploss)COLOURED(250,0,100)
DRAWSEGMENT (barindex, close-(stoploss-0.25), barindex, close-stoploss)COLOURED(250,0,100)
DRAWTEXT("SL", barindex-1, close-stoploss, Dialog, Standard, 10) COLOURED(0,0,0)
DRAWTEXT("LH", barindex, close+target2+0.75, Dialog, Standard, 14) COLOURED(0,250,0)
endif
endif
//start of cycle high
If macdl => macds and macdl[1] < macds[1] then
macdhighest2 = macdhighest
highestprice2 = highestprice
incyclehigh = 1
macdhighest = macdl
highestPrice = high
endif
//End of cycle
If macdl < macds and macdl[1] > macds[1] then
incyclehigh = 0
endif
//highest macd and price in cycle high
if incyclehigh then
macdhighest = min(macdhighest, macdl)
highestPrice = min(highestprice, low)
c1a = open > average[ma]
c2a = close < average[ma]
c3a = macdhighest < macdhighest2
c4a = highestprice < highestprice2
if c1a and c2a and c3a and c4a then
DRAWSEGMENT (barindex, close-target1, barindex, close-target2)COLOURED(0,250,0)
DRAWSEGMENT (barindex, close-target1, barindex+1, close-target1)COLOURED(0,250,0)
DRAWTEXT("TA1", barindex-1, close-target1, Dialog, Standard, 10) COLOURED(0,0,0)
DRAWSEGMENT (barindex, close-target2, barindex+1, close-target2)COLOURED(0,250,0)
DRAWTEXT("TA2", barindex-1, close-target2, Dialog, Standard, 10) COLOURED(0,0,0)
DRAWSEGMENT (barindex, close+stoploss, barindex+1, close+stoploss)COLOURED(250,0,100)
DRAWSEGMENT (barindex, close+(stoploss-0.25), barindex, close+stoploss)COLOURED(250,0,100)
DRAWTEXT("SL", barindex-1, close+stoploss, Dialog, Standard, 10) COLOURED(0,0,0)
DRAWTEXT("HL", barindex, close-target2-0.75, Dialog, Standard, 14) COLOURED(250,0,0)
endif
endif
return