code for limiting the number of cumulative orders
Forums › ProRealTime English forum › ProOrder support › code for limiting the number of cumulative orders
- This topic has 29 replies, 8 voices, and was last updated 3 years ago by nonetheless.
-
-
10/12/2020 at 9:07 PM #147223
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.
10/12/2020 at 10:44 PM #147235You’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?
10/12/2020 at 10:56 PM #147238for me the fifi743 solution works well enough:
1234Once MaxPositionsAllowed = 8// Conditions to enter long positionsIF Ctime and myconditions and round(CountOfPosition/positionsize) <= MaxPositionsAllowed THENI 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.
10/13/2020 at 3:30 PM #14730910/13/2020 at 4:56 PM #147324hi 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?
10/13/2020 at 5:13 PM #147330You 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?
1 user thanked author for this post.
10/13/2020 at 5:16 PM #147331You 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.
1 user thanked author for this post.
10/14/2020 at 12:46 AM #147357If 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:
12345678Once MaxPositionsAllowed = 8// Conditions to enter long positionsIF Ctime and myconditions and (CountOfPosition + positionsize) <= MaxPositionsAllowed * positionsize THENBUY positionsize CONTRACTS AT MARKET// Conditions to enter short positionsIF Ctime and myconditions and abs(CountOfPosition) + positionsize <= MaxPositionsAllowed * positionsize THENSELLSHORT positionsize CONTRACTS AT MARKET1 user thanked author for this post.
10/14/2020 at 9:28 AM #147365If you want no more than 8 positions and your position size is 0.8 then the calculation should be
12345MaxPositionsAllowed = 8 * positionsizeIF CountOfPosition < MaxPositionsAllowed THEN//place orderENDIFCountOfPosition 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.
1 user thanked author for this post.
10/14/2020 at 9:50 AM #14737310/14/2020 at 10:46 AM #147389Thanks @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.
1 user thanked author for this post.
10/14/2020 at 11:02 AM #147395Look 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.
1 user thanked author for this post.
10/20/2020 at 12:16 PM #14789110/20/2020 at 1:00 PM #147897Only 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 🙂
10/20/2020 at 2:32 PM #147917Hello, have you managed to limit orders?
Yes, if you see the most recent version posted there it controls the number of entries.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on