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 habeebft, Today, 07:27 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_ChristopherS  
    Started by AveryFlynn, Today, 04:57 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by Max238, Today, 01:28 AM
    4 responses
    38 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by r68cervera, Today, 05:29 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by geddyisodin, Today, 05:20 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X