Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Totally noob question about barsago

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

    Totally noob question about barsago

    Ok let's say I want to compare the current MACD value to the previous value:

    double macd1 = MACD(period1, period2, smooth).Avg[0];
    double macd2 = MACD(period, period2, smooth).Avg[1];

    if (macd1<macd2)
    {do something}

    macd1 seems to be computing fine but macd2 is not.

    Where am I messing up? Thanks!


    #2
    I think...

    Code:
    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] macd2 = MACD(period, period2[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], smooth[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[COLOR=Red][1][/COLOR].Avg[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]; [/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    Comment


      #3
      Hello,


      Try adding this before the condition:

      Print(macd1 + " macd1");
      Print(macd2 + " macd2");

      Then go to Tools>Output Window and see what prints when the strategy is running.

      If that doesn't work try printing your macd parameters before they are assigned to macd1 and macd2.

      Another possible issue may be that you do not have enough bars to calculate the macd. Please review this link:
      DenNinjaTrader Customer Service

      Comment


        #4
        When I put this in I get nothing

        Print(macd1 + " macd1");
        Print(macd2 + " macd2");

        If I remove the macd2 line I get all the values for macd1 in the output window.

        Comment


          #5
          I think what ben means is the following

          Code:
          Print("MACD1 = " + macd1.ToString());
          Print("MACD2 = " + macd2.ToString());
          Did you try what I suggested?
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment


            #6
            Hello,



            The issue is probably arising from not adding if(CurrentBar > some_number) return; at the top of the OnBarUpdate() block.
            DenNinjaTrader Customer Service

            Comment


              #7
              Thanks that worked perfectly.

              Originally posted by NinjaTrader_Ben View Post
              Hello,



              The issue is probably arising from not adding if(CurrentBar > some_number) return; at the top of the OnBarUpdate() block.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              607 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              353 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
              560 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              561 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X