CKWParticipant
Veteran
Hi All,
Just wondering if PRT allows add entry when you have trailing feature activated in your source code ?
For testing, I used sample from Nicholas and add new “market orders” when price triggered “first move of trailing“, and “next moves of trailing“. Apparently, It doesn’t work as I don’t find any trades open with 1.5 contracts or maybe my method is wrong :).
Basically, my Idea is to add contracts when initial position reaches targeted trailing moves.
Thanks for your advice
defparam cumulateorders = false
//order launch (example) would be set to any other entry conditions
//c1 = close>close[1]
c2 = close<close[1]
TrailingFlag = 0
//if c1 then
//BUY 1 LOT AT MARKET
//SET STOP PLOSS 50
//endif
if c2 then
SELLSHORT 1 contract 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
TrailingFlag = 1
SELLSHORT 1.5 contract AT MARKET
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
TrailingFlag = 2
SELLSHORT 1.5 contract AT MARKET
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
Graph TrailingFlag
//************************************************************************
Remove:
defparam cumulateorders = false
CKWParticipant
Veteran
Hi Vonasi,
Thanks.
Remove first line or “cumulateorders = true” then it works but I encountered another issue. Let me attach the new code to precise the issue.
Please find the details from the attached screenshot, and my observation below. From Orders list and Closed Positions list, the entry date and exit date are not tally:
- (Black) Rectangular for left and right entry time are not tally, and 2nd order always return 0 bar
- (green) Rectangular always the same time as 2nd order entry
Thanks for your advice
defparam cumulateorders = true
//order launch (example) would be set to any other entry conditions
//c1 = close>close[1]
c2 = close<close[1]
TrailingFlag = 0
//if c1 then
//BUY 1 LOT AT MARKET
//SET STOP PLOSS 50
//endif
if c2 AND Not ShortOnmarket then
SELLSHORT 1 contract 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 SHORTONMARKET 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
TrailingFlag = 1
SELLSHORT 1.5 contract AT MARKET
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
TrailingFlag = 2
//SELLSHORT 1.5 contract AT MARKET
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
Graph TrailingFlag
//************************************************************************
ode
Your 2 orders are closed at the same time by the trailing stop, or I don’t get what is your question?