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 burtoninlondon, Today, 12:38 AM
      0 responses
      9 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      14 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      13 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,983 views
      3 likes
      Last Post jhudas88  
      Working...
      X