Hi guys, anybody can explain me why when I am adding a trailing condition in my strategy the platform doesn’t allow me to run the system and when I delete the trailing conditions from the strategy the platform run my strategy?? Thanks
SET STOP TRAILING is accepted,thiough recommended.
What error does it return?
Usually a common mistake is to use TWO different kinds of stop, such as:
SET STOP LOSS 100 TRAILING 10
which is not allowed, SET STOP LOSS and SET STOP TRAILING cannot be in the same line and cannot be in the same strategy. If they are in the same line an error is reported, while if they are on different lines they are accepted, but the second line always overrides the previous one.
Hi, this is the code I am using for
defparam cumulateorders = false
//order launch (example) would be set to any other entry conditions
//c1 = close>close[1]
c2 = close<close[1]
//if c1 then
//BUY 1 LOT AT MARKET
//SET STOP PLOSS 50
//endif
if c2 then
SELLSHORT 1 LOT AT MARKET
SET STOP PLOSS 50
endif
//************************************************************************
//trailing stop function
trailingstart = 20 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the “stoploss”
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
GRAPH newSL as “trailing”
When I try to launch the automatic proreal time in the live market it`s show me this
It means : Delete the last line of your code.
oh yeah, I have just realized now. DONE. appreciate your help, many thanks.
Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Thank you 🙂
breakeven = 30
keeppoints = 5
if not onmarket then
flag = 0
endif
IF longonmarket and close - tradeprice >= Breakeven*pipsize THEN
flag = 1
endif
if flag then
sell at (tradeprice + keeppoints) stop
endif
Hi guys, I am new in programming so there is anybody who can help me how to build a breakeven code for short positions ? what do I have to change exactly to make it work for short one ? thank you for your patience.
MODERATORS EDIT: One post deleted and merged and code tidied up. Topic also moved to correct forum. Please try to be more careful with future posts.
Replace line 30 with:
sell at (tradeprice + keeppoints*PipSize) stop
breakeven = 30 * pipsize
keeppoints = 5 * pipsize
if not onmarket then
flag = 0
endif
// Long
IF longonmarket and close - tradeprice >= Breakeven THEN
flag = 1
endif
// Short
IF shortonmarket and tradeprice - close >= Breakeven THEN
flag = 1
endif
IF Flag = 1 then
IF LongOnMarket THEN
sell at (tradeprice + keeppoints) stop
ELSIF ShortOnMarket THEN
exitshort at (tradeprice - keeppoints) stop
ENDIF
Endif