CUMULATEORDERS – COUNTOFPOSITION

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #182578 quote
    murre87
    Participant
    Senior

    Hi.
    If i want to create at strategy with CUMULATEORDERS. Maximun 1 long position and 1 short position at once.
    What do i choose in “MAX Position” when i start the tradingsystem?

    DEFPARAM CUMULATEORDERS = true
    defparam preloadbars = 10000
    
    MAXSHARES = abs(COUNTOFPOSITION) <= 1
    CB = RSI[14]>50
    CS = RSI[14]<45
    
    If cb and MAXSHARES and not longonmarket then
    Buy PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS 1
    SET TARGET %PROFIT 2
    ENDIF
    
    If cs and MAXSHARES and not shortonmarket then
    sellshort PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS 1
    SET TARGET %PROFIT 2
    ENDIF
    max-position.jpg max-position.jpg
    #182581 quote
    robertogozzi
    Moderator
    Master

    You cannot open opposite positions (Long & Short) in the same strategy.
    Anytime you go Long any previous Short position still open will be closed. The other way round when you go Short.
    PositionSize is correct, but it must be defined before being used.

    #182584 quote
    murre87
    Participant
    Senior

    It need to look like this?

    DEFPARAM CUMULATEORDERS = false
    defparam preloadbars = 10000
    PositionSize=1 
    
    CB = RSI[14]>50
    CS = RSI[14]<45
    
    If cb then // Entry long
    Buy PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS 1
    SET TARGET %PROFIT 2
    ENDIF
    
    If cs then // Exit long
    sell at market
    endif
    
    If cs then // Entry short
    sellshort PositionSize CONTRACTS AT MARKET
    SET STOP %LOSS 1
    SET TARGET %PROFIT 2
    ENDIF
    
    If cb then // Exit short
    exitshort at market
    endif
    #182588 quote
    PeterSt
    Participant
    Master

    What do i choose in “MAX Position” when i start the tradingsystem?

    1.

    However, I would be very careful with depending on that, because in my particular case it seems it does not work reliably. And do notice that this happens specifically in the situation that the Strategy additionally buys. In other words, enter less in that field than the Strategy wants to do and nothing ever starts (taking position), but set it to e.g. 1 and let the Strategy take position – then when it additionally want to take position (make 2 from 1) then it just does it.
    Thus, take care of not depending on it, as it seems that you do that (not 100% sure).

    murre87 thanked this post
    #182594 quote
    robertogozzi
    Moderator
    Master

    MAX positions set when starting the strategy in autotrading and the number of lots/contracts coded with BUY/SELLSHORT grant that the lowest of the two is the one actually used, so if Max is set to 999 but you BUY 1, only 1 contract will be bought, if you set Max to 5 and BUY 10, then only 5 contracts will be bought.

    I have never had problems with this, so far.

    #182598 quote
    nonetheless
    Participant
    Master

    The way I do it is not to control the number of contracts, but the number of entries. This way you can let your MM alter the positionsize.

    if not onmarket then
    flag1 = 1
    flag2 = 1
    flag3 = 1
    ENDIF
    
    // Conditions to enter long positions
    
    IF not longonmarket and CB and Flag1 THEN
    BUY positionsize CONTRACT AT MARKET
    flag1 = 0
    elsif longonmarket and CBA and flag2 then
    BUY positionsize CONTRACT AT MARKET
    flag2 = 0
    elsif longonmarket and CBA and flag3 then
    BUY positionsize CONTRACT AT MARKET
    flag3 = 0
    ENDIF
    

    You can repeat the elsif and flags 4, 5, 6 as many times as you want. You can also create different conditions for the additional positions (CBA vs CB).

    Eg. you might start the first entry within a certain time range, but let it add extra positions outside of that (ie overnight)

    or add other criteria such as “positionperf <0” so that your aggregate is always averaging down.

    murre87 thanked this post
    #182602 quote
    PeterSt
    Participant
    Master

    if you set Max to 5 and BUY 10, then only 5 contracts will be bought.

    Maybe you have a special system, but mine (for IG) does not enter at all in that case (which is what I am happy with or else things will happen I did not code).
    Maybe I am wrong with my observations.

    #182622 quote
    robertogozzi
    Moderator
    Master

    Yes, you are right PeterSt, if you set MAX=5 then if you BUY more than 5 no trade is opened.

    You can only buy 5 or less contracts. It makes sense.

    Actually I never used that, I always set MAX=999 then I apply lot size management up to that limit.

    #182632 quote
    PeterSt
    Participant
    Master

    Actually I never used that, I always set MAX=999 then I apply lot size management up to that limit.

    Yes, I did too, until I dynamically started to increase the position (during the original Trade-opening). So now I limit it (with say 5) in order not to run into an out of money and *that* part seems not to work reliably. So this is the other half of the story (“be careful with that !”) but it is hard to test – waiting for the situation to happen.
    See example of what I am talking about (if not obvious in the first place).

    image_2021-12-01_170428.png image_2021-12-01_170428.png
    #182635 quote
    robertogozzi
    Moderator
    Master

    I see, but with Lot & Money management that shouldn’t happen!

    #182637 quote
    PeterSt
    Participant
    Master

    I most certainly agree and this is in there all right (see attachment). Meanwhile with such setups I like to have an extra protection. Thus, I set my own MM a tad too high deliberately and want to see if that extra protection (by PRT) works.

    N.b.: It s also testing myself (or my code) in order to see what actually happens and how decent I coded it. Thus, if an order is rejected, how do I actually notice that, and is that not one bar too late to remain in control. Understand ?

    image_2021-12-01_173208.png image_2021-12-01_173208.png
    #182639 quote
    robertogozzi
    Moderator
    Master

    Ok, that’s clear.

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

CUMULATEORDERS – COUNTOFPOSITION


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
murre87 @murre87 Participant
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by robertogozzi
4 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/01/2021
Status: Active
Attachments: 3 files
Logo Logo
Loading...