Divide by Zero issues

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #153652 quote
    Monobrow
    Participant
    Senior

    Hi

    My system is stopping every Sunday night at 2305 without fail. It works the rest of the week. The reason if gives me is more or less a divide by zero error. I believe the reason is because there is not sufficent data (previous bars) in order for me to make the required calculation.

    The code I am using is along the lines of

    Gap = Close-CustomClose[1]

    IF <indicator> and GAP <= 21 THEN

    Etc etc

     

    I believe at certain times Gap is not able to return a value so the system fails. Is there a way to code around this? something along the lines of:

     

    If Gap = Null/Error then do nothing Else carry on etc?

    Hope this makes sense as I kind of new to ccoding.

     

    thanks!

    #153657 quote
    GraHal
    Participant
    Master

    Try …

    Gap = max(1, Close-CustomClose[1])
    Monobrow thanked this post
    #153658 quote
    robertogozzi
    Moderator
    Master

    You can try this to make sure it’s never 0:

    Gap = Close-CustomClose[1]) + 0.000001

    this small amount shouldn’t affect your performance (but you can increase or decrease it).

    You can also write it as:

    Gap = Close-CustomClose[1]
    IF Gap = 0 THEN
       Gap = 0.000001
    ENDIF
    Monobrow thanked this post
    #153659 quote
    robertogozzi
    Moderator
    Master

    @GraHal

    that works with positive numbers, but in this case the gap can be negative and your code could change it quite a bit!

    GraHal and Monobrow thanked this post
    #153663 quote
    Monobrow
    Participant
    Senior

    Doh!, yes, that seems so intuitive and obvious (now I see it!).

    Thank you so very much, I will try these out.

    #153664 quote
    GraHal
    Participant
    Master

    now I see it!).

    Must have been that monobrow obstructing your vision! 🙂  (sorry couldn’t resist! 🙂 )

    JC_Bywan thanked this post
    #153677 quote
    Monobrow
    Participant
    Senior

    now I see it!).

    Must have been that monobrow obstructing your vision! 🙂 (sorry couldn’t resist! 🙂 )

    Haha, I guess i deserved that! 😬

    GraHal thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Divide by Zero issues


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Monobrow @monobrow Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Monobrow
5 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/14/2020
Status: Active
Attachments: No files
Logo Logo
Loading...