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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    56 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    133 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X