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 f.saeidi, Today, 12:14 PM
      2 responses
      5 views
      0 likes
      Last Post f.saeidi  
      Started by TradeForge, 04-19-2024, 02:09 AM
      2 responses
      28 views
      0 likes
      Last Post TradeForge  
      Started by aprilfool, 12-03-2022, 03:01 PM
      3 responses
      327 views
      0 likes
      Last Post NinjaTrader_Adrian  
      Started by giulyko00, Today, 12:03 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by AnnBarnes, Today, 12:17 PM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Working...
      X