Cumulating positions with breakeven

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #145007 quote
    Monochrome
    Participant
    Senior

    Im using nicolas’s code on breakeven which was working great until i tried using cumulating positions.

    //FOR STOPLOSS MANNGEMENT
    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

    Is 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

    #145012 quote
    kaq52
    Participant
    Average

    I 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.

    Monochrome thanked this post
    #145015 quote
    Monochrome
    Participant
    Senior

    If i were to trade live with IG using cumulative orders. Would they have individual target and stops? Not including the breakeven code.

    #145016 quote
    kaq52
    Participant
    Average

    Within same system, answer is no, they won’t have individual SLs and TPs.

    You can have multiple instances of same system running which will have their own separate SLs or TPs.

    #145019 quote
    Monochrome
    Participant
    Senior

    Thanks 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.

    #145020 quote
    robertogozzi
    Moderator
    Master

    I 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).

    PositionPrice-calculation.xls x-6.jpg x-6.jpg
    #145024 quote
    Monochrome
    Participant
    Senior

    Thanks 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.

    #145029 quote
    robertogozzi
    Moderator
    Master

    IG 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.

    Monochrome thanked this post
    #145033 quote
    Nicolas
    Keymaster
    Master

    Individual 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.

    Monochrome thanked this post
    #191088 quote
    SkippyTrader
    Participant
    New

    Hi, 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?

    #191091 quote
    robertogozzi
    Moderator
    Master

    TradePrice(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).

    SkippyTrader thanked this post
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Cumulating positions with breakeven


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Monochrome @monochrome Participant
Summary

This topic contains 10 replies,
has 5 voices, and was last updated by robertogozzi
3 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/22/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...