ramaParticipant
Senior
Set stop loss 25
set target profit 200
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
// — BUY SIDE —
//test if the price have moved favourably of “startBreakeven” points already
IF longonmarket AND close-tradeprice>=12*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice+2*pipsize
ENDIF
IF longonmarket AND close-tradeprice>=20*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice+10*pipsize
ENDIF
******************************************************
The above code is working exactly the way I wanted the problem when I am in profit >= stop loss moves to 10
when the floating profit falls <=20 then stop loss moves to 2. I want to keep the stop loss at 10 once my floating profit was 20 then fallen below 20
Please avoid double posts, thanks, the other copy of this post inserted in another thread has been deleted to keep the potential answers from other users in only one thread (this one) and not split across separate multiple threads. Thanks for your understanding.
To write code, please use the <> “insert PRT code” button, to make code easier to read.
You should post the whole strategy to test it and try to spot any issue.
At first glance I warn you that
Set stop loss 25
will never be executed (at least on forex pairs), you should either write:
Set stop loss 0.0025 //in Forex pairs, not Dax or oher indeces, it must be a difference in price
// or
Set stop Ploss 25 //this is 25 pips
// --- BUY SIDE ---
//test if the price have moved favourably of "startBreakeven" points already
IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
// --- end of BUY SIDE ---
sorry, mistake. I meant this one:
startBreakeven = 5 //how much pips/points in gain to activate the breakeven function?
PointsToKeep = 3 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
//reset the breakevenLevel when no trade are on market
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
// --- BUY SIDE ---
//test if the price have moved favourably of "startBreakeven" points already
IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
// --- end of BUY SIDE ---
ramaParticipant
Senior
This code works only one stop loss
not for variable stop loss