_2523_255eMTF_EMA_Prediction_2
Download scriptThis tool is designed to assist traders by analyzing price trends and providing visual alerts on the MetaTrader platform. Its primary logic revolves around tracking Exponential Moving Averages (EMA)—a common method used to smooth out price fluctuations—and identifying specific moments where those trends shift or interact.
Multi-Timeframe Analysis
One of the core strengths of this script is its ability to look beyond the current chart you are viewing. It can pull data from different timeframes (such as moving from a 1-minute view to a 4-hour view) and project that information onto your current screen. This allows you to keep track of the "big picture" market direction without having to constantly switch back and forth between different charts.
Core Logic & Trend Detection
The script operates by comparing two different EMA speeds: a "Short" EMA and a "Long" EMA. By calculating these two averages simultaneously, the tool looks for specific patterns in price momentum:
- Trend Identification: It monitors how quickly the price is moving relative to its historical average.
- Signal Generation: When the relationship between these two averages reaches specific criteria, the script triggers a visual signal. These signals are designed to highlight potential entry or exit points based on trend changes.
Visual Interface Features
To make the data easy for human traders to read quickly, the script translates its mathematical calculations into several types of visual cues:
- Arrows and "Thumbs": The tool places specific icons (arrows) on the chart to pinpoint exact locations where a signal has occurred. These serve as immediate visual confirmations of trend shifts.
- Vertical Lines: It can automatically draw vertical lines at key signal points, creating a historical "map" of price action and making it easier to see how often certain patterns occur.
- Trend Lines: Depending on the settings, it can plot lines that visually represent the moving averages, helping you see the flow of the market in real-time.
Clean Environment Management
The script is built with a "clean-up" logic. When you remove the indicator from your chart, it is programmed to automatically delete the visual objects (lines and arrows) it created. This ensures your trading workspace remains organized and free of cluttered data from previous sessions.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| EMA_Prediction_2.mq4 |
//| Codersguru |
//| http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Codersguru"
#property link "http://www.forex-tsd.com"
extern int TimeFrame=0;
extern int ShortEma=1;
extern int LongEma=2;
extern bool Draw_Lines = true;
extern bool Vertical_Lines = true;
extern bool Show_Thumbs = true;
#property indicator_buffers 4
#property indicator_chart_window
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double Signal1=0,Signal2=0;
int Previous_Bar = 0;
int init()
{
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,2);
SetIndexArrow(0, 234);
SetIndexArrow(1, 233);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,ExtMapBuffer4);
//---- name for DataWindow and indicator subwindow label
switch(TimeFrame)
{
case 1 : string TimeFrameStr="Period_M1"; break;
case 5 : TimeFrameStr="Period_M5"; break;
case 15 : TimeFrameStr="Period_M15"; break;
case 30 : TimeFrameStr="Period_M30"; break;
case 60 : TimeFrameStr="Period_H1"; break;
case 240 : TimeFrameStr="Period_H4"; break;
case 1440 : TimeFrameStr="Period_D1"; break;
case 10080 : TimeFrameStr="Period_W1"; break;
case 43200 : TimeFrameStr="Period_MN1"; break;
default : TimeFrameStr="Current Timeframe";
}
IndicatorShortName("MTF_EMA_Prediction_2 ("+TimeFrameStr+")");
return(0);
}
void DrawVertical( int bar , double value, color clr)
{
static int cnt = 0;
cnt++;
string dv = "Signal" + cnt;
ObjectCreate(dv, OBJ_VLINE, 0, Time[bar], 0);
ObjectSet(dv, OBJPROP_COLOR, clr);
ObjectsRedraw();
}
void DrawThumb( int bar , int thumb , double value, color clr)
{
static int cnt = 0;
cnt++;
string dv = "thumb" + cnt;
ObjectCreate(dv, OBJ_ARROW, 0, Time[bar], value);
if(thumb == 1)
{
ObjectSet(dv, OBJPROP_ARROWCODE, 67);
}
if(thumb == 2)
{
ObjectSet(dv, OBJPROP_ARROWCODE, 68);
}
ObjectSet(dv, OBJPROP_COLOR, clr);
ObjectSet(dv, OBJPROP_STYLE , STYLE_SOLID);
ObjectSet(dv, OBJPROP_WIDTH , 3);
ObjectsRedraw();
}
int deinit()
{
int I = WindowsTotal();
for (int count = 0; count < WindowsTotal(); count++)
{
int nObjects = ObjectsTotal();
for (int i=nObjects; i>=0; i--)
{
string objName = ObjectName(i);
if(StringFind(objName, "Signal", 0) >= 0)
ObjectDelete(objName);
if(StringFind(objName, "thumb", 0) >= 0)
ObjectDelete(objName);
}
}
return(0);
}
int start()
{
datetime TimeArray[];
int i,limit,y=0,counted_bars=IndicatorCounted();
// Plot defined time frame on to current time frame
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
limit=Bars-counted_bars;
for(i=0,y=0;i<limit;i++)
{
if (Time[i]<TimeArray[y]) y++;
//----
ExtMapBuffer1[1]=iCustom(NULL,TimeFrame,"EMA_Prediction_2", ShortEma,LongEma,Draw_Lines,Vertical_Lines,Show_Thumbs,Signal1,0,y);
ExtMapBuffer2[1]=iCustom(NULL,TimeFrame,"EMA_Prediction_2", ShortEma,LongEma,Draw_Lines,Vertical_Lines,Show_Thumbs,Signal2,1,y);
ExtMapBuffer3[1]=iCustom(NULL,TimeFrame,"EMA_Prediction_2", ShortEma,LongEma,Draw_Lines,Vertical_Lines,Show_Thumbs,2,y);
ExtMapBuffer4[1]=iCustom(NULL,TimeFrame,"EMA_Prediction_2", ShortEma,LongEma,Draw_Lines,Vertical_Lines,Show_Thumbs,3,y);
}
//
return(0);
}
Comments