EMA_Prediction_v1

Download script
Author: Codersguru
EMA_Prediction_v1

This tool is designed to analyze price movements in the financial markets by identifying specific momentum shifts. It operates by monitoring two different types of moving averages—a "short-term" average and a "long-term" average—to determine when the market's direction might be changing.

How the Logic Works

The script looks for specific "crossover" events. A crossover occurs when the short-term average line moves from being below the long-term line to above it (or vice versa). However, to ensure these signals are more reliable, the tool adds an extra layer of verification by checking the actual price action of the candles.

1. Buy Signal Identification The tool looks for a specific upward momentum pattern:

  • Crossover: The short-term average must cross from below to above the long-term average.
  • Price Confirmation: It verifies that the most recent candle is a "bearish" candle (where the price opened higher than it closed).
  • When both conditions are met, the script places a visual signal on the chart to highlight a potential upward move.

2. Sell Signal Identification Conversely, the tool looks for a downward momentum pattern:

  • Crossover: The short-term average must cross from above to below the long-term average.
  • Price Confirmation: It verifies that the most recent candle is a "bullish" candle (where the price opened lower than it closed).
  • When both conditions are met, the script places a visual signal on the chart to highlight a potential downward move.

Visual Features

The indicator provides clear visual feedback directly on your trading chart:

  • Arrows: It uses distinct arrows to mark exactly where these momentum shifts occur, allowing you to see historical signals at a glance.
  • Optional Trend Lines: Depending on your settings, the tool can also draw the moving average lines themselves on the chart. This helps you visualize the relationship between the short-term and long-term trends in real-time.

In summary, this script acts as a trend-detection assistant. It filters out noise by requiring both a mathematical crossover of averages and a specific price candle confirmation before highlighting a potential trade signal.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
EMA_Prediction_v1
//+------------------------------------------------------------------+
//|                                               EMA_Prediction.mq4 |
//|                                                       Codersguru |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Codersguru"
#property link      "http://www.forex-tsd.com"
//----
extern int ShortEma=1;
extern int LongEma=2;
extern bool Draw_Lines=false;
//----
#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);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(0, 234);
   SetIndexArrow(1, 233);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE, STYLE_SOLID,2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE, STYLE_SOLID,2);
   SetIndexBuffer(3,ExtMapBuffer4);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//---- 
   int pos=Bars - counted_bars - 1;
   while(pos>=0)
     {
      Signal1=0;
      Signal2=0;
      Previous_Bar=0;
//----
      double EmaLongPrevious=iMA(NULL,0,LongEma,0,MODE_EMA, PRICE_CLOSE, pos-1);
      double EmaLongCurrent=iMA(NULL,0,LongEma,0,MODE_EMA, PRICE_CLOSE, pos);
      double EmaShortPrevious=iMA(NULL,0,ShortEma,0,MODE_EMA, PRICE_CLOSE, pos-1);
      double EmaShortCurrent=iMA(NULL,0,ShortEma,0,MODE_EMA, PRICE_CLOSE, pos);
//----
      if (Open[pos] > Close[pos]) Previous_Bar=1;
      if (Open[pos] < Close[pos]) Previous_Bar=2;
      if (EmaShortPrevious<EmaLongPrevious && EmaShortCurrent>EmaLongCurrent && Previous_Bar==1)Signal1=High[pos];
      if (EmaShortPrevious>EmaLongPrevious && EmaShortCurrent<EmaLongCurrent && Previous_Bar==2)Signal2=Low[pos];
//----
      ExtMapBuffer1[pos-1]= Signal1+5*Point;
      ExtMapBuffer2[pos-1]=Signal2-5*Point;
      if(Draw_Lines)
        {
         ExtMapBuffer3[pos]= EmaLongCurrent;
         ExtMapBuffer4[pos]= EmaShortCurrent;
        }
      pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments