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

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
        Chris L.NinjaTrader Customer Service

        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 GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,221 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          7 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          438 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          9 views
          0 likes
          Last Post FAQtrader  
          Working...
          X