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 Hwop38, 05-04-2026, 07:02 PM
    0 responses
    161 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    312 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    245 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    350 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    179 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X