Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate SMA on Momentum: Periodtype problem

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

    Calculate SMA on Momentum: Periodtype problem

    Hi, i want to have an indicator that shows if the weekly momentum is above or below his moving average. The periodtype should always be weekly, no matter which period is selected on the chart. The idea is the following but it only works on a weekly chart. Can you help me please?

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Linie"));
    Add(PeriodType.Week, 1);
    Overlay = false;

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
    return;

    double mom1 = Momentum(Closes[1],28)[0];
    double smamom = SMA(Momentum(Closes[1],28),28)[0];
    if (mom1 > smamom)
    Linie.Set(1);
    else if (mom1 < smamom)
    Linie.Set(-1);
    else Linie.Set(0);

    #2
    Hello,

    Thank you for your post.

    The reason it does not plot on intra-day data is it is only looking 20 bars back (BarsRequired by default is only 20 bars).

    Your indicators calculate on a period of 28 for the weekly chart. 28 weeks means 196 daily bars, and 282,240 minute bars.

    So you would need to load 282,240+ bars on your minute chart to see these values.

    Please let me know if I may be of further assistance.

    Comment


      #3
      Thank you!

      Comment


        #4
        Do you know how can I run this indicator with CalculateOnBarClose = false for the weekly period type. For example on a Dayly Chart?
        Thank you again for your help!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        43 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        26 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        163 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        158 views
        2 likes
        Last Post CaptainJack  
        Working...
        X