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 kempotrader, Today, 08:56 AM
      0 responses
      6 views
      0 likes
      Last Post kempotrader  
      Started by kempotrader, Today, 08:54 AM
      0 responses
      4 views
      0 likes
      Last Post kempotrader  
      Started by mmenigma, Today, 08:54 AM
      0 responses
      2 views
      0 likes
      Last Post mmenigma  
      Started by halgo_boulder, Today, 08:44 AM
      0 responses
      1 view
      0 likes
      Last Post halgo_boulder  
      Started by drewski1980, Today, 08:24 AM
      0 responses
      4 views
      0 likes
      Last Post drewski1980  
      Working...
      X