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

using HeikenAshiSmoothed in a strategy

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

    using HeikenAshiSmoothed in a strategy

    Guys,

    I'm having trouble using this indicator in a strategy. The log shows the following entry:

    Error on calling the 'OnBarUpdate' method for indicator 'HeikenAshiSmoothed' on bar 1: Object reference not set to an instance of an object.

    My code is simple enough:
    protected override void OnBarUpdate()
    {

    HA_Open1 = HeikenAshiSmoothed(0.7, HAMA.SMA, HAMA.SMMA, 1, 2).HAOpen[1];
    HA_Open0 = HeikenAshiSmoothed(0.7, HAMA.SMA, HAMA.SMMA, 1, 2).HAOpen[0];
    HA_Close1 = HeikenAshiSmoothed(0.7, HAMA.SMA, HAMA.SMMA, 1, 2).HAClose[1];
    HA_Close0 = HeikenAshiSmoothed(0.7, HAMA.SMA, HAMA.SMMA, 1, 2).HAClose[0];



    if (HA_Open1 > HA_Close1 && HA_Open0 > HA_Close0)
    {
    ExitLong("ExitLongHeiken", "LongOnHeikenReverse");
    EnterShortLimit(DefaultQuantity, GetCurrentAsk(), "ShortOnHeikinReverse");

    }

    // Condition set 2
    if (HA_Open1 > HA_Close1 && HA_Open0 > HA_Close0)
    {
    ExitShort("ExitShortHeiken", "ShortOnHeikenReverse");
    EnterLongLimit(DefaultQuantity, GetCurrentBid(), "LongOnHeikenReverse");
    }
    }


    do I need more bars before calculating?



    #2
    Use try-catch blocks to isolate which line is causing the problem. Ultimately, it looks like it is erroneous programming in the indicator though.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      catch blocks..

      Originally posted by NinjaTrader_Josh View Post
      Use try-catch blocks to isolate which line is causing the problem. Ultimately, it looks like it is erroneous programming in the indicator though.

      Ok, Josh, good thought. I will and report back if I can solve it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by mlprice12, 12-21-2021, 04:55 PM
      3 responses
      291 views
      0 likes
      Last Post paypachaysa  
      Started by lorem, 04-25-2024, 09:18 AM
      20 responses
      85 views
      0 likes
      Last Post lorem
      by lorem
       
      Started by xepher101, 05-10-2024, 12:19 PM
      4 responses
      52 views
      0 likes
      Last Post xepher101  
      Started by DawnTreader, 05-08-2024, 05:58 PM
      22 responses
      82 views
      0 likes
      Last Post DawnTreader  
      Started by Mathias79, Today, 03:44 PM
      0 responses
      18 views
      0 likes
      Last Post Mathias79  
      Working...
      X