pdrhParticipant
Average
IF (c1 AND a2 ) AND ST<2 AND Not ShortOnMarket AND Not Daysforbidden And timeEnterBefore AND timeEnterAfter THEN
SELLSHORT 2 Perpoint AT c2 limit
ST=ST+1
ENDIF
// Conditions to exit short positions
IF SHORTONMARKET AND close < tradeprice - 6 THEN // if the price moves 5pts in my favour...
if countofshortshares = 2 then
Exitshort 1 PERPOINT at market //close half of the trade
//SoldHalf = 1
breakevenlevel = tradeprice //...calculate the level for a stop 5pts below the trade open price...
endif
If COUNTOFSHORTSHARES=1 then
Exitshort 1 PERPOINT at breakevenlevel limit
endif
Endif
// Stops and targets
SET STOP ploss 8
SET TARGET pPROFIT 14
graph tradeprice
graph breakevenlevel
I have an algo that closes half my position and sets a breakeven level .
My problem is that the instruction to exit at the break even level is ignored and exit happens at the stop level
It’s due to narrow SL and TP, try changing both to, say, 40 or 50 andit’ll work.
pdrhParticipant
Average
That did not work sadly.Still ignoring the breakeven .
Yes, there were a couple of additional issues:
- use STOP instead of LIMIT to exit, as you are placing a pending order to exit at WORSE price
- use a variable (I named it FLAG) to signal that an exit at breakeven has been triggered, as it must be placed each new bar until hit (or TP is hit, of course); the exit order must be outside the conditional IF…ENDIF block.
I tested this code on Dax, 4h TF:
IF close crosses under average[100] and not onmarket THEN
SELLSHORT 2 Perpoint AT market
flag = 0
ENDIF
// Conditions to exit short positions
IF SHORTONMARKET AND close < tradeprice - 6 THEN // if the price moves 5pts in my favour…
if countofshortshares = 2 then
Exitshort 1 PERPOINT at market //close half of the trade
//SoldHalf = 1
breakevenlevel = tradeprice //…calculate the level for a stop 5pts below the trade open price…
endif
If COUNTOFSHORTSHARES=1 then
flag = 1
endif
Endif
IF flag = 1 then
Exitshort 1 PERPOINT at breakevenlevel stop
endif
// Stops and targets
SET STOP ploss 500 //8
SET TARGET pPROFIT 500 //14
//
graphonprice tradeprice(1)
graphonprice breakevenlevel coloured(255,0,0,255)
graph close < (tradeprice - 6)
pdrhParticipant
Average
Thanks. That worked but I need to keep stop and target at 8/12 or elase I get a worse result
Keep in mind that you can now use the SET STOP BREAKEVEN instruction which is the best way to ask the broker your stoploss at breakeven