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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X