FF Tunnel v3
Download scriptThis script functions as a multi-layered technical analysis tool designed to help traders identify high-probability market trends and entry points by combining "Macro" (long-term) and "Micro" (short-term) market data. It acts as a visual navigation system, filtering out market noise to show the user where the price is likely heading and where specific trade boundaries exist.
Core Logic Overview
1. Dual-Timeframe Analysis (Macro vs. Micro) The logic operates on two distinct scales simultaneously:
- Macro Perspective: The script looks at weekly data to determine the "big picture" trend. It calculates the difference between two moving averages to detect if the overall market direction is tilting upward or downward.
- Micro Perspective: The script looks at 4-hour data to provide immediate, actionable information on current price action and volatility.
2. Dynamic Trend Detection By comparing the velocity of these long-term moving averages, the script determines the general market sentiment. If the "Macro" movement is gaining momentum upward, the script prepares for bullish setups; if it's tilting downward, it prepares for bearish setups. This helps prevent traders from taking trades that go against the primary flow of the market.
3. Risk Models and Fibonacci Boundaries The tool features four different "Risk Models." Depending on which model is selected, the script automatically calculates a series of support and resistance boundaries (similar to Fibonacci levels) around the main price averages. These act as visual "tunnels" or zones:
- They provide clear targets for profit-taking.
- They establish "no-trade zones" where price action might be too unstable.
4. The Neutral Line and Entry Markers One of the script's primary functions is identifying the "Neutral Line." This is a dynamic visual aid that shifts based on the Macro direction:
- In an Upward trend, it projects a specific entry distance above the current price.
- In a Downward trend, it projects a specific entry distance below the current price.
- The script also places a physical marker (an arrow) on the chart to highlight these specific neutral entry points in real-time.
5. Safety Filters and Alerts To protect the user from "choppy" markets (where price is moving sideways with no clear direction), the script includes a built-in Pip Rule filter. If the gap between the primary moving averages is too small, it generates an on-screen warning advising the user to stay out of the market until the trend becomes clearer.
6. Visual and Audio Notifications The script provides real-time feedback through:
- On-Screen Comments: A dashboard showing the current direction, risk levels, and specific price coordinates for all calculated boundaries.
- Visual/Audio Alerts: Optional triggers that notify the user when the price interacts with key "Slope Change" levels, ensuring the trader doesn't miss critical turning points in the market.
//+------------------------------------------------------------------+
//| 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 copyright "Financial Freedom with Forex"
#property link ""
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Magenta
#property indicator_color2 Aqua
#property indicator_color3 HotPink
#property indicator_color4 Pink
#property indicator_color5 HotPink
#property indicator_color6 Pink
#property indicator_color7 Blue
#property indicator_color8 Silver
//---- input parameters
extern bool AudioAlerts=false;
extern bool VisualAlerts=false;
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 = 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[];
//+------------------------------------------------------------------+
//| 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,DRAW_LINE,STYLE_DOT,1,Green);
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 (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 (WDiff > 0.0) //up
{
ExtMapBuffer8[i]=Close[MicroFMA]+(NeutralLineEntry*Point);
}
else if (WDiff < 0.0) //down
{
ExtMapBuffer8[i]=Close[MicroFMA]-(NeutralLineEntry*Point);
}
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);
}
Comment("v3.1 4Hr Tunnel Macro 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],
"\nSMA55 : ",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);
}
//+------------------------------------------------------------------+
Comments