CumulateOrders is not working ?

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #78106 quote
    petitdudu
    Participant
    Junior

    Hi folks,

    A. I would like that my system accumulates positions every time my conditions are met (this can happen on two consecutive candles for instance). I’m using the following code as parameter but it is not working

    DEFPARAM CumulateOrders=True

    Every time I am in a position and the conditions are met again, the system doesn’t buy a new position.

    B. My exit rules are either stop loss at 2% below low of candle of entrance or once a target profit of 15% is reached. Because of that, I obviously don’t want the system to accumulate positions and sell those altogether if I get 15% return on the first shares bought (before accumulation) ot if we reach the stop-loss level of the first shares bought for instance. Is the system treating every buy as a separate “bundle” and consequently only sells a bundle if conditions are met for this bundle ?

    Thanks for your help !!

    #78109 quote
    robertogozzi
    Moderator
    Master

    Did you set the max number of contracts to something greater than 1 at launch time?

    ProBackTest doesn’ t care about it and works correctly, while ProOrder DOES need to know the max number of contracts it is allowed to trade.

    #78111 quote
    petitdudu
    Participant
    Junior

    Hey Roberto ! I am backtesting (on stocks only). I set an initial capital of 100.000 euros and ask the system to trade “10.000 cash at market” every time the signal is met.

    #78113 quote
    robertogozzi
    Moderator
    Master

    Try replacing 10,000 with 1, or 100,000 with 100,000,000.

    #78159 quote
    petitdudu
    Participant
    Junior

    I tried but this doesn’t make any difference. Is there any particularity of use of the “Cumulateorders” parameter ?

    #78162 quote
    Vonasi
    Moderator
    Master

    You may be best to share the code as without it we are just guessing. You might just have an IF ONMARKET in the wrong place for all we know. It must be a coding error as cumulate orders works fine in all the codes I test it in.

    #78164 quote
    Nicolas
    Keymaster
    Master

    every time the signal is met.

    Are you sure the signal is met multiple times in your strategy? Try to GRAPH the variable that trigger the signal.

    #78177 quote
    petitdudu
    Participant
    Junior

    Here is the full code. It is a code for going short (and not long as I said for comfort reasons in my previous messages).

    C4, C5 and C6 are to define the type of candle I’m looking for (length of shadows, length of candle as % of close price, etc.).

    In order to check what Prorealtest does, I took a stock and noted down on paper every candle that respect my rules. This code shorts the right candles except when I’m already in short position. If two following candles respect my rules, Probacktest always shorts on the first one and never on the second. If it was a mistake in my code, Prorealtest would sometimes short on the first candle, sometimes on the second.

    //Parameters
    DEFPARAM CumulateOrders=True
    DEFPARAM Preloadbars=30
    
    // Conditions to enter short positions
    indicator1=average[20](close)
    indicator2=indicator1[1]
    c1= indicator1<indicator2
    indicator3=indicator1[8]
    indicator4=indicator1[9]
    c2=indicator3<indicator4
    c3=high>high[2]
    queuesouscoeur=min(open,close)-low
    queuesouscoeurenpctrange=queuesouscoeur/(high-low)
    c4= queuesouscoeurenpctrange<0.27
    queuesurcoeur=high-max(open,close)
    queuesurcoeurenpctrange=queuesurcoeur/(high-low)
    c5= queuesurcoeurenpctrange>0.45
    queuesurcoeur= high-max(open,close)
    queuesurcoeurenpctcloture= queuesurcoeur/close
    c6= queuesurcoeurenpctcloture>0.035
    
    IF NOT shortonmarket AND c1 AND c2 AND c3 AND c4 AND c5 AND c6 THEN
    SELLSHORT 10000 CASH AT MARKET
    sl=high*1.02
    Buy at sl stop
    ENDIF
    
    IF shortonmarket then
    Exitshort at sl stop
    endif
    
    // Stops and targets
    SET TARGET %PROFIT 15
    #78178 quote
    petitdudu
    Participant
    Junior

    DAMN. I see my mistake now. I mentioned “If not short on market” whereas I don’t care about that and want the system to short anyway.

    Sorry and thanks for the help.

    #78179 quote
    petitdudu
    Participant
    Junior

    May I come back to the second point of my first post as it seems that the system sells all positions together and doesn’t respect the stop loss rule of the first short position taken. It seems to decide to sell everything based on the stop loss level or 15% target profit as calculated on the second candle of entry.

    B. My exit rules are either stop loss at 2% (above) below low of candle of entrance or once a target profit of 15% is reached. Because of that, I obviously don’t want the system to accumulate positions and sell those altogether if I get 15% return on the first shares bought (before accumulation) ot if we reach the stop-loss level of the first shares bought for instance. Is the system treating every buy as a separate “bundle” and consequently only sells a bundle if conditions are met for this bundle ?

    #78180 quote
    Vonasi
    Moderator
    Master

    Yes that NOT  SHORTONMARKET is why it only opens one trade.

    Surely line 26 is also wrong and should be an EXITSHORT rather than a BUY?

    #78181 quote
    Vonasi
    Moderator
    Master

    If you put a pending order at a price it will sell all positions at that price. If you SET a target level or stop level then each position will have individual exit prices.

    #78182 quote
    petitdudu
    Participant
    Junior

    Thank you, I replaced Buy and put Exitshort instead.

    You see the full code. I don’t know what you mean by pending orders, I never used that.I see on the chart that on a given moment, while the system did accumulate positions as wanted, Prorealtest didn’t respect my stoploss rule of 2% above the high of the first candle of entry and sold all accumulated positions at 15% profit calculated on the second candle of entry. He should have sold my first short position at stop loss level whereas I still would hold the second short position (for which its stop loss level was never reached).

    #78223 quote
    Vonasi
    Moderator
    Master

    If the last bit of your code is now like this:

    IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 THEN
    SELLSHORT 10000 CASH AT MARKET
    sl=high*1.02
    Exitshort at sl stop
    ENDIF
     
    IF shortonmarket then
    Exitshort at sl stop
    endif
     
    // Stops and targets
    SET TARGET %PROFIT 15

    …then every time the entry conditions are met then your SL value will be changed.

    The following is a pending order:

    Exitshort at sl stop

    It places an order on the market to close all trades at whatever the value of SL is. STOP is at an inferior price and LIMIT is at a superior price.

    There is no way to have different values of stop loss or take profit for different positions. You can either exit all trades at a certain price with a pending order or use the SET instruction to place orders a set distance from each individual position but every time you change the value it changes the distance for all open trades.

    With partial closure you could make this work by selling parts of your position at different levels but although partial closure works in back testing it is not yet possible to forward test using it in demo. I’m not sure if it works in live trading but then again I would never run anything live that has not been forward tested so that is irrelevant anyway.

    petitdudu and Nicolas thanked this post
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.

CumulateOrders is not working ?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
petitdudu @petitdudu Participant
Summary

This topic contains 13 replies,
has 4 voices, and was last updated by Vonasi
7 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/13/2018
Status: Active
Attachments: No files
Logo Logo
Loading...