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

Error on calling 'OnBarUpdate' method on bar 11

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

    Error on calling 'OnBarUpdate' method on bar 11

    Hello,

    I am getting the following error every time I try to enable an strategy. The strategy compiles just fine with no errors. The problem arises when I try to run strategy analyzer or enable it on a chart.

    The error is:
    Strategy 'XXXXXX': Error on calling 'OnBarUpdate' method on bar 11: Unable to cast object of type 'NinjaTrader.NinjaScript.Indicators.ATR' to type 'System.IConvertible'.
    These are the parts of the code in which the ATR plays a role. I have not been able to spot the problem. Would you please help me?



    #region Class Variables

    private ATR Atr;

    protected override void OnStateChange()
    {
    //Set defaults
    if (State == State.SetDefaults)
    {
    BolPeriod = 9;


    }
    else if (State == State.Configure)
    {

    }
    else if (State == State.DataLoaded)
    {

    //Create strategy indicators

    Atr = ATR(Close, Convert.ToInt32(BolPeriod));
    }

    case 03:
    EnterLongLimit(0, true, Convert.ToInt32(Order01LotSize), Close[0] - (Convert.ToInt32(Atr) * 0.25 * TickSize), "LE01");;
    EnterLongLimit(0, true, Convert.ToInt32(Order02LotSize), Close[0] - (Convert.ToInt32(Atr) * 0.5 * TickSize), "LE02");
    EnterLongLimit(0, true, Convert.ToInt32(Order03LotSize), Close[0] - (Convert.ToInt32(Atr) * 0.75 * TickSize), "LE03");
    break;

    case 02:
    EnterLongLimit(0, true, Convert.ToInt32(Order01LotSize), Close[0] - (Convert.ToInt32(Atr) * 0.25 * TickSize), "LE01");;
    EnterLongLimit(0, true, Convert.ToInt32(Order02LotSize), Close[0] - (Convert.ToInt32(Atr) * 0.5 * TickSize), "LE02");
    break;

    case 01:
    EnterLongLimit(0, true, Convert.ToInt32(Order01LotSize), Close[0] - (Convert.ToInt32(Atr) * 0.25), "LE01");
    break;

    #Properties

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="BolPeriod", Description="Periodo Bollinger", Order=42, GroupName="Order Inputs")]
    private int BolPeriod
    { get; set; }


    #2
    Hello, thanks for your question.

    Your Atr object is of type Series<double>, so it must be indexed to get a value. E.g.

    Code:
    EnterLongLimit(0, true, Convert.ToInt32(Order01LotSize), Close[0] - (Convert.ToInt32(Atr[0]) * 0.25 * TickSize), "LE01"); //this index will give you the ATR value of the most recently closed bar.
    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chris

      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