Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Displaced SMA in strategy

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

    Displaced SMA in strategy

    Understand displacement is covered in the manual, https://ninjatrader.com/support/help...splacement.htm

    but is there an example of how that int is called in a strategy? What I'm trying to do below isn't working. Thanks

    private SMA sma;

    Period = 14;
    Displacement = 2;


    Code:
    			else if (State == State.Configure)
    			{
    				sma = SMA(Period).Displacement;
    			}
    			
    			else if (State == State.DataLoaded)
    			{
    				sma = SMA(Period).Displacement;
    				AddChartIndicator(sma);

    #2
    Hello,

    Thank you for the post.

    Yes, the Displacement property would need to be set by the indicator its self but this would not be used when being hosted by a Strategy.

    For a strategy to displace an indicators data, it would need to replot that data using the BarsAgo concept for the displacement needed. Otherwise, the indicator would need to plot a displaced value to begin with to avoid using the UI option for displacement completely.

    For example, instead of adding the SMA from the strategy, you could replot its displaced value using the strategy like the following:

    Code:
    protected override void OnStateChange()
    {
    	if (State == State.SetDefaults)
    	{
    		AddPlot(Brushes.Red, "SMA");
    	}
    }
    
    protected override void OnBarUpdate()
    {
    	if(CurrentBar < 2) return;
    	Value[0] = SMA(14)[2]; //2 for displacement
    }
    This would affect the actual plot value here, so if your strategy references this plot you would need to remember the values are actually displaced instead of just visually displaced.



    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    93 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    138 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    123 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    73 views
    0 likes
    Last Post PaulMohn  
    Working...
    X