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

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 bortz, 11-06-2023, 08:04 AM
            47 responses
            1,612 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            22 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X