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 Belfortbucks, Today, 09:29 PM
          0 responses
          6 views
          0 likes
          Last Post Belfortbucks  
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          151 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Working...
          X