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

Why CrossBelow doesn't work??

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

    Why CrossBelow doesn't work??

    Why why why???

    Procedure chkTendencia() executing OnBarUpdate() event always.
    var Tendencia="N" always ( is a strategy parameter )

    Code:
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                }
                else if (State == State.Configure)
                {
                    SMA(SMAPeriod).Plots[0].Brush = Brushes.Green;
                    WMA(SMAPeriod).Plots[0].Brush = Brushes.Red;
                    AddChartIndicator(SMA(SMAPeriod));
                    AddChartIndicator(WMA(SMAPeriod));    
                }
                else if (State == State.DataLoaded)
                {    
                    SMA1         = SMA(Closes[0], SMAPeriod);
                    WMA1         = WMA(Closes[0], SMAPeriod);
                }
            }
    
    
            // ************************************************** *****************************    
            public void chkTendencia()
            {    
                string oldTend=myTendencia;
                if (Tendencia=="N")
                {
                    myTendencia = "A";
                    if (CrossBelow(WMA1, SMA1, 1)) myTendencia = "B";
                    if (oldTend!=myTendencia)
                    {    
                        totLines++;
                        Draw.Text(this,string.Format("TEXT{0}",totLines), string.Format("New Tend: {0}",myTendencia) ,0,High[0]+5);
                    }
                }
            }
    Thanks!
    Last edited by mbcito; 12-02-2019, 06:33 AM.

    #2
    Hello mbcito,

    Thanks for your post.

    I would suggest debugging your code by using Print statements. The Print statement will send its output to the New>Ninjascript output window.

    The CrossBelow() method in your code requires Tendencia=="N" to be true before it can even check for a cross so you would want to print out the value Tendencia. to see when specifically it is true and then Print the value myTendencia to see when it changes.

    Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm

    Here is an example that may help: Print (Time[0]+" Tendencia = "+Tendencia); // print the close time of the bar and the value of Tendencia on that bar.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul!!!

      Now I' am doing this, and it's working good!

      Code:
              public void chkTendencia()
              {    
                  string oldTend=myTendencia;
                  if (Tendencia=="N")
                  {
                      myTendencia = "A";
                      //if (CrossBelow(WMA1, SMA1, 1)) myTendencia = "B";
                      if (WMA1[0] < SMA1[0] ) myTendencia = "B";
                      if (oldTend!=myTendencia) 
                      {    
                          totLines++;
                          Draw.Text(this,string.Format("TEXT{0}",totLines), string.Format("New Tend: {0}",myTendencia) ,3,SMA1[0]+1);
                      }
                  }
              }
      Regards, Mariano

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Aviram Y, Today, 05:29 AM
      0 responses
      2 views
      0 likes
      Last Post Aviram Y  
      Started by quantismo, 04-17-2024, 05:13 PM
      3 responses
      25 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by ScottWalsh, 04-16-2024, 04:29 PM
      7 responses
      34 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by cls71, Today, 04:45 AM
      0 responses
      6 views
      0 likes
      Last Post cls71
      by cls71
       
      Started by mjairg, 07-20-2023, 11:57 PM
      3 responses
      217 views
      1 like
      Last Post PaulMohn  
      Working...
      X