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

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 Haiasi, 04-25-2024, 06:53 PM
              2 responses
              16 views
              0 likes
              Last Post Massinisa  
              Started by Creamers, Today, 05:32 AM
              0 responses
              4 views
              0 likes
              Last Post Creamers  
              Started by Segwin, 05-07-2018, 02:15 PM
              12 responses
              1,786 views
              0 likes
              Last Post Leafcutter  
              Started by poplagelu, Today, 05:00 AM
              0 responses
              3 views
              0 likes
              Last Post poplagelu  
              Started by fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,407 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Working...
              X