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

Adjusting Scale to Accommodate Drawing

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

    Adjusting Scale to Accommodate Drawing

    I've got a risk reward tool that I'm drawing programatically. I need to draw this object, and if it is outside the bounds of the visible chart, I want the scale to adjust to accommodate it.

    However I don't want to use the Autoscale property of the drawing. The drawing's IsLocked property is set to false as I want to be able to re-position the object. The problem with Autoscale is that the chart re-scales when the object is being moved - essentially both the chart and the drawing are moving at the same time, which makes it impossible to place the object accurately.

    So I just want to adjust the scale, without autoscaling.

    I tried this but I must be missing something as it did nothing.

    MaxValue = Math.Max(MaxValue, drawing.Anchors.Max( x=> x.Price));
    MinValue = Math.Min(MinValue, drawing.Anchors.Min( x=> x.Price));

    Thank you

    Kevin.

    #2
    Hello reach4thelasers,

    Thanks for writing in.

    In order to set the MinValue and the MaxValue of a chart within code, you must have an override for OnCalculateMinMax().

    If you need to force a screen update when adjusting the scale, you can create a drawing object and remove it on the next call.

    I will provide a link to the section of the help guide on OnCalculateMinMax().


    This override will allow you to adjust the scale of the chart. You do not necessarily have to change the MinValue and the MaxValue inside of OnCalculateMinMax() but the override must exist in your code for it to work.

    For example, you can adjust the scale in OnRender() and follow the scaling with a call to add and remove a drawing object. When you hit F5 to refresh the indicator, the scale will adjust how you have specified. This is not generally recommended as it adds a lot of calculation.

    The ForceRefresh() section of the help guide covers the circumstances in which OnRender() will be called:


    Please let me know if we may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hey Jim,

      cheers for the response. I implemented the OnCalculateMinMax method, and It had the desired effect of adjusting the scale to accommodate my object. However, when I move the object the scale recalculates while the object is being moved; giving the same effect as the shape's Autoscale feature. Its just impossible to place an object accurately when both are moving simultaneously.

      Any ideas on how to get around this? Like I want objects to be visible, but not rescale mid-flight.

      Thank you

      Kevin
      Last edited by reach4thelasers; 03-23-2017, 10:00 AM.

      Comment


        #4
        Hello reach4thelasers,

        Thanks for getting back to me.

        I believe you can accomplish the behavior you are looking for by creating a duplicate drawing object to the Risk Reward drawing object and changing the OnCalculateMinMax() override to only update when the drawing object is being placed for the first time.

        You would still have Autoscale enabled, but you would be modifying the Risk Reward drawing tool so its Autoscale behavior does not occur when moving the draw object.

        Please consider the following as an example:

        Code:
        public override void OnCalculateMinMax()
        {
        	// It is important to set MinValue and MaxValue to the min/max Y values your drawing tool uses if you want it to support auto scale
        	MinValue = double.MaxValue;
        	MaxValue = double.MinValue;
        
        	if (!IsVisible)
        		return;
        	
        	[B]if (DrawingState == DrawingState.Moving)
        		return;[/B]
        
        	// return min/max values only if something has been actually drawn
        	if (Anchors.Any(a => !a.IsEditing))
        		foreach (ChartAnchor anchor in Anchors)
        		{
        			MinValue = Math.Min(anchor.Price, MinValue);
        			MaxValue = Math.Max(anchor.Price, MaxValue);
        		}
        }
        The above modification to the RiskReward drawing tool will prevent the drawing tool from change the scale of the chart when moving.

        Further information on DrawingStates can be found here: https://ninjatrader.com/support/help...awingstate.htm

        Please let me know if I may be of further help.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by funk10101, Yesterday, 09:43 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        5 responses
        551 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by rtwave, 04-12-2024, 09:30 AM
        5 responses
        37 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by funk10101, Today, 12:02 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by GLFX005, Today, 03:23 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X