Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get fibonacci levels - Exception occurred while binding a dynamic operation

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

    Get fibonacci levels - Exception occurred while binding a dynamic operation

    Hello,

    I'm trying to get the fibo retracements levels given a tag name. The script captures the object but when tries to read the levels appears the following error: "Error on calling 'OnBarUpdate' method on bar 4105: An unexpected exception occurred while binding a dynamic operation."

    May I have to save the dynamic object before accessing the fibo levels?

    The code:

    -------

    foreach (dynamic obj in DrawObjects.ToList())

    {

    if(obj.Tag.ToString().Equals("fibonacci_test"))

    {

    // Access the object by assuming that it is the Type we expect

    Print(String.Format("FINONACCI {0} detected!", obj.Tag));

    foreach (PriceLevel p in obj.PriceLevels)

    {

    Print(p.Value);

    Print(p.GetPrice(obj.StartAnchor.Price, obj.EndAnchor.Price - obj.StartAnchor.Price, false));

    }

    }

    }

    -------

    Thanks




    #2
    Hello egurenk,

    Below is a link to a forum post with some sample code of getting price levels from a fibonacci.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello.

      I've tried with the example but the case it's different. I'm trying to get the levels from a fibo already created by other indicator, so i can get the tag name (with the code posted before) and i need to access to the fibo levels.

      I think that the problem appears accesing to the fibo probably. How can I cast the dynamic obj to FibonacciExtension? I don't know if it's the right way.

      Thanks

      Comment


        #4
        Hello egurenk,

        Below is a link to the help guide.
        https://ninjatrader.com/support/help...assemblies.htm

        From the example in the help guide I've changed the type of FibonacciRetracements to FibonacciExtensions.

        Code:
        foreach (dynamic dt in DrawObjects.ToList())
        {
        if(dt.ToString().Equals("NinjaTrader.NinjaScript.D rawingTools.FibonacciExtensions"))
        {
        Type type = dt.PriceLevels.GetType().GetGenericArguments()[0];
        Assembly assembly = type.Assembly;
        var pl = assembly.CreateInstance(type.FullName, false, BindingFlags.CreateInstance, null, new object[] { 55.5, Brushes.Red, 2 }, new System.Globalization.CultureInfo("en-US"), new object[] {});
        dt.PriceLevels.GetType().GetMethod("Add").Invoke(d t.PriceLevels, new object[] { pl } );
        this.ForceRefresh();
        }
        }
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        118 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        62 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        40 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        44 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        82 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X