Dear all,
I’m trying to set a stop loss 2 pips under or 2 pips above the high at 2 prevoius bar of a Heikin Ashi.
I found something on the forum but it was talking about normal candles and not HA. I tried to adapt it to HA but it is not working as expected.
I want the stop loss NOT to change at next bars.
Here’s the code of Heikin Ashi I use:
xClose = (open+high+low+close)/4
IF BarIndex=0 THEN
xOpen = open
xHigh = high
xLow = low
ELSE
xOpen = (xOpen[1] + xClose[1])/2
xHigh = Max(Max(high, xOpen), xClose)
xLow = Min(Min(low, xOpen), xClose)
ENDIF
To enter long:
IF all my conditions THEN
BUY 1 SHARES AT MARKET
xsll = xlow[3]
SET TARGET pPROFIT x
ENDIF
to enter short:
IF all my conditions THEN
SELLSHORT 1 SHARES AT MARKET
xSLS = xhigh[3]
SET TARGET pPROFIT y
ENDIF
finally to set stop loss:
IF longonmarket THEN
SELL AT xsll-2*pipsize STOP
endif
IF ShortOnMarket THEN
BUY AT xsls+2*pipsize STOP
ENDIF
Here what happen:
- When it has to close long position looks not bad even if it sometimes the exit from position it’s lower then xlow[3], so I do not understand if it sell as soon as the price reach xlow[3]+2pipsize or it waits the bar where it reaches it to close.
- When it has to close short position it opens a countrary long position, so I found myself with a opened long postion which I don’t need. Regarding point where it closes the short position the issue is as above at point 1.
I really appreciate your help!
Thank you all!
To close short position, you have to use EXITSHORT instruction, not BUY which is already made to go long on market.
Thank you Nicolas
that was it! i’ve done some other changes and now it’s working as it should!
Thank you again!