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 CarlTrading, 03-31-2026, 09:41 PM
              1 response
              42 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by CarlTrading, 04-01-2026, 02:41 AM
              0 responses
              20 views
              0 likes
              Last Post CarlTrading  
              Started by CaptainJack, 03-31-2026, 11:44 PM
              0 responses
              29 views
              1 like
              Last Post CaptainJack  
              Started by CarlTrading, 03-30-2026, 11:51 AM
              0 responses
              46 views
              0 likes
              Last Post CarlTrading  
              Started by CarlTrading, 03-30-2026, 11:48 AM
              0 responses
              38 views
              0 likes
              Last Post CarlTrading  
              Working...
              X