• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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, 05: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 faisamtrader, Today, 10:31 AM
      1 response
      16 views
      0 likes
      Last Post NinjaTrader_Tyler  
      Started by ChazJ, Today, 09:48 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by maxie, Today, 10:01 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Melissa  
      Started by Bionian, Today, 09:36 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Started by tomd, Today, 09:48 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Ariana  
      Working...
      X