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 traderqz, Yesterday, 09:06 AM
          3 responses
          21 views
          0 likes
          Last Post NinjaTrader_ThomasC  
          Started by f.saeidi, Today, 10:19 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by kujista, Today, 06:23 AM
          5 responses
          17 views
          0 likes
          Last Post kujista
          by kujista
           
          Started by traderqz, Today, 12:06 AM
          3 responses
          6 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by RideMe, 04-07-2024, 04:54 PM
          5 responses
          29 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X