Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 SMA to SMA closeness - price and slope

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

    NT8 SMA to SMA closeness - price and slope

    Hi - I am wanting to find the simplest way to determine these conditions:

    1) the amount of "closeness" in price at a particular point in time that two SMAs --- for example when the SMA prices are equal, we would consider that to be a nearness of 0; then, as they diverse from each other the nearness would be the difference between the prices.
    2) then, there is the rate of divergence --- this would be the change of nearness being experienced by the chart for these two MAs

    So, what I want to do is measure the both nearness and the rate that it is decreasing / increasing at any moment on the chart.

    Thanks you for any suggestions on how to script this in NT8.

    #2
    Hi seeseea, thanks for your question.

    Unfortunately, the support team can't create custom code. If you have a specific formula for the values you need I can try to make an example. You can access SMA values in a script like so, this gets a difference of two SMAs:

    Code:
    public class SMADifference : Indicator
        {
            private SMA _SMA0;
            private SMA _SMA1;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    //...
                }
                else if (State == State.Configure)
                {
                    AddPlot(Brushes.Red, "MyPlot");
                }
                else if (State == State.DataLoaded)
                {
                    _SMA0 = SMA(20);
                    _SMA1 = SMA(40);
                }
            }
    
            protected override void OnBarUpdate()
            {
                Value[0] = _SMA0[0] - _SMA1[0];
            }
        }
    The rate could be something like the current Value[0] - Value[1]. Getting comfortable with accessing the needed indicator values would be the best starting point to get maximum flexibility out of NinjaScript.

    Please let me know if I can assist any further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    80 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X