• 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, 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 sgordet, Today, 08:07 PM
      0 responses
      1 view
      0 likes
      Last Post sgordet
      by sgordet
       
      Started by smcllr, Today, 08:04 PM
      0 responses
      1 view
      0 likes
      Last Post smcllr
      by smcllr
       
      Started by 5element, Today, 02:46 PM
      1 response
      22 views
      0 likes
      Last Post Emma1
      by Emma1
       
      Started by jeronymite, Today, 04:47 PM
      0 responses
      11 views
      0 likes
      Last Post jeronymite  
      Started by jtrading82, Today, 04:05 PM
      0 responses
      7 views
      0 likes
      Last Post jtrading82  
      Working...
      X