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

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 Tim-c, Today, 02:10 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Taddypole, Today, 02:47 PM
        0 responses
        2 views
        0 likes
        Last Post Taddypole  
        Started by chbruno, 04-24-2024, 04:10 PM
        4 responses
        50 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        10 responses
        399 views
        1 like
        Last Post beobast
        by beobast
         
        Started by lorem, Yesterday, 09:18 AM
        5 responses
        25 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X