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 ETFVoyageur, Today, 04:00 PM
      0 responses
      5 views
      0 likes
      Last Post ETFVoyageur  
      Started by AaronKTradingForum, Today, 03:44 PM
      1 response
      6 views
      0 likes
      Last Post AaronKTradingForum  
      Started by Felix Reichert, 04-26-2024, 02:12 PM
      11 responses
      76 views
      0 likes
      Last Post Felix Reichert  
      Started by junkone, 04-28-2024, 02:19 PM
      7 responses
      82 views
      1 like
      Last Post junkone
      by junkone
       
      Started by pechtri, 06-22-2023, 02:31 AM
      11 responses
      136 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Working...
      X