Division by zero error

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #140810 quote
    snucke
    Participant
    Veteran

    hello!

    i have found a condition i want to use in a strategy on the 1 min TF that is causing the error “division by zero”

    and here it is

    c2 = (abs(close-open) / range <= 0.1) and close < open

    anyone know a way how to solve this?

    #140811 quote
    Nicolas
    Keymaster
    Master

    “range” is equal to zero because a candle is missing. You could probably get rid of this error by using this sort of code:

    c2 = (abs(close-open) / max(range,pipsize) <= 0.1) and close < open
    snucke thanked this post
    #140921 quote
    PhilA
    Participant
    New

    I had a similar problem where I was trying to calculate a dynamic position size and was getting a divide by zero error when the current price was equal to a variable I called “Entry”.

    I fixed it like this:

    PositionSize = abs(round(Maxrisk/((close+0.00001) - Entry)))

    It’s not pretty but it works.

    By always adding that tiny .00001 to the current close it ensures the two things are never equal and therefore no chance of division by 0.

    Hope that helps.

    Nicolas, snucke and robertogozzi thanked this post
Viewing 3 posts - 1 through 3 (of 3 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 2 replies,
has 3 voices, and was last updated by PhilA
5 years, 6 months ago.

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