Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Having an issue with using Value[0] in ATM Strategy

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

    Having an issue with using Value[0] in ATM Strategy

    I'm trying to use this line of code "Value[0] = SMA(BarsArray[1], 10)[0];"

    For some reason, the strategy does not like this line of code. It won't enable the ATM Strategy. If I comment it out, it enables. What's the problem? Here if the first few lines of code:

    protected override void OnBarUpdate()
    {
    if(CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < BarsRequiredToTrade)
    return;

    Value[0] = SMA(BarsArray[1], 10)[0];

    double BarMADiff = Math.Abs(TSI(BarsArray[1],10, 34)[0] - EMA(TSI(BarsArray[1],10, 34), 4)[0]);

    // HELP DOCUMENTATION REFERENCE: Please see the Help Guide section "Using ATM Strategies" under NinjaScript--> Educational Resources--> http://ninjatrader.com/support/helpG...strategies.htm
    // Make sure this strategy does not execute against historical data
    if(State == State.Historical)
    return;

    if (PositionAccount.MarketPosition == MarketPosition.Long || PositionAccount.MarketPosition == MarketPosition.Short)
    {
    CloseStrategy(atm_id);
    }

    #2
    I think I know what my problem is. That line of code Value[0] = SMA(BarsArray[1], 10)[0]; is part of an MA indicator. I'm not referencing it in the strategy.

    Comment


      #3
      No. That's not the problem.

      Comment


        #4
        Hi James, thanks for posting.

        First, check the Log tab of the Control Center for any errors coming from the script. If you are getting a BarsAgo error, there are not enough bars on the chart to process the command. This simple test script works for me:

        State.Configure:
        AddDataSeries(BarsPeriodType.Minute, 5);

        OnBarUpdate:
        if(CurrentBars[0] < 10 || CurrentBars[1] < 10) return;

        Print(SMA(BarsArray[1], 10)[0]);

        Kind regards,
        -ChrisL

        Comment


          #5
          I'm using IsRising and IsFalling in my ATM Strat. Instead of using Value[0], I just passed in the SMA in to the methods. IsRising(SMA(BarsArray[1], 10))... It's working.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          93 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          138 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          123 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          73 views
          0 likes
          Last Post PaulMohn  
          Working...
          X