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 NullPointStrategies, Today, 05:17 AM
    0 responses
    44 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X