Cumulating positions with breakeven
Forums › ProRealTime English forum › ProOrder support › Cumulating positions with breakeven
- This topic has 10 replies, 5 voices, and was last updated 2 years ago by robertogozzi.
Tagged: accumulation, POSITIONPRICE
-
-
09/22/2020 at 5:52 PM #145007
Im using nicolas’s code on breakeven which was working great until i tried using cumulating positions.
breakeven code12345678910111213141516//FOR STOPLOSS MANNGEMENTIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIFIs there a way to reset the code after each trade instead of ‘If not onmarket then breakeven=0’ ?
Also strangely my cumulating positions dont follow there individual targets and stoplosses, its as if they are added to each other. I tried both pProfit and %Profit, neither worked. I tried searching through the forum and people were saying in IG Profit and stoploss will follow individual trades but not it prorealtime, is this right?
How do I make it work so i can backtest it properly?
Thanks in advance
09/22/2020 at 6:57 PM #145012I think you misunderstood how code works for accumulation….when more and more trades are placed by same strategy (accumulating), all of them will have a single stoploss and single target profit, you have to exit them all at same point (unless you manage them manually in which case code will stop managing your order).
Orders placed by separate strategies or manually will have their individual SL and TP always.
Hope this helps.
1 user thanked author for this post.
09/22/2020 at 9:18 PM #145015If i were to trade live with IG using cumulative orders. Would they have individual target and stops? Not including the breakeven code.
09/22/2020 at 9:45 PM #14501609/22/2020 at 10:37 PM #145019Thanks for your reply but Im sorry, im still extremely confused. According to this thread – https://www.prorealcode.com/topic/cumulate-orders-and-stops-targets/
Targets and stoplosses are placed individually with IG. Is that only with %profit or with pProfit as well.
Also if thats the case will we have different results with prorealtime backtest vs ig live trades if correlated??
If we include the breakeven code with cumulative orders and say i am making a profit, would that also correlate with IG trades?
It questions the reliability of the backtest specifically with IG.
09/22/2020 at 11:37 PM #145020I am attaching an eXcel file with the calculations of POSITIONPRICE (hilighted in bold blue on yellow), which is an average price updated each new entry according to price and number of lots accumulated.
POSITIONPRICE is the keyword to use in your code to check gains/losses, beacuse TRADEPRICE (commonly used as a reference) cannot be used because there are several TRADEPRICES.
All SL’s and TP’s are calculated according to the updated value of POSITIONPRICE when accumulating positions (DEFPARAM CumulateOrders = TRUE).
09/23/2020 at 12:20 AM #145024Thanks for your reply.
“Set a target profit x% from the average position price.
Note: the % profit is calculated and placed individually for each order with IG or PRT-CFD.” from https://www.prorealcode.com/documentation/profit/
Im more worried with the differences between the backtest and IG.
For eg cumulated %profit in the backtest with be calculated based on positionprice but would it deliver the same results with IG?
What would happen if I put pProfit with IG?
My understanding is that IG will not trigger stoploss/target based of positionprice.
09/23/2020 at 7:41 AM #145029IG keep track of TP when a new position is entered, when accumulation is active, so they will close the single position when TP is reached, regardless of POSITIONPRICE.
1 user thanked author for this post.
09/23/2020 at 8:05 AM #145033Individual target and stoploss doesn’t mean that they can be different: x% target for 1st order and y% target for 2nd order = Not possible.
The breakeven function you are using set a pending stop order to sell all long orders at the same moment when price reach the breakeven price level.
1 user thanked author for this post.
04/03/2022 at 4:55 AM #191088Hi, i am curious – sorry join this old discussion, but was just thinking about this myself and wondering how to do it.
If used TRADEPRICE in the code instead of POSITIONPRICE would that make this possible ? For example a different loop for the Trailing SL’s or Breakevens if used TRADEPRICE[0], TRADEPRICE[1], TRADEPRICE[2] etc.. as in most recent trade price, the prior trade price, and the trade price before that? Using like ‘if positionsize + 1″ etc .. ?
Would doing something like that allow the strategy to operate seperate Stop-loses/Trailing profits for each trade in cumulating positions?
04/03/2022 at 7:37 AM #191091TradePrice(1), even without parenthesis, is not the price of the last entry; it’s the price of the last operation carried out, be it an entry or a partial exit.
If you use it to trail your stop loss, you might then use a wrong price.
Tradeprice is fine if you don’t close partial positions.
PositionPrice will always be the updated average price.
You could keep track of each individual entry price using an array and adding elements retaining a different Tradeprice each time a new entry is executed.
Bear in mind that you can keep track of each Tradeprice, but you cannot track individual orders and close the one you prefer. Everytime you close a position, the FIFO (First In First Out) rule applies. So if you choose to close a position at the most recent Tradeprice, you can do it, but it’s the oldest entry that will be closed, though.
Furthermore, I want to remind you that partial closing of positions can only be used with MARKET orders, not pending ones (as it’s not supported by IG).
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on