Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with If/else

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

    Problem with If/else

    Hello:

    I'm building a indicator that have a line called "Maximo", and I want that when the value of "Maximo" is equal to the value of the MACD, a new variable called "IgualMax" worth the same as "Maximo".

    I tried to program it but it gave me errors. I hit the code to see if you can help me.

    Code:
     protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Minimo"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Maximo"));
                Add(new Plot(Color.FromKnownColor(KnownColor.GreenYellow), PlotStyle.Line, "IgualMax"));
                Add(new Line(Color.FromKnownColor(KnownColor.MediumBlue), 0, "Cero"));
                Overlay				= false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                	double Macd = MACD(Close, 12, 26, 9) [0];
    			
    			
    				if(Maximo[0]==Macd)
    					{
    						IgualMax = Maximo[0]);
    					}
    					else
    					{
    						IgualMax = 0;
    					}
    			
    			// Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                Minimo.Set(MACD(Close,12,26,9) [LowestBar(MACD(Close,12,26,9), Perios)]);
                Maximo.Set(MACD(Close,12,26,9) [HighestBar(MACD(Close,12,26,9), Perios)]);

    I think that the problem is specifically here:

    Code:
    				if(Maximo[0]==Macd)
    					{
    						IgualMax = Maximo[0]);
    					}
    					else
    					{
    						IgualMax = 0;
    					}

    Thank you very much for your help, and sorry for my bad english level.

    #2
    Hello rubenyes,
    Welcome to the forum and I am happy to assist you.


    To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

    Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

    I look forward to assisting you further.

    *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
    JoydeepNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    576 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    553 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X