Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mogalef bands

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

    Mogalef bands

    Hi all,
    There is a powerful indicator called MOGALEF BANDS created by trader Eric Lefort.
    https://www.mogalef-trading.com/mogalef-bands
    This indicator is based on linear regression and predicts future volatility by drawing the bands.
    I think it would be interesting to translate it for the Ninja community.
    Unfortunately, I don't have the skills to do it myself.
    Maybe someone could do it.
    This indicator is open source
    Sincerely
    Georges

    Here is its code in Prorealtime:

    // Calculation Mogalef Bands
    // variables std1=7 linear1=3

    CP=(open+high+low+2*close)/5
    F=LinearRegression[linear1](CP)
    E=std[std1](F)

    if barindex<8 then
    Median = undefined
    BandHigh = undefined
    BandLow = undefined

    Else
    BandHigh = F+(E*2)
    BandLow = F-(E*2)
    BandMedHigh = F+E
    BandMedLow = F-E

    if F<BandHigh[1]and F>BandLow[1]then
    E=E[1]
    BandHigh=BandHigh[1]
    BandLow=BandLow[1]
    BandMedHigh=BandMedHigh[1]
    BandMedLow=BandMedLow[1]

    endif

    Median =(BandHigh+BandLow)/2
    Endif

    return BandHigh as"Mogalef Band High", Median as "Mogalef Median Band », BandLow as "Mogalef Band Low", BandMedHigh as"Mogalef Band Med High », BandMedLow as "Mogalef Band Med Low"
    Attached Files
    Last edited by georges61; 12-31-2020, 09:33 AM.

    #2
    Hello georges61,

    Thanks for your post.

    We will leave this thread open for any community member that would like to create the indicator. I recommend once created/tested that the indicator be added to the NT user apps so it is available to all from the convenience of the site: https://ninjatraderecosystem.com/use...r-8-indicators

    An alternative here would be to hire a 3rd party programmer and if this is of interest we can provide a link to 3rd party programmers through the NinjaTrader Ecosystem,

    Comment


      #3
      Code:
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion
      
      namespace NinjaTrader.NinjaScript.Indicators.prorealtime
          {
              public class MogalefBands : Indicator
              {
                  private Series<double> CP;
                  private Series<double> F;
                  private Series<double> E;
                  private Series<double> BandHigh;
                  private Series<double> BandLow;
                  private Series<double> BandMedHigh;
                  private Series<double> BandMedLow;
                  private Series<double> Median;
      
                  [Range(1, int.MaxValue), NinjaScriptProperty]
                  [Display(Name = "Std Period", Description = "Standard Deviation Period", Order = 1, GroupName = "Parameters")]
                  public int StdPeriod { get; set; }
      
                  [Range(1, int.MaxValue), NinjaScriptProperty]
                  [Display(Name = "Linear Regression Period", Description = "Linear Regression Period", Order = 2, GroupName = "Parameters")]
                  public int LinearRegressionPeriod { get; set; }
      
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description = @"Custom Indicator for Mogalef Bands";
                          Name = "MogalefBands";
                          Calculate = Calculate.OnEachTick;
                          IsOverlay = true;
                          AddPlot(Brushes.Red, "Mogalef Band High");
                          AddPlot(Brushes.Orange, "Mogalef Median Band");
                          AddPlot(Brushes.Green, "Mogalef Band Low");
                          AddPlot(Brushes.Blue, "Mogalef Band Med High");
                          AddPlot(Brushes.Purple, "Mogalef Band Med Low");
                      }
                      else if (State == State.DataLoaded)
                      {
                          CP = new Series<double>(this);
                          F = new Series<double>(this);
                          E = new Series<double>(this);
                          BandHigh = new Series<double>(this);
                          BandLow = new Series<double>(this);
                          BandMedHigh = new Series<double>(this);
                          BandMedLow = new Series<double>(this);
                          Median = new Series<double>(this);
                      }
                  }
      
                  protected override void OnBarUpdate()
                  {
                      CP[0] = (Open[0] + High[0] + Low[0] + 2 * Close[0]) / 5;
                      F[0] = LinReg(CP, LinearRegressionPeriod)[0];
                      E[0] = StdDev(F, StdPeriod)[0];
      
                      if (CurrentBar < 8)
                      {
                          BandHigh[0] = double.NaN;
                          BandLow[0] = double.NaN;
                          BandMedHigh[0] = double.NaN;
                          BandMedLow[0] = double.NaN;
                          Median[0] = double.NaN;
                      }
                      else
                      {
                          double prevBandHigh = BandHigh[1];
                          double prevBandLow = BandLow[1];
                          double prevBandMedHigh = BandMedHigh[1];
                          double prevBandMedLow = BandMedLow[1];
      
                          BandHigh[0] = F[0] + (E[0] * 2);
                          BandLow[0] = F[0] - (E[0] * 2);
                          BandMedHigh[0] = F[0] + E[0];
                          BandMedLow[0] = F[0] - E[0];
      
                          if (F[0] < prevBandHigh && F[0] > prevBandLow)
                          {
                              E[0] = E[1];
                              BandHigh[0] = prevBandHigh;
                              BandLow[0] = prevBandLow;
                              BandMedHigh[0] = prevBandMedHigh;
                              BandMedLow[0] = prevBandMedLow;
                          }
      
                          Median[0] = (BandHigh[0] + BandLow[0]) / 2;
      
                          Values[0][0] = BandHigh[0];
                          Values[1][0] = Median[0];
                          Values[2][0] = BandLow[0];
                          Values[3][0] = BandMedHigh[0];
                          Values[4][0] = BandMedLow[0];
                      }
                  }
      
                  #region Properties
                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> MogalefBandHigh
                  {
                      get { return Values[0]; }
                  }
      
                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> MogalefMedianBand
                  {
                      get { return Values[1]; }
                  }
      
                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> MogalefBandLow
                  {
                      get { return Values[2]; }
                  }
      
                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> MogalefBandMedHigh
                  {
                      get { return Values[3]; }
                  }
      
                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> MogalefBandMedLow
                  {
                      get { return Values[4]; }
                  }
                  #endregion
              }
          }
      
      ​

      Comment


        #4
        this is a ChatGPT code

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        629 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        564 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X