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

probleme with SMA 5 bars ago

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

    probleme with SMA 5 bars ago

    Hi,

    in an Indicator in 70 Tick, I need SMA, 5 bars ago :

    if ((SMA(50)[5] > SMA(100)[5])
    && (SMA(100)[5] > SMA(200)[5]))
    {
    PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav");
    }
    dont made sound Alert4

    BUT this next works perfectly in 0 Bars ago and ma
    if ((SMA(50)[0] > SMA(100)[0])
    && (SMA(100)[0] > SMA(200)[0]))
    {
    PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav");
    }
    give the Alert4 sound

    Where is the difference ?
    What can I do to use SMA (X) in 5 bars ago

    Thanks in Help

    #2
    Hello,

    If you are not first checking how many bars are loaded before checking a barsago value you will get an error.

    Try adding this above the statement you provided:

    if(CurrentBar < 5) return;

    This prevents the script from running until you have 5 bars loaded, then it can look back 5 bars.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      oups, it is obvious
      i am so sorry

      thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by pibrew, Today, 06:37 AM
      0 responses
      1 view
      0 likes
      Last Post pibrew
      by pibrew
       
      Started by rbeckmann05, Yesterday, 06:48 PM
      1 response
      12 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      11 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      15 views
      0 likes
      Last Post AaronKoRn  
      Working...
      X