code for limiting the number of cumulative orders

Viewing 15 posts - 16 through 30 (of 30 total)
  • Author
    Posts
  • #147223 quote
    nonetheless
    Participant
    Master

    but if the positionsize were 0.8 and it had cumulated 7 orders then countofposition would be 5.6 … so round(CountOfPosition/positionsize) = 6 and no more positions would be allowed.

    I would prefer if it could always max at 8 x positionsize, but less is better than more.

    #147235 quote
    swedshare
    Participant
    Senior

    You’re right, it creates a conflict between positionsize and maxallowedorders. Illustrated in attached pic where I put startpositionsize at 0.2 and maxallowedorders at 1. It stops accumulating orders when positionsize reaches 1.

    Moderators, is it possible to get around this?

    test.jpg test.jpg
    #147238 quote
    nonetheless
    Participant
    Master

    for me the fifi743 solution works well enough:

    Once MaxPositionsAllowed = 8
     
    // Conditions to enter long positions
    IF Ctime and myconditions and round(CountOfPosition/positionsize) <= MaxPositionsAllowed THEN

    I posted a new version of the NAS Hull-SAR with this change, tested with MM – seems ok, you can check it out. Haven’t tried changing the DJ version yet.

    #147309 quote
    fifi743
    Participant
    Master

    Hi nonetheless,
    Yes, I’m fine and you?
    I use COUNTOFLONGSHARES and COUNTOFSHORTSHARES .

    #147324 quote
    nonetheless
    Participant
    Master

    hi Fifi, yes all good thanks. Haven’t died of Covid … yet.

    Unfortunately, as for this code, I just realised that your solution only works when the positionsize is close to 1

    In the above example, where MaxPositionsAllowed = 8, if positionsize = .4 then round(CountOfPosition/positionsize) <= MaxPositionsAllowed will allow 20 x .4 orders

    With positionsize = 2.5 it would only allow 3 orders.

    What I want is a max of 8 orders regardless of the size – something like MaxPositionsAllowed = (positionsize x 8) but i can’t have that.

    Any other ideas?

    #147330 quote
    JC_Bywan
    Moderator
    Master

    You could add a new variable to your code, starting it at zero, incrementing it by +1 at each new order (regardless of how much positionsize is), checking it’s not more than 7 in the “if” statement before each order (to reach 8 max), and reseting it equal to zero when not on market?

    nonetheless thanked this post
    #147331 quote
    robertogozzi
    Moderator
    Master

    You can only count trades anytime BUY or SELLSHORT is executed and stop when you reach your limit.

    Reset the count to zero when not on market or when it changes from long to short and viceversa in case of stop & reverse.

    nonetheless thanked this post
    #147357 quote
    pableitor
    Participant
    Master

    If maxpositionsallowed is the total number of  operations (the name is confusing , position usually refers to the total amount of contracts or money opened, not number of operations) why dont you try this:

    Once MaxPositionsAllowed = 8
     
    // Conditions to enter long positions
    IF Ctime and myconditions and (CountOfPosition + positionsize) <= MaxPositionsAllowed * positionsize THEN
    BUY positionsize CONTRACTS AT MARKET
    // Conditions to enter short positions
    IF Ctime and myconditions and abs(CountOfPosition) + positionsize <= MaxPositionsAllowed * positionsize THEN
    SELLSHORT positionsize CONTRACTS AT MARKET
    
    nonetheless thanked this post
    #147365 quote
    J.
    Participant
    Average

    If you want no more than 8 positions and your position size is 0.8 then the calculation should be

     

    MaxPositionsAllowed = 8 * positionsize
    
    IF CountOfPosition < MaxPositionsAllowed THEN
        //place order
    ENDIF

    CountOfPosition gives you the number of total contracts open. If you want to count short positions this becomes a negative number.

    You could also use COUNTOFSHORTSHARES and COUNTOFLONGSHARES for this though.

    nonetheless thanked this post
    #147373 quote
    fifi743
    Participant
    Master

    Hi nonetheless,
    I’m on the DJI in 0.2 contract.
    Look at the attached pictures.

    Capture-decran-138.png Capture-decran-138.png Capture-decran-139.png Capture-decran-139.png Capture-decran-140.png Capture-decran-140.png
    #147389 quote
    nonetheless
    Participant
    Master

    Thanks @J. – yes that is the obvious solution and it’s the first thing I tried but for some reason it went completely peculiar. Now it seems fine though, so apparently I had made some other error that was in conflict. I’ll have to watch it in forward testing to make sure it’s doing what i want.

    fifi743 thanked this post
    #147395 quote
    nonetheless
    Participant
    Master

    Look at the attached pictures.

    yes, in theory it looks like it should work but in practice, running Maxpositionsallowed =5 and positionsize .4 it opened 12 separate orders. I think MaxPositionsAllowed = n * positionsize could be the better way to go.

    fifi743 thanked this post
    #147891 quote
    josef1604
    Participant
    Senior

    Hola, ¿has conseguido limitar los pedidos? Ver el sistema de comercio HULL-SAR sigue haciendo más entradas

    Hello, have you managed to limit orders? See the HULL-SAR trading system keeps making more entries

    #147897 quote
    robertogozzi
    Moderator
    Master

    @josef1604

    Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.

    Thank you 🙂

    #147917 quote
    nonetheless
    Participant
    Master

    Hello, have you managed to limit orders?

    Yes, if you see the most recent version posted there it controls the number of entries.

    josef1604 thanked this post
Viewing 15 posts - 16 through 30 (of 30 total)
  • You must be logged in to reply to this topic.

code for limiting the number of cumulative orders


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 29 replies,
has 8 voices, and was last updated by nonetheless
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/12/2020
Status: Active
Attachments: 5 files
Logo Logo
Loading...