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:
1
2
3
4
5
6
7
8
9
10
xClose=(open+high+low+close)/4
IFBarIndex=0THEN
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:
1
2
3
4
5
IFallmyconditionsTHEN
BUY1SHARESATMARKET
xsll=xlow[3]
SET TARGETpPROFITx
ENDIF
to enter short:
1
2
3
4
5
IFallmyconditionsTHEN
SELLSHORT1SHARESATMARKET
xSLS=xhigh[3]
SET TARGETpPROFITy
ENDIF
finally to set stop loss:
1
2
3
4
5
6
7
IFlongonmarketTHEN
SELLATxsll-2*pipsizeSTOP
endif
IFShortOnMarketTHEN
BUYATxsls+2*pipsizeSTOP
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.