FF Tunnel v3-1





//+------------------------------------------------------------------+
//|                                                    FF Tunnel.mq4 |
//|                                                         FFwithFX |
//|                                                                  |
//+------------------------------------------------------------------+
// Time frame enumeration
// Constant    Value Description 
// PERIOD_M1   1     1 minute. 
// PERIOD_M5   5     5 minutes. 
// PERIOD_M15  15    15 minutes. 
// PERIOD_M30  30    30 minutes. 
// PERIOD_H1   60    1 hour. 
// PERIOD_H4   240   4 hour. 
// PERIOD_D1   1440  Daily. 
// PERIOD_W1   10080 Weekly. 
// PERIOD_MN1  43200 Monthly. 
// 0 (zero) 0 Time frame used on the chart. 
//
// Moving Average method enumeration
// Constant    Value    Description 
// MODE_SMA    0        Simple moving average, 
// MODE_EMA    1        Exponential moving average, 
// MODE_SMMA   2        Smoothed moving average, 
// MODE_LWMA   3        Linear weighted moving average. 
//
// Applied price enumeration
// Constant       Value    Description 
// PRICE_CLOSE    0        Close price. 
// PRICE_OPEN     1        Open price. 
// PRICE_HIGH     2        High price. 
// PRICE_LOW      3        Low price. 
// PRICE_MEDIAN   4        Median price, (high+low)/2. 
// PRICE_TYPICAL  5        Typical price, (high+low+close)/3. 
// PRICE_WEIGHTED 6        Weighted close price, (high+low+close+close)/4. 




/*
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Magenta
#property indicator_color2 Red
#property indicator_color3 Silver
#property indicator_color4 Silver
#property indicator_color5 Silver
#property indicator_color6 Silver
#property indicator_color7 Blue  
#property indicator_color8 Silver
*/

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 SaddleBrown
#property indicator_color2 DarkTurquoise
#property indicator_color3 Silver
#property indicator_color4 Silver
#property indicator_color5 Silver
#property indicator_color6 Silver
#property indicator_color7 Green  
#property indicator_color8 Silver


//---- input parameters
extern bool      AudioAlerts=false;
extern bool      VisualAlerts=false;
extern bool      ManuTrend=true;
extern bool      ManuLong=True;
extern int       RiskModel=1;

extern int       Fib1=0;
extern int       Fib2=0;
 
extern int       NeutralLineEntry=20;
extern bool      DarkBackground=true;

extern int       PipRule=50;
/*
extern int Macro_Period = PERIOD_W1;

extern int MacroFMA = 8;
extern int MacroFMA_Type = MODE_SMA;
extern int MacroFMA_Price = PRICE_CLOSE;

extern int MacroSMA = 34;
extern int MacroSMA_Type = MODE_EMA;
extern int MacroSMA_Price = PRICE_CLOSE;

extern int Micro_Period = PERIOD_H4;

extern int MicroFMA = 13;
extern int MicroFMA_Type = MODE_SMA;
extern int MicroFMA_Price = PRICE_CLOSE;

extern int MicroSMA = 55;
extern int MicroSMA_Type = MODE_EMA;
extern int MicroSMA_Price = PRICE_CLOSE;

*/
extern int Macro_Period = PERIOD_W1;

extern int MacroFMA = 5;
extern int MacroFMA_Type = MODE_SMA;
extern int MacroFMA_Price = PRICE_MEDIAN;

extern int MacroSMA = 21;
extern int MacroSMA_Type = MODE_EMA;
extern int MacroSMA_Price = PRICE_MEDIAN;

extern int Micro_Period = PERIOD_H4;

extern int MicroFMA = 8;
extern int MicroFMA_Type = MODE_SMA;
extern int MicroFMA_Price = PRICE_CLOSE;

extern int MicroSMA = 55;
extern int MicroSMA_Type = MODE_SMA;
extern int MicroSMA_Price = PRICE_MEDIAN;


//---- buffers
double ExtMapBuffer1[]; // 55 SMA Median
double ExtMapBuffer2[]; // 8 SMA Close
double ExtMapBuffer3[]; // 1st FibLine up
double ExtMapBuffer4[]; // 2nd FibLine up
double ExtMapBuffer5[]; // 1st FibLine down
double ExtMapBuffer6[]; // 2nd FibLine down
double ExtMapBuffer7[]; // Turning Line
double ExtMapBuffer8[];
string MiTr;
double witr=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,MicroSMA + " MA");
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,MicroFMA + " MA");   
   SetIndexStyle(2,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(4,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexStyle(6,0,2,1,Green);
   //SetIndexStyle(6,DRAW_NONE);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexLabel(6,"Slope Change");
   SetIndexStyle(7,DRAW_LINE);
   SetIndexStyle(7,DRAW_NONE);
   SetIndexBuffer(7,ExtMapBuffer8);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
ObjectDelete("NeutralLine");
ObjectDelete("NeutralLineEntry");           
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int    counted_bars=IndicatorCounted();
   
   double curr_Slow;
   double curr_Fast;
   double prev_Slow;
   double prev_Fast;
   double WDiff;
   
   string Direction;
   string Filter;
  
  //---- check for possible errors
   if(counted_bars<0) return(-1);
  //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

//---- Calculate the different weekly data
         curr_Slow=iMA(NULL,Macro_Period,MacroSMA,0,MacroSMA_Type,MacroSMA_Price,0);
         curr_Fast=iMA(NULL,Macro_Period,MacroFMA,0,MacroFMA_Type,MacroFMA_Price,0);

         prev_Slow=iMA(NULL,Macro_Period,MacroSMA,0,MacroSMA_Type,MacroSMA_Price,1);
         prev_Fast=iMA(NULL,Macro_Period,MacroFMA,0,MacroFMA_Type,MacroFMA_Price,1);

         WDiff=((curr_Fast-curr_Slow) - (prev_Fast-prev_Slow));
         if (ManuTrend)
          {
          if (ManuLong) Direction = "^^ UP ^^";
          else Direction = "vv DOWN vv"; 
           }         
         else 
         {
         if (WDiff > 0.0) Direction = "^^ UP ^^";
         else if (WDiff < 0.0) Direction = "vv DOWN vv";          
         }

  //---- main loop
     for(int i=0; i<limit; i++)
       {

        //---- ma_shift set to 0 because SetIndexShift called abowe
         ExtMapBuffer1[i]=iMA(NULL,Micro_Period,MicroSMA,0,MicroSMA_Type,MicroSMA_Price,i);
         ExtMapBuffer2[i]=iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,i);
          ExtMapBuffer7[i]=Close[i+MicroFMA];
         Filter = "OK to Trade";
         
         switch (RiskModel)
            {
               case 0:
                  ExtMapBuffer3[i]=ExtMapBuffer1[i]+Fib1*Point;  
                  ExtMapBuffer4[i]=ExtMapBuffer1[i]+Fib2*Point;
                  ExtMapBuffer5[i]=ExtMapBuffer1[i]-Fib1*Point;
                  ExtMapBuffer6[i]=ExtMapBuffer1[i]-Fib2*Point;
                  break;

               case 1:
                  ExtMapBuffer3[i]=ExtMapBuffer1[i]+89*Point;  
                  ExtMapBuffer4[i]=ExtMapBuffer1[i]+144*Point;
                  ExtMapBuffer5[i]=ExtMapBuffer1[i]-89*Point;
                  ExtMapBuffer6[i]=ExtMapBuffer1[i]-144*Point;
                  break;

               case 2:
                  ExtMapBuffer3[i]=ExtMapBuffer1[i]+144*Point;  
                  ExtMapBuffer4[i]=ExtMapBuffer1[i]+233*Point;
                  ExtMapBuffer5[i]=ExtMapBuffer1[i]-144*Point;
                  ExtMapBuffer6[i]=ExtMapBuffer1[i]-233*Point;
                  break;

               case 3:
                  ExtMapBuffer3[i]=ExtMapBuffer1[i]+233*Point;  
                  ExtMapBuffer4[i]=ExtMapBuffer1[i]+377*Point;
                  ExtMapBuffer5[i]=ExtMapBuffer1[i]-233*Point;
                  ExtMapBuffer6[i]=ExtMapBuffer1[i]-377*Point;
                  break;
            }
 
             
         //---Determine and draw Neutral Line Entry        
         //if(Open[i] < ExtMapBuffer7[i])
         
      
         if (Direction == "^^ UP ^^") //up
            {
               ExtMapBuffer8[i]=Close[MicroFMA]+(NeutralLineEntry*Point);
              if (iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,0)<iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,1)) witr=1;
             if (iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,1)<iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,2)) witr=1;
             
            }
            
         else if (Direction == "vv DOWN vv") //down
            {
               ExtMapBuffer8[i]=Close[MicroFMA]-(NeutralLineEntry*Point);
             if (iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,0)>iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,1)) witr=1;
             if (iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,1)>iMA(NULL,Micro_Period,MicroFMA,0,MicroFMA_Type,MicroFMA_Price,2)) witr=1;
             
              }
if (witr==1)
{
witr=0;
          
         if(ObjectFind("NeutralLineEntry") != 0)
            {
               ObjectCreate("NeutralLineEntry", OBJ_ARROW, 0, Time[0], ExtMapBuffer8[0]);
               ObjectSet("NeutralLineEntry", OBJPROP_ARROWCODE, 6);
               ObjectSet("NeutralLineEntry", OBJPROP_WIDTH, 1);
               ObjectSet("NeutralLineEntry", OBJPROP_RAY, false);  
            
               if(DarkBackground) 
                  {
                     ObjectSet("NeutralLineEntry", OBJPROP_COLOR, Silver);                
                  }                     
               else 
                  {
                     ObjectSet("NeutralLineEntry", OBJPROP_COLOR, Blue);              
                  }                     
            }

         else
            {
               ObjectMove("NeutralLineEntry", 0, Time[0], ExtMapBuffer8[0]);
            }
 
          //---Determine and draw Neutral Line 
         if(ObjectFind("NeutralLine") != 0)
            {
              ObjectCreate("NeutralLine", OBJ_TREND, 0,Time[MicroFMA], ExtMapBuffer7[0], Time[0], ExtMapBuffer7[0]);
              ObjectSet("NeutralLine", OBJPROP_STYLE, STYLE_SOLID);
              ObjectSet("NeutralLine", OBJPROP_WIDTH, 1);
              ObjectSet("NeutralLine", OBJPROP_RAY, false);  
              
              if(DarkBackground) 
                  {
                     ObjectSet("NeutralLine", OBJPROP_COLOR, Silver); 
                  }                                         
              else 
                  {
                     ObjectSet("NeutralLine", OBJPROP_COLOR, Blue);               
                  }                     
            }
         else
            {
              ObjectMove("NeutralLine", 0, Time[MicroFMA], ExtMapBuffer7[0]);
              ObjectMove("NeutralLine", 1, Time[0], ExtMapBuffer7[0]);
            } 
                    
       }
}
// Check for FILTER conditions
         if (MathAbs(ExtMapBuffer1[0]-ExtMapBuffer2[0]) < PipRule*Point) {
         Filter = StringConcatenate("WARNING: Only trade if Price > ",MathMin(ExtMapBuffer1[0],ExtMapBuffer2[0])+PipRule*Point,
         " or < ",MathMax(ExtMapBuffer1[0],ExtMapBuffer2[0])-PipRule*Point);
         }         
      
  if (ManuTrend)MiTr = "MANUALLY SET";
  else MiTr = GetToken(Macro_Period);       
         
         Comment(GetToken(Micro_Period) + " Tunnel, " + MiTr + " Direction : ",Direction,"\n",Filter,
        
         "\nRISK MODEL #",RiskModel," (0-3)",
         "\nSlope Change : ",ExtMapBuffer7[0],
         "     Neutral Line Entry = ",ExtMapBuffer8[0],
         "\n",
         "\nMA+2 : ",ExtMapBuffer4[0],
         "\nMA+1 : ",ExtMapBuffer3[0],
         "\nMA" + MicroSMA + " : "  ,ExtMapBuffer1[0],
         "\nMA-1 : ",ExtMapBuffer5[0],
         "\nMA-2 : ",ExtMapBuffer6[0]);

//       }
       
       //+--------------------------------------------------------------------------+
       //-                          ALERTS    PlaySound("alert.wav");               -
       //+--------------------------------------------------------------------------+
      if(AudioAlerts)
      {
         if(Close[i]>ExtMapBuffer7[0] || Close[i]<ExtMapBuffer7[0])
         {
            PlaySound("alert.wav");
         }
      }

      if(VisualAlerts)
      {
         if(Close[0]==ExtMapBuffer7[0] || Close[0]==ExtMapBuffer7[0])
         {
           Alert(Symbol()," ", Period(), "min Slope Change - ",Close[0],
            "\n Time: ", TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS),"\n",Filter);
         }
      }
         
  //---- done

//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

string GetToken(int pParam)
  {
      string sToken;
      
      switch (pParam)
         {
// PERIOD_M1   1     1 minute. 
            case 1:
               sToken = "1 min";
               break;
               
// PERIOD_M5   5     5 minutes. 
            case 5:
               sToken = "5 min";
               break;
// PERIOD_M15  15    15 minutes. 
            case 15:
               sToken = "15 min";
               break;
// PERIOD_M30  30    30 minutes. 
            case 30:
               sToken = "30 min";
               break;
// PERIOD_H1   60    1 hour. 
            case 60:
               sToken = "1 hour";
               break;
// PERIOD_H4   240   4 hour. 
            case 240:
               sToken = "4 hour";
               break;
// PERIOD_D1   1440  Daily. 
            case 1440:
               sToken = "Daily";
               break;
// PERIOD_W1   10080 Weekly. 
            case 10080:
               sToken = "Weekly";
               break;
// PERIOD_MN1  43200 Monthly. 
            case 43200:
               sToken = "Monthly";
               break;               
         }          
         
      return (sToken);
  }



Sample



image not available


Analysis



Market Information Used:

Series array that contains close prices for each bar
Series array that contains open time of each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE

Implements a curve of type 0
Implements a curve of type DRAW_NONE

Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features:

It plays sound alerts
It issuies visual alerts to the screen