Price Data Components
Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
FF Tunnel v3
//+------------------------------------------------------------------+
//| 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
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---