Division by zero ERROR
Forums › ProRealTime English forum › ProOrder support › Division by zero ERROR
- This topic has 19 replies, 6 voices, and was last updated 3 years ago by GraHal.
-
-
06/11/2020 at 6:13 AM #135531DAX 30123456789101112131415161718192021222324252627// DAX 30DEFPARAM CumulateOrders = Falsedefparam preloadbars = 10000TIMEFRAME (60 MINUTES, UPDATEONCLOSE)c7 = Average[50] > Average[50][1]TIMEFRAME (10 MINUTES, UPDATEONCLOSE)indicator11 = Stochastic[14,3](close)c14 = (indicator11 > 95)TIMEFRAME (Default)// DonchianV = 23DonchianInfV = lowest[V](low)indicator1 = CALL VWAP1c2 = close crosses under DonchianInfV[1]c1 = (close > indicator1)IF c1 and c2 and c7 THENbuy 1 shares at marketENDIFset stop $loss 90IF longonmarket and C14 THENsell at marketendifVWAP1234567891011121314d = max(1, intradaybarindex)VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)if(intradaybarindex=0) thenendifif vwap>vwap[1] thencolor = 1elsecolor = -1endifRETURN VWAP coloured by color STYLE(LINE,2) as "VWAP"
Hey guys!
i still get the same error, division by zero…. only difference now is that it takes a few hours before it stops, i inerted the code for the strat and the vwap indicator
06/11/2020 at 9:06 AM #135551Hi, sorry to ask if you’ve already checked, but just in case : if running the strategy on cfd on 24h basis, considering it calls Vwap which requires volume data in denominator, do you have in place somewhere a safeguard in order to avoid the first few bars of the day with no volume where it’s not possible to have a vwap?
The safeguard max(1,intradaybarindex) on line 1 of vwap code protects you from having no bar to make the summation on, ok… But if calculated too early on bars with no volume on a cfd Germany30 instrument before 2.15am when Dax futures market opens, it won’t prevent in line 3 summation[d](volume) from summing zero’s resulting in a division by 0 for vwap.
06/11/2020 at 11:04 AM #13556506/12/2020 at 1:25 PM #135735As far as vwap is concerned there are several easy ways you could improve this vwap code.
Moderator hat on, considering plenty of beginners recently joined, I would have to suggest most of these ways probably are already in the forum past topics, either in the “similar topics” suggested just after the last messaeg of this page (and just above the reply box), or reachable with the search box on the site frontpage (or in the drop down menu from your avatar top right corner of this page).
But taking the moderator hat off and putting the “prt user just like anyone else” hat on, I’ll go further and suggest adding an “if” statement to avoid candles when volume=0. It would avoid the inelegant way of selecting time which would make the code not compatible with other instruments for which volume does not start at the same time. Something like:
12345if SUMMATION[d](volume)<>0 thenVWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)elsevwap=0endifOf course you would have to check vwap=0 doesn’t introduce problems in the main code calling the vwap code (like not dividing by vwap…)
However, maybe it won’t solve it all in case you might be in a multiple bugs hunt here, but at least it opens you the door to finding your next bug. Because I see 2 things on page 1 :
1) it doesn’t seem to be the same vwap code you were calling, so the unseen full vwap initial code might need more cleaning up.
2) you mentionned having the problem early on in the strategy before, assuming that’s in the same day as launching the strategy, that couldn’t be because of vwap at night, it is likely there remains something else to solve…
Anyway, I hope it helped at least a little bit, good luck.
06/12/2020 at 2:25 PM #135748Above code added as Log 222 to here …
-
AuthorPosts
Find exclusive trading pro-tools on