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 zstheorist, Today, 07:52 PM
        0 responses
        3 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        149 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        5 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
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        5 views
        0 likes
        Last Post tkaboris  
        Working...
        X