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

Using Fib Retracement Levels as Parameter Dropdown in Properties of Strategy

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

    Using Fib Retracement Levels as Parameter Dropdown in Properties of Strategy

    I'm using Fib Retracement price levels in my strategy as entry, target and stop levels but want to do a little more with them. I would like to have all fib levels in a user-defined parameter dropdown in strategy properties.

    I found a post on using enums for such a dropdown and and it works with the levels I've defined after looping thru levels, i.e. ThirtyEightLevel, FiftyLevel, etc.

    Apparently enums only work with int types and the fib levels are double values...if I have 21 fib levels (0-20), is there a way to convert the double value into a enum-friendly int type?


    #2
    Hello swjake,

    In order to use an enum for that purpose you would have to make a list of enums and then based on the selected enum set a double varaiable to a specific value in your code. For example:

    double levelValue = 10;
    if(MyCustomEnum == MyEnum.Twenty)
    {
    levelValue = 20;
    }
    if(MyCustomEnum == MyEnum.TwentyPointFive)
    {
    levelValue = 20.5;
    }​

    The only other way to make a custom list of levels would be to implement a property similar to the fibonacci tools property PriceLevels which would require some fairly heaving coding requirements to duplicate how the fibonacci tools inherit from a custom base class.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for the quick reply. Is there a way without using enums? While I could certainly hardcode each price level, I was hoping that as levels are added, deleted or modified, they could be "dynamically" added, deleted or modified.

      If I do a loop thru drawing tools like so:

      Code:
      if(myFib != null)
                                      for(int i = 0; i <  myFib.PriceLevels.Count; i++)
                                      {
                                          Print("Level " + i + "\t=\t " + myFib.PriceLevels[i].Value + "\t=\t " + myFib.PriceLevels[i].GetPrice(myFib.StartAnchor.Price, myFib.EndAnchor.Price-myFib.StartAnchor.Price, true));
                                      }
      ​
      It returns in a numbered list of levels like so:

      0 = 0 Level = Price
      1 = 38.2 Level = Price
      2 = 50.0 Level = Price
      3 = 61.8 Level = Price

      and so on thru all price/fib levels. Isn't there a way to assign those 0, 1, 2, 3, etc integers that would work? I'm still hacking my way thru and learning Ninjascript, so please forgive my persistence. It seems like there's a workaround there somewhere..

      Comment


        #4
        Hello swjake,

        I am not clear on what your overall goal is here. A user input would be configured before you draw any objects so you wouldn't be able to take the levels from that object and assign them to an input. You can use those values in your code but you couldn't assign the double values to a user input.

        Are you asking how to specify which level from the drawing objects default levels that you wanted to use for an orders price? If so you can just cast the enum and supply that as the index assuming that the enum matches the number of levels were defined in the drawing object.

        If we assume that your drawing object has 4 total levels you could make an enum with 4 selections and the cast the enum to an int and use that like the following:

        double value = myFib.PriceLevels[(int) myEnumUserInput].Value;

        If you had a enum with more levels than the drawing object and tried to use it this way it would produce an error if you tried to select a level that was not there.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Sorry if I'm a bit confusing. My strategy doesn't draw a fib retracement, but uses one I draw and move around manually, it finds it by Tag.
          A user input would be configured before you draw any objects so you wouldn't be able to take the levels from that object and assign them to an input.
          Works great, use the levels for conditional entries, moving stops, assigning target levels, etc. Here's a screenshot of the Parameters I configured via enum.




          I was hoping to have all the actual values (38.2, 50, 61.8, etc.) display in the dropdown, since I use a variety of levels as targets and entry levels depending on price action. I have 21 levels. If I pass it to my friend, he has 30+ levels that change often.

          Hope that makes a bit more sense.

          Thanks Jesse!

          Comment


            #6
            Hello swjake,

            That wouldnt be possible because your script will only have access to that object once its past the configuration screen. To populate user inputs you need to do that in State.SetDefaults but you won't be able to access the draw objects collection there.
            JesseNinjaTrader Customer Service

            Comment


              #7
              It wouldn't have access to the default Fib levels? I guess I'm biting off more than I can chew at the moment. Thank you Jesse.

              Comment


                #8
                Hello swjake,

                You cant draw an object from State.SetDefaults so you wouldn't be able to do that to set a user input based on the drawing object that hasn't been drawn yet. As an alternate you could draw the list of levels on the chart if you just wanted to see what was configured but that otherwise wouldn't be able to be used as a selection when configuring the script initially.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thanks for your patience Jesse, I don't want to be a pest. If I've saved all my levels as "default", the Fib Level value of those "default" levels remains constant, is that correct or am I thinking about this wrongly?

                  So in the code snippet above the FibonacciRetracements.PriceLevels.Count would still be retrievable outside of the strategy, right? If there were 20 levels yesterday, and 20 levels today, wouldn't the values (PriceLevels[i].Value in the above snippet) remain the same, i.e. 38.2 remains 38.2 whether the price is 70.32 or 42.37?

                  Can't I access the Value levels saved in the default fib template in some fashion? Couldn't I convert the integers 0 - 20 the above snippet prints into 20 values to choose from?
                  Last edited by swjake; 01-08-2024, 03:09 PM.

                  Comment


                    #10
                    Hello swjake,

                    The default template is not the problem, the problem is that you cant draw an object or access the drawing objects collection from State.SetDefaults which is where you need to get the value to set it to your user inputs. The user inputs are already configured by the time you can draw or access drawing objects from the chart. The drawing object collection specifically can only be accessed in realtime when the strategy has already done its processing so you could only pull the values from the object like the snippet i provided once the script has been running. There's otherwise not any kind of built in way to access template data from a drawing object besides drawing it and then accessing the drawn object.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Thank you for explaining Jesse. I still have much to learn. Have a great day!

                      Comment


                        #12
                        Originally posted by swjake View Post
                        Thank you for the quick reply. Is there a way without using enums? While I could certainly hardcode each price level, I was hoping that as levels are added, deleted or modified, they could be "dynamically" added, deleted or modified.

                        If I do a loop thru drawing tools like so:

                        Code:
                        if(myFib != null)
                        for(int i = 0; i < myFib.PriceLevels.Count; i++)
                        {
                        Print("Level " + i + "\t=\t " + myFib.PriceLevels[i].Value + "\t=\t " + myFib.PriceLevels[i].GetPrice(myFib.StartAnchor.Price, myFib.EndAnchor.Price-myFib.StartAnchor.Price, true));
                        }
                        ​
                        It returns in a numbered list of levels like so:

                        0 = 0 Level = Price
                        1 = 38.2 Level = Price
                        2 = 50.0 Level = Price
                        3 = 61.8 Level = Price

                        and so on thru all price/fib levels. Isn't there a way to assign those 0, 1, 2, 3, etc integers that would work? I'm still hacking my way thru and learning Ninjascript, so please forgive my persistence. It seems like there's a workaround there somewhere..
                        Can I append txt to show on the chart ?

                        I.E:

                        0 Level = Show on the chart "0.00% Append txt #1"
                        38.2 Level = Show on the chart "38.20 Append txt #2"
                        50.0 Level = Show on the chart "50.00 Append txt #3"
                        61.8 Level = Show on the chart "61.80 Append txt #4"

                        Comment


                          #13
                          Hello PrTester,

                          You can use Draw.TextFixed for that purpose. If you wanted multi line text you would make a string that has \n where you want a newline:

                          Code:
                          string myString = "lineOne\nLineTwo\nLineThree";
                          JesseNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by ageeholdings, Today, 07:43 AM
                          0 responses
                          11 views
                          0 likes
                          Last Post ageeholdings  
                          Started by pibrew, Today, 06:37 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post pibrew
                          by pibrew
                           
                          Started by rbeckmann05, Yesterday, 06:48 PM
                          1 response
                          14 views
                          0 likes
                          Last Post bltdavid  
                          Started by llanqui, Today, 03:53 AM
                          0 responses
                          9 views
                          0 likes
                          Last Post llanqui
                          by llanqui
                           
                          Started by burtoninlondon, Today, 12:38 AM
                          0 responses
                          12 views
                          0 likes
                          Last Post burtoninlondon  
                          Working...
                          X