Increase position based on equity drawdown

Forums ProRealTime English forum ProOrder support Increase position based on equity drawdown

Viewing 15 posts - 1 through 15 (of 22 total)
  • #121300

    Hi,

    This is probably an easy question for any one who nows coding in PRT. I would like some help to create a code that increases/cumulate a position if the equity drops x% below the strategy’s maxequity. I thought it would be something like the code below that I found but it clearly doesn’t work:

    Any idea on how to fix it? Is it the definition of maxequity (line 1) that is wrong?

    #121433

    …Or maybe the above is not logical. Instead, what would be the code for increasing a position if current position is down x %?

    #121434

    Perhaps something like this – not tested.

     

    #121446

    Thank you @Vonasi , it worked! 🙂

    It was also a minor disaster since it accumulated like crazy… do you know if there is a command to limit the increased order to only once per trade? Something like “max cumulateorders = 1”? I tried using the “countofposition” command but that only works if the strategy is static on the number of contracts to buy or sellshort and I prefer to use re-invest with increasing positions. I looked in the PRT manual but it didn’t have any example on limiting the number of cumulate orders.

    #121447

     

    1 user thanked author for this post.
    #126741

    I would like to do a twist on the above code and instead create a trigger to increase a position with x contracts if the current position is down x %. I could really use some help since I failed with my own poor skills…

     

    #126746

    Not sure that I fully understand what you are trying to do but this is what you have described. Not tested.

     

    #126750

    We’re getting closer. We can focus on only longonmarket and ignore short. I would like the code to trigger a buy of x contracts at market if the current position has declined x % since buy.

    Let’s say I have 0.2 contracts on DJI and if this position is down 0.5% in value I want to buy an additional 0.2 contracts. I would also like the maximum position to be 0.4 contracts.

    #126751

    A picture says more than a thousand words, right. See attached. When the MAE is down 15 euro (which is roughly 0,3%) I want to buy 0.2 contracts. Is that possible?

    #126753

    So you don’t want to buy x contracts at a drop of x%. You want to buy y contracts at a drop of x%.

     

    #126754

    The above code places a pending order on the market at the same time that it opens the first trade so that if the market drops 0.5% in that first candle then a second position will open. This initial order however has to be calculated on the closing price of the previous candle and so if there is a gap down then it will not be 0.5% below your first buy price. After the first candle it is exactly 0.5% below because we now know what price we bought at.

    #126755

    You also have to consider that that code uses the POSITIONPRICE and not TRADEPRICE in the calculations so if you increase the maximum position size so that it opens more individual trades than two then the 0.5% is calculated off the average price you purchased at and not the last price you purchased at. Just change POSITIONPRICE to TRADEPRICE to match whichever you prefer.

    #126756

    It didn’t have any effect. No additional buy is being made. But it usually takes way more than one candle before the market has dropped to the trigger level. Does the limit order cancel itself after one candle?

     

    #126770

    I just tested this version on DJI daily and it worked just fine.

    It did nothing though with a position size of 0.2.

    Why have you moved the variable setting to the bottom of the code? They must be at the start of the code or they will not be known for the first bar on the chart.

    #126775

    I get no extra trade when I add the code. Changed the positionsize to 1 and max to 2. See attached for ITF if you want to give it a go. DJI/wall street cash (1 eur) with 5sec timeframe. I do appreciate your support 🙂

Viewing 15 posts - 1 through 15 (of 22 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login