Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Operators in If instruction

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

    Operators in If instruction

    I would like to use the bollinger bands with cellconditions in the Market Analyzer.
    So I created the If-instructions to select the Priceposition near the Bands.
    The If-instructions are not working and I don´t know why.





    I would be glad if someone can help me.

    I have here my cod -- OnBarUpdate:



    protected override void OnBarUpdate()
    {
    double smaValue = SMA(Period)[18];
    double stdDevValue = StdDev(Period)[0];


    Upper.Set(smaValue + NumStdDev * stdDevValue);
    Middle.Set(smaValue);
    Lower.Set(smaValue - NumStdDev * stdDevValue);


    if (Close[0] >= (smaValue + NumStdDev * stdDevValue))
    {
    Value.Set(1); // to be green in Market Analyzer
    }

    else if (Close[0] <= (smaValue - NumStdDev * stdDevValue))
    {
    Value.Set(2); // to be red in Market Analyzer
    }

    else if (Close[0] >= smaValue)
    {
    Value.Set(3); // to be dark green in Market Analyzer
    }

    else if (Close[0] <= smaValue)
    {
    Value.Set(4); // to be dark red in Market Analyzer
    }

    else Value.Set(5);

    // Alert("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);
    }





    For reply many thanks.

    #2
    Hi chartvisor,

    I recommend you add a print to your code and see what the value is before the condition.

    Print("Close: "+Close[0]+" >= upper :"+(smaValue + NumStdDev * stdDevValue));
    Print("Close: "+Close[0]+" <= lower: "+(smaValue - NumStdDev * stdDevValue));
    Print("Close: "+Close[0]+" >= smavalue: "+smaValue);
    Print("Close: "+Close[0]+" <= smavalue: "+smaValue);

    What do you get for these prints?

    (prints go to the output window (Tools -> Output Window...))
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea.B,

      thank you for your reply,

      with Print - I have found the Problem.

      It was very helpfull

      Thank you!





      Bye :-)

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      624 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      359 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      562 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      567 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X