Division By Zero Error: Solved
Forums › ProRealTime English forum › ProOrder support › Division By Zero Error: Solved
- This topic has 12 replies, 2 voices, and was last updated 2 years ago by Khaled.
-
-
09/10/2017 at 11:51 AM #45869
Good Day Everyone
For those of you who have had issues with strategies stopping due to the division by zero issue, despite making provision to contain it I have found another cause and possible solution.
Other than the obvious reasons such as actual division by zero or division by undefined/null variables here is another cause I identified:
During weekends or outside market hours there are obviously no prices/quotes available and hence any calculation that requires such information will not be able to be calculated i.e. range
Thus containing your whole code (the parts that make sense obviously) inside an If statement that only executes/evaluates during market hours/weekdays you can effectively eliminate the division by zero error caused due to this particular reason.
Hope some of you might find this useful.
Regards
04/21/2020 at 2:05 PM #127267@juanj you make a good point about out of hours and no data which could cause this error but the systems should be paused by IG during “market closed” times and we should not get this error due to a market being closed. I’ve had a few instances when a systems still tries to calculate even though the market is closed.
I’m having this error: Division By Zero Error
The strange thing is that it’s somewhat inconsistent. I have one instance of a system on Demo that is running without the error on h1 but on m1 I get the error. In a live account on h1 I had this error occur and the system closed. It still might be due to an error in my code which I’m trying to find (and probably is the cause) but the inconsistency of running without error on h1 and error on m1 is what has me puzzled.
04/21/2020 at 2:12 PM #127271but the inconsistency of running without error on h1 and error on m1 is what has me puzzled.
It probably will be as Juanj says … on 1 min TF there will be a bar missing / no data.
But on 1 hour TF there will be a bar for 1 hour (doubtful no bar for 1 whole hour? ).
04/21/2020 at 2:35 PM #12727504/21/2020 at 2:56 PM #127278In a live account on h1 I had this error occur and the system closed?
But you said …
but the inconsistency of running without error on h1 and error on m1 is what has me puzzled.
Anyway have you clicked the setting / box on both Demo and Real Live to say Close trades if System stops?
Also when I said no data on M1 … I only meant like for 1 minute / bar there might be no data?
04/21/2020 at 4:22 PM #127280@Grahal why should it matter if I “clicked the setting / box on both Demo and Real Live to say Close trades if System stops.” the system stops (I see I wrote “closed” but I meant “stops”) because of the supposed “division error”.
The issue is the supposed error and not if the orders are closed or remain open or am I misunderstanding something?
04/21/2020 at 4:29 PM #127283am I misunderstanding something?
No … it’s more likely me not spending enough time reading and thinking etc.
Why don’t you post your code on here? The experts may spot something that is causing the problem?
04/25/2020 at 11:20 AM #127996I ran older version of my code on a Demo and it was working for a few days then I got this error.
One of the orders of this trading system was rejected. Due to the type of rejection, the trading system had to be stopped…
The Rejected error information is:
You have requested a closing transaction but either you have no open position in that market, or the size is greater than your existing position.
The code has 2 types of close orders:
12345floatingProfitValue = (((close-positionprice)*pointvalue)*countofposition)/pipsize // with a MARKET ORDERand... it has theSELL AT x LIMITWhen the system stopped because of the above error the SELL AT x LIMIT had closed 2 open BUY trades (as you will see in the attacehment) and then at the start of the next bar PRT ran the code and my guess is that for some reason it still thought there might have been an 2 open trades and tried to close them based on the floatingProfitValue but there was no longer any trades open. This is further supported by Order List report (attached). Furthermore, PRT kept trying to close the orders more than 11 times when it should have stopped them system unless something has changed with that 11 attempts/failure rule that I’m not up to date with?
Another interesting point is that at first “Pos. Chg” was
2 => 1
2 => 1
… for 12 times and then it went
1 => 0
then back to
2=> 1The error:
You have requested a closing transaction but either you have no open position in that market, or the size is greater than your existing position.
The thing is this system had completed many trades with the same conditions and no errors had occur but then randomly this time it had this issue.
I know this is different to the previous division By Zero Error but I think it might be related or the same but I just got a different error because on this occasion there were no open orders while with the “Division By Zero” I still had open orders.
I will send a report to PRT to see if they can identify if there’s an issue with the engine because that’s what I think is happening.
12/31/2021 at 4:22 PM #184222Hello folks!
Sharing my experience: : I keep experiencing the same problem again and again on NQ 1min TF and tried to check on the graph the candles where the system stops. The problem typically happens outside of normal trading hours. The problem in my case isn’t a division per zero as the PRT message says, it’s rather the size of the body of the current candle and/or the difference between the prices of the current candle and the previous candle. Very small difference (<0.5pts) body of the candle and/or current vs previous generates errors when (1) you have conditions including size of the candle and/or comparison with the previous candle and/or (2) minimum distance of SL required by the broker. This problem happens to me independently whether the Algo is in position or waiting for a signal.
Happy New year to all!
12/31/2021 at 5:52 PM #184224Use this code to never drop below 1:
1max(1,range) //or max(1,abs(close-open))2 users thanked author for this post.
01/05/2022 at 12:11 AM #184570@robertogozzi, I applied the max(1,range) and the error appeared again. I was in front the system, so there was a gap at the open midnight 5 Jan. Any clue how to solve this, because the Algo seems to calculate anyway. Thanks
1 user thanked author for this post.
01/05/2022 at 1:01 AM #184575The only place where I have the sign “/” in my code is the ALMA
1234567891011121314WindowSlow = 8//13//9SigmaSlow = 6//1//6OffsetSlow = 0.85PriceSlow = closemSlow = (OffsetSlow * (WindowSlow - 1))sSlow = WindowSlow/SigmaSlowWtdSumSlow = 0CumWtSlow = 0for kSlow = 0 to WindowSlow - 1 doWtdSlow = Exp(-((kSlow-mSlow)*(kSlow-mSlow))/(2*sSlow*sSlow))WtdSumSlow = WtdSumSlow + WtdSlow * PriceSlow[WindowSlow - 1 - kSlow]CumWtSlow = CumWtSlow + WtdSlownextALAverageSlow = WtdSumSlow / CumWtSlow“/(2*sSlow*sSlow))” this cannot be the problem, since “sSlow = WindowSlow/SigmaSlow”, 8/6 = 1,33
The other division is “ALAverageSlow = WtdSumSlow / CumWtSlow”, so I added the following and will see for the next few days
12345IF CumWtSlow = 0 thenALAverageSlow = ALAverageSlow[1]ELSEALAverageSlow = WtdSumSlow / CumWtSlowENDIF01/11/2022 at 5:07 PM #185144For what’s worth… For those with IG, who does some maintenance between 23:45 and 00:00 (French time), and who experience problems with their Algos shutting doan (divison by zeron not enough historical data, etc), problem number one identified above is the absence of quotation or gaps, and problem number two is the close=high=low=open.
See suggestion from Roberto to avoid the problem#184224.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on