Division by zero ERROR

Viewing 5 posts - 16 through 20 (of 20 total)
  • Author
    Posts
  • #135531 quote
    snucke
    Participant
    Veteran
    // DAX 30
    DEFPARAM CumulateOrders = False
    defparam preloadbars = 10000
    TIMEFRAME (60 MINUTES, UPDATEONCLOSE)
    c7 = Average[50] > Average[50][1]
    TIMEFRAME (10 MINUTES, UPDATEONCLOSE)
    indicator11 = Stochastic[14,3](close)
    c14 = (indicator11 > 95)
    TIMEFRAME (Default)
    
    // Donchian
    V = 23
    
    DonchianInfV = lowest[V](low)
    indicator1 = CALL VWAP1
    c2 = close crosses under DonchianInfV[1]
    c1 = (close > indicator1)
    
    IF c1 and c2 and c7 THEN
    buy 1 shares at market
    ENDIF
    
    set stop $loss 90
    
    IF longonmarket and C14 THEN
    sell at market
    endif
    
    d = max(1, intradaybarindex)
     
    VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
    if(intradaybarindex=0) then
    endif
    
     
    if vwap>vwap[1] then
    color = 1
    else
    color = -1
    endif
     
    RETURN 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

    #135551 quote
    JC_Bywan
    Moderator
    Master

    Hi, 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.

    GraHal and Nicolas thanked this post
    #135565 quote
    snucke
    Participant
    Veteran

    okay, so that means i cant use vwap in the strat? or is there a way to work around that problem?

    #135735 quote
    JC_Bywan
    Moderator
    Master

    As 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:

    if SUMMATION[d](volume)<>0 then
      VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
    else
      vwap=0
    endif
    

    Of 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.

    #135748 quote
    GraHal
    Participant
    Master

    Above code added as Log 222 to here …

    Snippet Link Library

Viewing 5 posts - 16 through 20 (of 20 total)
  • You must be logged in to reply to this topic.

Division by zero ERROR


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
snucke @snucke Participant
Summary

This topic contains 19 replies,
has 6 voices, and was last updated by GraHal
5 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/08/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...