Author: Dmitry Yakovlev, Russia,Omsk WM R865705290089
gen_RFTL

This script functions as a sophisticated trend-following analysis tool designed to smooth out market price movements and clearly identify the prevailing direction of the market. Instead of simply looking at raw, noisy price data, it uses a specialized mathematical approach to provide a "cleaner" view of where the market is heading.

Here is a breakdown of the logic used by this tool:

Core Processing Logic

The script operates using a Digital Filter mechanism. Rather than relying on standard moving averages, it applies a specific set of predefined coefficients (a mathematical weight system) to historical price data.

  1. Data Selection: The user can choose which price point the indicator focuses on—whether it be the opening, closing, highest, or lowest price of a candle.
  2. Filtering Phase: The script takes these prices and processes them through the filter. This calculation determines a "smoothed" value for each point in time. If the tool is running on a timeframe higher than the chart (e.g., looking at 4-hour data on a 1-hour chart), it automatically adjusts the calculations to maintain accuracy across different scales.
  3. Trend Detection: Once the smoothed values are calculated, the script compares each new value against the previous one:
    • If the current value is higher than the previous one, it registers an upward trend.
    • If the current value is lower, it registers a downward trend.

Visual Representation

The tool communicates these findings to the user through two distinct visual lines on the chart:

  • The Up Trend (Lime Line): This line appears when the filter detects a positive movement. It tracks the smoothed price as long as the momentum remains bullish.
  • The Down Trend (Red Line): This line appears when the filter detects a negative movement, tracking the smoothed price during bearish phases.

When the trend switches from up to down (or vice versa), the script handles the transition by "closing" the previous line at the turning point and beginning the new line immediately. This creates a continuous visual history of the market's directional shifts.

Auxiliary Functions

  • Timeframe Management: The script includes logic to ensure that calculations remain consistent even if the user switches between different chart views.
  • User Interaction: The script includes an administrative check to manage user preferences and provides an automated way to interact with the developer for support or contributions via a prompt system.
Price Data Components
Series array that contains close prices for each barSeries array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Miscellaneous
Implements a curve of type %1Uses files from the file systemIt reads information from a fileIt writes information to file
11 Views
0 Downloads
0 Favorites
gen_RFTL
// -----------------------------------------------------------------
//  RFTL
//  Dmitry Yakovlev 
//  dmitry_yakovlev@rambler.ru
//  WebMoney R865705290089
//------------------------------------------------------------------
// Parameters DF: 
// RFTL: P1=14, D1=10, A1=40, P2=52, D2=32, A2=40, Ripple=0.0864, Delay=5


#property copyright "Dmitry Yakovlev, Russia,Omsk WM R865705290089"
#property link      "dmitry_yakovlev@rambler.ru"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Black
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_width1 0
#property indicator_width2 2
#property indicator_width3 2

#import  "shell32.dll"           //Connect a dll (provided with Windows)             
  int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd); 
#import "user32.dll"
  int MessageBoxA(int hWnd ,string lpText,string lpCaption,int uType);
//------------------------------------------------------------------------------------------------------


// ÏÀÐÀÌÅÒÐÛ
extern string  _tf="Òàéìôðåéì (0-òåêóùèé)";
extern int     tf=0;
extern string  _pr="Öåíà 0-cl,1-op,2-hi,3-lo";
extern int     pr=0;
extern string  _donate1="Äëÿ $ áëàãîäàðíîñòè:";
extern string  _donate2="R865705290089";

//---- buffers
double iBuffer[];
double up[];
double dn[];
double trend[];

double F[]=
{
0.0427244051220,+0.0798496403966,+0.1151557791422,+0.1427762745496,+0.1579266069793,+0.1579266069793,+0.1427762745496,
+0.1151557791422,+0.0798496403966,+0.0427244051220,+0.00952274869912,-0.01526900415719,-0.02922757486830,-0.0322728430050,
-0.02639360942444,-0.01505348026677,-0.002179623244963,+0.00871170305657,+0.01526062539351,+0.01660716287034,
+0.01334923351197,+0.00714393572868,+0.0001280673815127,-0.00572164688704,-0.00905661252147,-0.00941895697856,
-0.00722021865323,-0.00348150582689,+0.000536779907191,+0.00370827835280,+0.00532949036053,+0.00523924067169,
+0.00376584455008,+0.001556160742037,-0.000671481978740,-0.002351525647288,-0.00325682927431,-0.00365443171797,
-0.00459998751022,+0.002104648357131
};
int FilterSize=0;
//+------------------------------------------------------------------+
//| Digital filter indicator initialization function                 |
//+------------------------------------------------------------------+
int init()
{
   CheckDonate();
   
   FilterSize=ArraySize(F);
   
   if(tf<Period()) tf=Period();
   if(pr>1)pr=0;
//---- indicator line

   IndicatorShortName("RFTL-"+tf);
   
   IndicatorBuffers(4);
   //---- indicator line
   SetIndexStyle(0,DRAW_NONE);
   SetIndexBuffer(0,iBuffer);

   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(1,up);
   SetIndexLabel(1,"Up");

   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(2,dn);
   SetIndexLabel(2,"Dn");

   SetIndexStyle(3,DRAW_NONE);
   SetIndexBuffer(3,trend);
   SetIndexLabel(3,"trend");

   ArraySetAsSeries(iBuffer, true); 
   ArraySetAsSeries(trend, true);
//----
   return(0);
}
//+------------------------------------------------------------------+
double price(int i)
{
   if(pr==0) return(iClose(Symbol(),tf,i));
   else if(pr==1) return(iOpen(Symbol(),tf,i));
   else if(pr==2) return(iHigh(Symbol(),tf,i));
   else if(pr==3) return(iLow(Symbol(),tf,i));
}
//+------------------------------------------------------------------+
int start()
{
   int k, nn, nn1, i, j, counted_bars=IndicatorCounted();
   int koef=(tf/Period());
   double res=0, step=0;
   // <--- ðàñ÷èòûâàåì çíà÷åíèÿ èíäèêàòîðà
   if (FilterSize>0)
   {
      if(Bars<=FilterSize) return(0);
      //-------------------------------
      i=(Bars-counted_bars+FilterSize-1)/koef+1;
      //-------------------------------
      while(i>=0)
      {
         res=0;
         for (j=0; j<FilterSize; j++)
            res+=F[j]*price(i+j);
         
         nn=i*koef;
         if(nn!=-1) iBuffer[nn]=NormalizeDouble(res,Digits);
         
         nn1=(i+1)*koef;
         if(nn!=-1 && nn1!=-1 && iBuffer[nn1]!=EMPTY_VALUE && iBuffer[nn1]!=0)
         {
            step=(iBuffer[nn1]-iBuffer[nn])/koef;
            for(k=1;k<koef;k++) iBuffer[k+nn]=NormalizeDouble(iBuffer[nn]+step*k,Digits);
         }
         i--;
      }
   } else return;
   // ðàñ÷èòûâàåì -->
   //-------------------------------------------------------------------------
   // <-- ðàñêðàøèâàåì 
   for(int x=Bars;x>=0;x--)
   {
      trend[x] = trend[x+1];
      if (iBuffer[x]> iBuffer[x+1]) trend[x] =1;
      if (iBuffer[x]< iBuffer[x+1]) trend[x] =-1;
 
      if (trend[x]>0)
      { up[x] = iBuffer[x]; 
        if (trend[x+1]<0) up[x+1]=iBuffer[x+1];
        dn[x] = EMPTY_VALUE;
      }
      else              
      if (trend[x]<0)
      { 
        dn[x] = iBuffer[x]; 
        if (trend[x+1]>0) dn[x+1]=iBuffer[x+1];
        up[x] = EMPTY_VALUE;
      }              
   }
   // ðàñêðàøèâàåì -->
   //-------------------------------------------------------------------------
   return(0);
}

void CheckDonate()
{
   int fd=0; string pay="0"; datetime dt=0;
   string fn="DigFlts1.txt";
   fd=FileOpen(fn,FILE_READ|FILE_CSV,";");
   if(fd>=1)
   {
      pay=FileReadString(fd); if(pay!="0" && pay!="1") pay="0";
      dt=StrToTime(FileReadString(fd));
   }
   else
   {
      dt=TimeCurrent();
      fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
      FileWrite(fd,"0",TimeToStr(dt,TIME_DATE));
   }
   FileClose(fd);
   
   if(pay=="0" && (TimeCurrent()-dt)>10*24*60*60) // 5 äíåé
   {
      if(MessageBoxA(0,"Åñëè Âàì ïîíðàâèëñÿ èíäèêàòîð RFTL,\n õîòèòå ïîìî÷ü àâòîðó ìàòåðèàëüíî?","Âîïðîñ",4)==6)
      {
         ShellExecuteA(0,"Open","iexplore.exe","wmk:payto?Purse=R865705290089&Amount=100&Desc=DigitalIndicators&BringToFront=Y&ExecEvenKeeperIsOffline=Y","",7);
         pay="1";
      }
      dt=TimeCurrent();
      
      fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
      FileWrite(fd,pay,TimeToStr(dt,TIME_DATE));
      FileClose(fd);
   }
   FileClose(fd);
}

Comments