• 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 Sh00tHerMcGavin, Today, 07:39 PM
      0 responses
      1 view
      0 likes
      Last Post Sh00tHerMcGavin  
      Started by Mberg, Today, 05:13 PM
      0 responses
      0 views
      0 likes
      Last Post Mberg
      by Mberg
       
      Started by Barry Milan, Today, 01:33 PM
      2 responses
      8 views
      0 likes
      Last Post marcus2300  
      Started by NW Trader, Today, 03:42 PM
      2 responses
      8 views
      0 likes
      Last Post NW Trader  
      Started by ralett, Today, 01:42 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Working...
      X