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

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.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DanielTynera, Today, 01:14 AM
    0 responses
    2 views
    0 likes
    Last Post DanielTynera  
    Started by yertle, 04-18-2024, 08:38 AM
    9 responses
    41 views
    0 likes
    Last Post yertle
    by yertle
     
    Started by techgetgame, Yesterday, 11:42 PM
    0 responses
    12 views
    0 likes
    Last Post techgetgame  
    Started by sephichapdson, Yesterday, 11:36 PM
    0 responses
    2 views
    0 likes
    Last Post sephichapdson  
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,615 views
    0 likes
    Last Post aligator  
    Working...
    X