Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Attempted to divide by zero

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Attempted to divide by zero

    Hello.

    I'm running a strategy that I've run many times before without error.

    I have both SetTrailStop(() and SetProfitTarget() in the OnExecution() routine.

    I have trace=true on and I see messages saying, "Amended trail stop order" as the price moves.

    After some messages, the output says, "Attempted to divide by zero."

    I've never seen that message before.

    What could be causing that?

    #2
    Hello SilverSurfer1,

    The error can only be reproduced when calling SetTrailStop()? If this is commented out the behavior stops?

    Please provide the line of code calling SetTrailStop() so that we may verify the price supplied is valid.

    May I also confirm you are using 8.0.27.1? (Help -> About)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm running NT 7.0.1000.43

      I think I see kind of what's happening.

      _addDD = (int)Math.Abs(Performance.RealtimeTrades.TradesPer formance.Currency.DrawDown);
      _addDD = _addDD / (int)TickSize;

      I recently added the above two lines. Later I set the target price in SetProfitTarget() by adding the absolute value of the DrawDown to my initial profit of $200.

      When it runs those two statements, I immediately see an "Attempted Divide By Zero."

      There is something going on when I try to cast a "double" value to an integer and add it to another integer.

      Not 100% sure what is trying to divide by zero, but for now I'll take out that code.

      Thanks.


      Comment


        #4
        Hello SilverSurfer1,

        An integer is a whole number. If the TickSize (which is a double) was 0.25, and was cast to an int, it would have a value of 0 as the decimal would be dropped.

        Maybe you mean to divide first and then cast to an int?

        (int)(_addDD / TickSize)


        Thank you for providing the version. I overlooked where this was posted in the forums.

        Please note, NinjaTrader 7 is no longer in active development and we are no longer considering new feature requests or changes for NinjaTrader 7. Main development has shifted to our flagship platform NinjaTrader 8. This does mean updates from brokerages, data feeds, or operating systems that require an update in NinjaTrader will not be implemented in NinjaTrader 7 and may cause an interruption in service.

        While there is not a set ETA for the complete discontinuation of NinjaTrader 7, we highly recommend transitioning to NinjaTrader 8 as soon as possible before NinjaTrader 7 reaches its end of life to prevent interruption of service.

        Click below to download NinjaTrader 8.
        http://ninjatrader.com/GetStarted
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          if( Math.Abs(Performance.RealtimeTrades.TradesPerforma nce.Currency.DrawDown) > 0.00) {

          _addDD = (int)(Math.Abs(Performance.RealtimeTrades.TradesPe rformance.Currency.DrawDown) / TickSize);
          _profitTarget = _profitTarget + _addDD;

          }​

          This removed the "Attempted Divide by Zero"

          Thanks for the help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Spiderbird, Today, 12:15 PM
          2 responses
          7 views
          0 likes
          Last Post Spiderbird  
          Started by WHICKED, Today, 12:45 PM
          0 responses
          3 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by FrazMann, Today, 11:21 AM
          2 responses
          6 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by rjbtrade1, 11-30-2023, 04:38 PM
          2 responses
          80 views
          0 likes
          Last Post DavidHP
          by DavidHP
           
          Started by lorem, Yesterday, 09:18 AM
          5 responses
          18 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X