51星变 发表于 2021-1-8 22:50:40

LaguerreFilter






#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red
#property strict

extern ENUM_TIMEFRAMES    TimeFrame= PERIOD_CURRENT;   // Time frame
extern double             gamma         = 0.7;         // Gamma
extern ENUM_APPLIED_PRICE Price_Type      =   4;         // Price
extern bool               alertsOn      = false;       // Turn alerts on?
extern bool               alertsOnCurrent = false;       // Alerts on currnt (still opened) bar?
extern bool               alertsMessage   = true;      // Alerts should show pop-up message?
extern bool               alertsSound   = false;       // Alerts should play alert sound?
extern bool               alertsPushNotif = false;       // Alerts should send push notification?
extern bool               alertsEmail   = false;       // Alerts should send email?
extern bool               Interpolate   = true;      // Interpolate in multi time frame mode?


double Filter[];
double Fir[];
double price[];
double L0[];
double L1[];
double L2[];
double L3[],trend[];
string IndicatorFileName;
bool   returnBars;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorBuffers(8);
        SetIndexLabel(0, "LaguerreFilter");
        SetIndexLabel(1, "FIR");
        SetIndexBuffer(0, Filter);
        SetIndexBuffer(1, Fir);
        SetIndexBuffer(2, price);
   SetIndexBuffer(3, L0);
   SetIndexBuffer(4, L1);
   SetIndexBuffer(5, L2);
   SetIndexBuffer(6, L3);
   SetIndexBuffer(7, trend);
      IndicatorFileName = WindowExpertName();
      returnBars      = TimeFrame==-99;
      TimeFrame = MathMax(TimeFrame,_Period);
      IndicatorShortName("LaguerreFilter(" + DoubleToStr(gamma, 2) + ") "+(string)TimeFrame);
   return(0);
}
int deinit() { return(0); }
int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-2);
         if (returnBars) { Filter = limit+1; return(0); }
         if (TimeFrame != _Period)
         {
            limit = (int)MathMax(limit,MathMin(Bars-1,iCustom(NULL,TimeFrame,IndicatorFileName,-99,0,0)*TimeFrame/Period()));
            for (int i=limit; i>= 0; i--)
            {
               int y = iBarShift(NULL,TimeFrame,Time);       
               Filter = iCustom(NULL,TimeFrame,IndicatorFileName,PERIOD_CURRENT,gamma,Price_Type,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsPushNotif,alertsEmail,0,y);
               Fir    = iCustom(NULL,TimeFrame,IndicatorFileName,PERIOD_CURRENT,gamma,Price_Type,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsPushNotif,alertsEmail,1,y);
                  if (!Interpolate || (i>0 && y==iBarShift(NULL,TimeFrame,Time))) continue;

                  //
                  //
                  //
                  //
                  //

                  int n,j; datetime time = iTime(NULL,TimeFrame,y);
                     for(n = 1; (i+n)<Bars && Time >= time; n++) continue;       
                     for(j = 1; j<n && (i+n)<Bars && (i+j)<Bars; j++)
                     {
                        Filter = Filter + (Filter-Filter)*j/n;
                        Fir    = Fir    + (Fir   -Fir   )*j/n;
                     }
            }
            return(0);         
         }

   //
   //
   //
   //
   //

        for (int i=limit; i>=0; i--)
        {
                price=iMA(NULL,0,1,0,0,Price_Type,i);
                if (i>=Bars-3)
                {
                   L0   = price;
                   L1   = price;
                   L2   = price;
                   L3   = price;
                   L0   = price;
                   Filter = price;
                   Fir    = price;
                   trend= 0;
                   continue;
                }
      L0 = (1.0 - gamma)*price + gamma*L0;
                L1 = -gamma*L0 + L0 + gamma*L1;
                L2 = -gamma*L1 + L1 + gamma*L2;
                L3 = -gamma*L2 + L2 + gamma*L3;
               
      Filter = (L0 + 2 * L1 + 2 * L2 + L3) / 6.0;
      Fir   = (price+2.0*price+2.0*price+price) / 6.0;
      trend = trend;
         if (Filter<Fir) trend= 1;
         if (Filter>Fir) trend=-1;
        }
       
        //
        //
        //
        //
        //
   if (alertsOn && Bars>2)
   {
   int whichBar = 1; if (alertsOnCurrent) whichBar = 0;
      static string   mess1 = "";
      static datetime time1 = 0;
            if (trend != trend)
            {
               if (trend ==1)doAlert(mess1,time1,whichBar,"laguerre filter fir trend changed to up");
               if (trend == -1)doAlert(mess1,time1,whichBar,"laguerre filter fir trend changed to down");
            }               
   }      
   return(0);
}   

//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tf==iTfTable) return(sTfTable);
                              return("");
}

//
//
//
//
//

void doAlert(string& previousAlert, datetime& previousTime, int forBar, string doWhat)
{
   string message;

   if (previousAlert != doWhat || previousTime != Time) {
       previousAlert= doWhat;
       previousTime   = Time;

       //
       //
       //
       //
       //

       message =timeFrameToString(_Period)+" - "+Symbol()+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" "+doWhat;
          if (alertsMessage)   Alert(message);
          if (alertsEmail)   SendMail(Symbol()+" LaguerrFilter fir",message);
          if (alertsPushNotif) SendNotification(message);
          if (alertsSound)   PlaySound("alert2.wav");
   }
}




让我你 发表于 2021-1-9 11:02:26

{:1_186:}

流金岁月 发表于 2021-1-10 18:17:24

{:1_186:}

lztky168 发表于 2021-1-12 12:44:44

{:1_186:}

想你哈师大 发表于 2021-1-16 12:14:10

支持下

鸳鸯 发表于 2021-1-16 13:26:02

支持下

明程序化 发表于 2021-1-18 17:11:00

谢谢

清水河边 发表于 2021-1-24 14:16:44

支持下

qaejitbfj 发表于 2021-1-28 19:18:48

顶下

大河马 发表于 2021-2-5 10:21:28

顶下
页: [1] 2 3 4 5 6
查看完整版本: LaguerreFilter