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

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 geddyisodin, Today, 05:20 AM
    0 responses
    1 view
    0 likes
    Last Post geddyisodin  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    6 responses
    32 views
    0 likes
    Last Post JonesJoker  
    Started by GussJ, 03-04-2020, 03:11 PM
    12 responses
    3,239 views
    0 likes
    Last Post Leafcutter  
    Started by AveryFlynn, Today, 04:57 AM
    0 responses
    5 views
    0 likes
    Last Post AveryFlynn  
    Started by RubenCazorla, 08-30-2022, 06:36 AM
    3 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Working...
    X