Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Logic Problem?

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

    Logic Problem?

    Can anyone tell me why this does not work? It never prints an arrow.

    protected override void OnBarUpdate()
    {
    if (Low[0] < Low[1]) // Problem is in this line.
    {
    DrawArrowUp("Up" + CurrentBar, false, 0, Low[0] - (1 * TickSize), Color.Blue);
    }
    }

    I know the problem is in the 'if' statement, if I change it to

    if (Close[0] >= Median[0])

    It prints arrows correctly.

    Thanks
    Dave

    #2
    Dave,

    I was about to post a near identical question to the board when I saw your post from today. I'm having the same problem with simple logic. My code is as follows:

    double myInteger = Close[1];
    if (Close[0] > myInteger)
    {
    Plot0.Set(100);
    } else {
    Plot0.Set(0);
    }

    My code is actually a modified thing that I did during troubleshooting but you'll see that the problem boils down to the same thing...

    Comparing basic OHLC data between two bars when one references a historic value.

    Close[0] > Close[1]

    Just like you... if I do something like Close[0] = Open[0], it works. But once I reference a [1] or [2], it breaks.

    This seems so fundamental that I feel like an idiot for not figuring it out. But I'm glad to know that I'm not alone and there's clearly some trick we're both missing.

    Comment


      #3
      I went through the same agony. It seemed so simple that I thought I must be doing something stupid.

      Hopefuly someone will have the answer.

      Comment


        #4
        In case any NinjaTrader admin reads this thread and wants to chime in... here's the simplest demonstration of the problem I could think of:

        If you follow Lesson 1 from the NinjaScript help tutorials you create an indicator that draws a line every time the close price = the open price. The code is this:

        protected override void OnBarUpdate()
        {
        Plot0.Set(Open[0] == Close[0] ? 1 : 0);
        }

        If all you do is change it to this:

        protected override void OnBarUpdate()
        {
        Plot0.Set(Open[0] == Close[1] ? 1 : 0);
        }

        The whole thing fails to plot. No errors come up. And it compiles successfully... just is a blank plot on the chart.

        Comment


          #5
          Errors do come up with those codes you guys are using. You will see it in the Control Center log. Please see this tip on what needs to be done: http://www.ninjatrader-support2.com/...ead.php?t=3170
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            So there you go Noevictorian, we WERE doing something wrong.

            Thanks very much Josh, that fixed it.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            152 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            89 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            131 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            127 views
            1 like
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            107 views
            0 likes
            Last Post CarlTrading  
            Working...
            X