Cumulating positions ARE NOT WORKING

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #176322 quote
    efahmy
    Participant
    Average

    Gents,
    Could you check this code why the Cumulating positions are not working??

    
    // Definition of code parameters
    DEFPARAM CumulateOrders = True // Cumulating positions activated
    timeframe(DEFAULT)
    MaxPositionsAllowed = 5
    // Conditions to enter long positions
    indicator1 = MACDline[5,35,5](close)
    indicator2 = MACDSignal[5,35,5](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    PP = (DHigh(1) + DLow(1) + DClose(1))/3
    C2 = (close < indicator1)
    S3 = DLow(1)-2*(DHigh(1)-(DHigh(1) + DLow(1) + DClose(1))/3)
    C3 = (close > indicator2)
    IF c1 AND c2 AND c3 THEN
    BUY 50 CONTRACT AT MARKET
    ENDIF
    // Stops and targets
    SET TARGET pPROFIT 2.0
    
    #176326 quote
    Swingueur
    Participant
    Average

    Hello,
    What is the issue that you have and make you say it’s not working?
    For sure, the variable MaxPositionsAllowed is defined but not used in the code, which is not good, the system will rebuy more than 5 times
    Assuming that the conditions are met, I would try something like this, and verifying the number of positions in the graph once the results are generated.

    ounce n=0
    
    ....
    
    IF NOT LongOnMarket THEN
    n=0
    ENDIF
    
    IF c1 AND c2 AND c3 AND n<MaxPositionsAllowed THEN
    BUY 50 CONTRACT AT MARKET
    n=n+1
    ENDIF
    #176330 quote
    robertogozzi
    Moderator
    Master

    Conditions in lines 13 and 15 seem to be impossible to be both true at the same time.

    #176331 quote
    efahmy
    Participant
    Average

    The issue is that the code buy only once and never buy again when the conditions are met??!!

    #176333 quote
    Nicolas
    Keymaster
    Master

    Condition C2 & C3, you are checking the price with an MACD line?! They do not share the same scale.

    When do you see an order opening? At beginning of the data history or later?

    #176337 quote
    efahmy
    Participant
    Average
    // Definition of code parameters
    DEFPARAM CumulateOrders = True // Cumulating positions activated
    timeframe(DEFAULT)
    MaxPositionsAllowed = 5
    // Conditions to enter long positions
    indicator1 = MACDline[5,35,5](close)
    indicator2 = MACDSignal[5,35,5](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    PP = (DHigh(1) + DLow(1) + DClose(1))/3
    C2 = (close < PP)
    S3 = DLow(1)-2*(DHigh(1)-(DHigh(1) + DLow(1) + DClose(1))/3)
    C3 = (close > S3)
    IF c1 AND c2 AND c3 THEN
    BUY 50 CONTRACT AT MARKET
    ENDIF
    // Stops and targets
    SET TARGET pPROFIT 2.0
    
    #176344 quote
    nonetheless
    Participant
    Master

    this is the entry code for a cumulating algo I have up and running and I know works. In this case the limit is 3 entries instead of 5, but you can adapt it.

    The logic of MaxPositionsAllowed is to control the total number of contracts, not the number of entries. The code below will make 3 entries of 50 contracts each.

    Another stipulation I use, that you might want to consider, is adding “and positionperf <0” to your additional entries, so that your total position is always averaging down.

     

    positionsize = 50
    
    MaxPositionsAllowed = 3*positionsize
    
    if not onmarket then
    flag = 1
    flag1 = 1
    ENDIF
    
    // Conditions to enter long positions
    IF not longonmarket and (conditions) THEN
    BUY positionsize CONTRACT AT MARKET
    elsif longonmarket and (conditions) and flag and COUNTOFLONGSHARES < MaxPositionsAllowed then
    BUY positionsize CONTRACT AT MARKET
    flag = 0
    elsif longonmarket and (conditions) and flag1 and COUNTOFLONGSHARES < MaxPositionsAllowed then
    BUY positionsize CONTRACT AT MARKET
    flag1 = 0
    ENDIF
    
    If LongOnMarket THEN
    SET STOP %LOSS sl
    SET TARGET %PROFIT tp
    ENDIF
    efahmy and Midlanddave thanked this post
    #176351 quote
    deletedaccount051022
    Participant
    New

    I really like the addition of the  “and positionperf <0” , neat snippet – thank you for sharing.

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

Cumulating positions ARE NOT WORKING


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
efahmy @efahmy Participant
Summary

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

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