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 NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          62 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          134 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X