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 timmbbo, Today, 08:59 AM
      0 responses
      1 view
      0 likes
      Last Post timmbbo
      by timmbbo
       
      Started by bmartz, 03-12-2024, 06:12 AM
      5 responses
      33 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by Aviram Y, Today, 05:29 AM
      4 responses
      14 views
      0 likes
      Last Post Aviram Y  
      Started by algospoke, 04-17-2024, 06:40 PM
      3 responses
      28 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by gentlebenthebear, Today, 01:30 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X