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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      156 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      90 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      140 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 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