Announcement

Collapse
No announcement yet.

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.

    Comment


      #3
      oups, it is obvious
      i am so sorry

      thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      566 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X