Division By Zero Error

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #237070 quote
    whateveritmightbewhateveritmightbe
    Participant
    Junior

    Good Day Everyone,

    this is about another division by zero issue. It does happen to me with various instruments (NDX, DAX etc.) only within the 1M time frame.
    I checked other forum posts and tried a few things: -volume is > 0, -only execute in a selected time frame, -tried the min and max function

    Here is part of the code (I think it happens with “mySTOLong = STOCHASTIc…”, if I set it the mySTOLong value to 0 it does work).
    And of course every time it stops i see that close = open and open = high and high = low….

    Any idea or comment is highly appreciated!

    Thx Oliver

    mySTOnLong                    = 1 
    mySTOkLong                    = 6
    mySTOsmootherLong             = 4 
    mySTOlookPeriodsLong          = 11 
    mySTOoverBoughtLimitLong      = 90 
    mySTOoverSoldLimitLong        = 49 
    LongTime                      = time>=090000 and time<170000
    
    
    if longtime and NOT ONMARKET then
    
    // STOCHASTIC CONDITION
    //
    mySTOLong                     = STOCHASTIc[mySTOnLong,mySTOkLong](close)
    
    
    //mySTOLong                     = 0 // STOCHASTIc[mySTOnLong,mySTOkLong](close)
    
    
    mySTOsmoothedLong             = AVERAGE[mySTOsmootherLong](mySTOLong)
    mySTOcrossOverLong            = SUMMATION[mySTOlookPeriodsLong]((mySTOLong CROSSES OVER mySTOsmoothedLong) AND (mySTOLong < mySTOoverSoldLimitLong))
    mySTOnotOverBoughtLong        = (mySTOLong < mySTOoverBoughtLimitLong) AND (mySTOsmoothedLong < mySTOoverBoughtLimitLong)
    mySTOconditionLong            = mySTOcrossOverLong AND mySTOnotOverBoughtLong
    
    
    ENDIF
    
    #237071 quote
    JC_BywanJC_Bywan
    Moderator
    Master

    Hi,

    it might be because with mySTOnLong=1, this means the stochastic calculation is made with a division of high-low, and that would indeed be worth zero when high=low.

    Maybe an if statement checking high vs low for mySTOnLong=1, or >1 on its own (although it might happen again with mySTOnLong=2 if 2 consecutive candles with twice same high=low, but not as frequently, a more general condition could be written if that’s the case):

    if (mySTOnLong=1 and high<>low) or  mySTOnLong>1 then

    mySTOLong = STOCHASTIc[mySTOnLong,mySTOkLong](close)

    else

    mySTOLong = // choose what default value to give when high=low and stochastic cannot be calculated over a span of mySTOnLong=1

    endif

    Iván González thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Division By Zero Error


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by JC_BywanJC_Bywan
2 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/04/2024
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...