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

Extending the FibonacciTools

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

    Extending the FibonacciTools

    Hello.

    I'm trying to build an indicator which uses the two or more of the Fibonacci drawing tools that come with NT8. What I want to do is draw a grid consisting of BOTH the Retracements (horizontal lines) and the TimeExtensions (vertical lines).

    It was simple enough to deal with the case of calling the Fibonacci tool from an indicator. I simply added one more constructor to the Draw partial class, which calls two methods in succession:

    Code:
            public static void FibonakkiBothTimeAndPrice(NinjaScriptBase owner, string tag, bool isAutoScale,
                int startBarsAgo, double startY, int endBarsAgo, double endY)
            {
                FibonakkiTimeExtensions(owner, tag+"Verticals", isAutoScale,
                 startBarsAgo, startY, endBarsAgo, endY);
                FibonakkiRetracements(owner, tag+"Horizontals", isAutoScale,
                 startBarsAgo, startY, endBarsAgo, endY);
                //return FibonakkiCore<FibonakkiTimeExtensions>(owner, isAutoScale, tag, startBarsAgo, Core.Globals.MinDate, startY, endBarsAgo, Core.Globals.MinDate, endY, false, null);
            }
    But I'm stuck when it comes to invoking such a grid as a chart drawing, i.e. holding the mouse and moving it to set the anchors. In other words, I want to use the same anchors for both horizontal Retracements and vertical TimeExtensions in one go.

    I've looked at the code and each of the two classes has its own OnRender to deal with the anchors. Can someone point me in the right direction? Instead of tampering with the code and copy-pasting between the two classes, I'm hoping there's a straightforward way as simple as the route I took with .Draw(...) above.

    Thanks in advance.

    One more thing: If, in the indicator I'm building, I want to include the inputs (properties) of the drawing tool (i.e. to set Fibo levels and colours, etc) so that they can be set from the indicator and sent to the drawing tool when it's called, is there a way of "inheriting" the properties of the Fibo tool instead of copy-pasting the same properties?

    #2
    Sorry I opened the thread in the NT7 forum. Please move it to NT8. Thanks.

    Comment


      #3
      Hello zambi,

      Thank you for the post.

      I want to use the same anchors for both horizontal Retracements and vertical TimeExtensions in one go.
      In this situation, I dont believe there would be a straightforward way to approach this. If you also want to include manual control while using an indicator that does make it more difficult.

      Drawing objects drawn from an indicator are locked by default (unless you unlock them) as they are generally meant to be managed by the indicator and not manually. You can unlock them and modify them but you run into the limitation of clicking on only one tool at once.

      You would very likely have to create a new tool that includes the logic for both the target Fibonacci tools and only one set of anchors. Drawing the tools from NinjaScript as you pointed out allows you to change the Draw method which then affects both tools. Because each individual tool expects specific manual input and only one tool can have input at once, this would not likely be directly possible to control both at once manually.

      You may be able to create a wrapper drawing tool that inherits from the FibonacciLevels similar to how FibonacciRetracements does already. In its code, you could mix the FibonacciRetracements and FibonacciTimeExtensions code where needed. This would allow you to render both sets of logic at once how you would like from the single anchor system in that tool. Because FibonacciTimeExtensions already inherits from FibonacciRetracements, it may need to be modified to fit in the new tool or to be mixed in with the existing FibonacciRetracements code. This would be a slightly complicated item as both existing sets of code are pretty large but there would also be a lot of duplicate overrides/properties so it would be reduced as well.

      I had previously created a video showing duplicating an existing tool by inheritance, this would likely apply to this situation as well if you are interested in creating a new mixed tool. https://ninjatrader.com/support/foru...95&postcount=6

      Outside of creating a new tool, you would likely need to modify the way the indicator handles mouse input to get around having a single tool selected at once but I really wouldn't suggest going that route. Using your existing Draw method, you could handle mouse input to the indicator and then pass that information to the Draw. method. You can find some examples of mouse handling on the forum here but that can be messy when you use other items that also handle mouse events on the same chart as they can end up fighting for control.


      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Accessing the inputs of drawing tool from indicator

        Hello.

        This indicator calls the FibonacciRetracements drawing tool, which I have as an input parameter for the indicator. I was hoping that within the indicator, I can adjust the settings of the drawing tool, like extending lines and maybe the price levels.

        Why am I not able to set the properties of the tool from the indicators input panel? Any guidance appreciated.

        Code:
        namespace NinjaTrader.NinjaScript.Indicators
        {
        	public class MyCallAndSetFibRet : Indicator
        	{
        		protected override void OnStateChange()
        		{
        			if (State == State.SetDefaults)
        			{
        				Description									= @"Enter the description for your new custom Indicator here.";
        				Name										= "MyCallAndSetFibRet";
        				Calculate									= Calculate.OnBarClose;
        				IsOverlay									= true;
        				DisplayInDataBox							= true;
        				DrawOnPricePanel							= true;
        				DrawHorizontalGridLines						= true;
        				DrawVerticalGridLines						= true;
        				PaintPriceMarkers							= true;
        				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
        				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
        				//See Help Guide for additional information.
        				IsSuspendedWhileInactive					= true;
        				Distance					= 16;
        				MyFibRet = new FibonacciRetracements();
        			}
        			else if (State == State.Configure)
        			{
        			}
        		}
        
        		protected override void OnBarUpdate()
        		{
        			//Add your custom indicator logic here.
        			double high = MAX(High, Distance)[0];
        			double low = MIN(Low, Distance)[0];
        			if (CurrentBar == Count - 2)
        			{
        				MyFibRet = Draw.FibonacciRetracements(this, "fib", false, Distance, high, -Distance, low);
        			}
        		}
        
        		#region Properties
        		[NinjaScriptProperty]
        		[Range(16, int.MaxValue)]
        		[Display(Name="Distance", Description="Distance in bars ago", Order=1, GroupName="Parameters")]
        		public int Distance
        		{ get; set; }
        
        		[NinjaScriptProperty]
        		public FibonacciRetracements MyFibRet
        		{ get; set; }
        
        		#endregion
        
        	}
        }

        Comment


          #5
          Hello zambi,

          In this case, the tool is not set up to be a property like you have made it. You would need to make a type converter that displays the drawing object as a property with multiple fields for that to work as you are expecting. Because this would be complex It would likely be easiest to make your own properties for what you want to control, and then when you draw the object, set those properties from what the input has.

          After creating a property, you can set them like it is shown in this example: https://ninjatrader.com/support/help...htsub=MyFibRet

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thanks Jesse.

            How about changing the format of how the pricelevel and price value are displayed? How can I do that.

            I've been trying to access the first PriceLevel at index 0, yet PriceLevel[0].Name = "some random string" doesn't seem to work.

            I've also tried the GannAngles container. Trying GannAngles[0].Name = "random string" produces a compiler error that the Name property is read-only (it isn't with PriceLevels, though).

            Anyway, what I want to do is use a different format than the default 61.80 % (xxxxx). Is there a way to do it without modifying the built-in PriceLevels definition?

            Comment


              #7
              Hello zambi,

              Thank you for the reply.

              To have the price levels displayed differently, you would need to create a custom TypeConverter for that purpose. This would not be something you can set from NinajScript using a property.

              You can see how the existing PriceLevels are defined and what is required for that type of property by reviewing the GannFan drawing tool.

              The property grid you see in the user interface is only capable of displaying simple properties by its self, a TypeConverter or PropertyEditor could be used to create more complex UI controls.


              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              4 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              19 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Working...
              X