Hello, I am writing here in hopes of someone having a solution, because I have tried probably seven different methods myself and the bot still gets stopped before taking trades in ProOrder.
The code is as follows:
defparam cumulateorders = FALSE
defparam preloadbars = 10000
// POSITION MANAGEMENT
positionsize = (50000/close)*0.3 //NIKKEI - spread 15
timeframe(weekly, updateonclose)
adxv = 16
ADXW = ADX[ADXv] > ADXR[ADXv]
timeframe(default)
nr=75
indicator1 = AccumDistr(TypicalPrice)[nr]
indi2 = indicator1[0]>indicator1[1] and indicator1[1]<indicator1[2]
if indi2 and ADXW then
buy positionsize contract at market
ENDIF
DonLow = close < DonchianChannelDown[4]
if onmarket and DonLow then
sell at market
ENDIF
I am running this on Nikkei, and when putting it on demo, it gets stopped the following day with the classic error message of “This strategy was stopped because one of its orders was rejected more than the allowed number of retries. To see the reason the order was rejected, open the order list, go to the”Canceled/Rejected” tab and place your mouse over the warning icon in the “Status” column.”.
I am aware of this error message usually showing up when there is an indicator that could have a possibility of being = 0. So I have tried different solutions in regard to that. I have also tried increasing the preloadbars, along with a few other things.
Should be mentioned as well that I am running the bot on FTSE as well, and there it has taken trades and run smoothly.
I am genuinely out of ideas/solutions, and hoping someone here could help, I am all open for suggestions. If you were to put it on your demo account to try a few solutions and see if something sticks, that would also be greatly appreciated.
//Jonathan
JSParticipant
Senior
It appears that the issue is most likely in the position sizing formula, where a calculated size results in a value that is invalid for the Nikkei…
To verify whether this is indeed the case, you can temporarily set the position size to 1 and check whether the algorithm stops again…
Can’t believe it was this all along. Worked out when I tried with one contract, thank you so so much!!
Do you potentially happened to have an explanation to why this was so? I am using this type of position sizing for all my algos, to make sure I always have the same security margin. I genuinely have no idea to why it would not be working specifically on Nikkei??
JSParticipant
Senior
Hi,
Glad to hear it worked…
In my view, the issue is most likely related to floating-point rounding applied by ProOrder when the calculated position size drops below 1…
One way to make the logic more robust is to add a simple safety guard, for example by checking whether PositionSize is smaller than 0.02 and, if so, forcing it back to 0.02 before sending the order…
This ensures that the order size never falls below the broker’s minimum tradable size and prevents order rejections caused by invalid volumes…
If PositionSize<0.02 then
PositionSize=0.02
EndIf
I have used the same positionsize for DAX and NASDAQ and never once experienced an issue when the sizing has been below 1, so I am very baffled.
I will try the Nikkei one with the <0.02 snippet and keep you posted. Thanks!
JSParticipant
Senior
I looked into this a bit further, and the combination of a 5% margin and a minimum position size of 0.02 only occurs for the Japanese index…
If you were to use this position size, the resulting margin would be:
54,000 × 5% × 0.02 = 54 euros of margin.
This does not align at all with the other indices, which is why I think IG has made an error here…
Whether this is actually a mistake or something that was done intentionally is always an open question with IG…
Do you have any tips on a position management that would create a similiar position sizing as I am after, a consistent security margin?
I tried this:
// POSITION MANAGEMENT
positionsize = (50000/close)*0.3 //NIKKEI - spread 15
positionsize2 = Round(positionsize*100)
positionsize3 = positionsize2/100
(where positionsize3 is the entry size)
Hoping it would sort out the round issue, but it also got rejected.
Try this:
//POSITIONMANAGEMENT
StepSize=0.01 //Step Size
MinSize=0.02 //Nikkeis Mininum Allowed Size
pMultiplier=0.1
RawSize=(50000/close)*pMultiplier
//AdjustSizeByStep
PositionSize2=floor(RawSize/StepSize)*StepSize
//ApplyMinimumRequirement
IF PositionSize2 <MinSize THEN
PositionSize3=MinSize
ELSE
PositionSize3=PositionSize2
ENDIF
JSParticipant
Senior
Hi,
Your “Position Management” is not incorrect; the issue appears to be on IG’s side…
I think that in this case the minimum position size is 1 (the information provided by IG seems to be incorrect)…
Something that has never crossed my mind but I noticed now that I payed attention is that IG has a minimum size of 0.5 contracts if taking a Nikkei Trade with your demo account on their website. But the minimum size when doing it live is 0.02. Have tried adjusting the size a bit on a few of my demo attempts and now additionally running:
If PositionSize<0.5 then
PositionSize=0.5
EndIf
I will keep you posted if it still gets stopped!
Just an update: this was the issue all along. Nikkei has different minimum size on demo than live, so I with the rule of minimum 0.5 contracts it worked out with the dynamic code I wanted to use. Thanks for the help all!