ew1
Download scriptThis technical indicator is designed to analyze market trends by calculating the relationship between two different moving averages. It provides a visual representation of price momentum and shifts in direction, making it easier for traders to identify whether the current market movement is bullish or bearish.
Core Logic and Methodology
The script operates based on the difference between a fast-moving average (which reacts quickly to recent price changes) and a slow-moving average (which reflects longer-term price behavior). By subtracting the slow average from the fast one, the tool creates a "difference" value that represents the current strength of the trend.
To ensure the signals are reliable, the logic follows these specific steps:
1. Establishing Extremes (Backtesting Range) The indicator does not look at just the current moment in isolation. It looks back over a user-defined period (determined by the "back_test" setting). Within this window, it identifies the highest point (peak) and the lowest point (valley) of the difference between the two moving averages.
2. Trend Identification The script then compares the current difference to those identified peaks and valleys:
- Bullish Shift: If the current difference reaches a new high within that look-back period, the indicator recognizes a potential upward trend.
- Bearish Shift: If the current difference reaches a new low within that look-back period, it recognizes a potential downward trend.
3. Reversal and Trigger Mechanism The indicator includes a specific "trigger" logic to help filter out market noise. It looks for significant corrections:
- If the market is in a downward trend but rallies significantly (based on a percentage defined by the "triger" variable), it may signal a shift back to an upward trend.
- Conversely, if the market is in an upward trend but drops significantly, it may signal a shift back to a downward trend.
Visual Output
The final result is plotted as a line in a separate window on your trading platform. Instead of showing complex price numbers, it simplifies the market state into a binary trend:
- A positive value typically represents an upward momentum.
- A negative value typically represents a downward momentum.
By monitoring these shifts, users can better visualize when the "weight" of the market is moving in one direction versus another, providing a clearer picture of the prevailing trend without being distracted by minor price fluctuations.
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| .mq4 |
//| |
//| |
//| Converted by Mql2Mq4 v0.7 |
//| http://yousky.free.fr |
//| Copyright © 2006, Yousky Soft |
//+------------------------------------------------------------------+
//#property copyright " CONVERT BY "ENG.AED AL NAIRAB" ."
#property link " http://www.nairab.com/"
#property indicator_separate_window
#property indicator_color1 Blue
#property indicator_buffers 1
//+------------------------------------------------------------------+
//| Common External variables |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| External variables |
//+------------------------------------------------------------------+
extern double triger = 0.70;
extern double back_test = 20;
//+------------------------------------------------------------------+
//| Special Convertion Functions |
//+------------------------------------------------------------------+
int LastTradeTime;
double ExtHistoBuffer[];
void SetLoopCount(int loops)
{
}
void SetIndexValue(int shift, double value)
{
ExtHistoBuffer[shift] = value;
}
//+------------------------------------------------------------------+
//| End |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Initialization |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables |
//+------------------------------------------------------------------+
int shift = 0;
int i = 0;
double llv = 0;
double hhv = 0;
double taiv = 0;
double trend = 0;
/*[[
Name := ew1
Author := CONVERT BY "ENG.AED AL NAIRAB" .
Link := http://www.nairab.com/
Separate Window := yes
First Color := Blue
First Draw Type := Line
First Symbol := 217
Use Second Data := no
Second Color := Red
Second Draw Type := Line
Second Symbol := 218
]]*/
SetLoopCount(0);
// loop from first bar to current bar (with shift=0)
for(shift=900;shift>=0 ;shift--){
llv=iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_MEDIAN, shift)-iMA(NULL, 0, 35, 0, MODE_SMA, PRICE_MEDIAN, shift);
hhv=iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_MEDIAN, shift)-iMA(NULL, 0, 35, 0, MODE_SMA, PRICE_MEDIAN, shift);
for(i=shift;i<=shift+back_test ;i++){
llv=MathMin(iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_MEDIAN, i)-iMA(NULL, 0, 35, 0, MODE_SMA, PRICE_MEDIAN, i),llv);
hhv=MathMax(iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_MEDIAN, i)-iMA(NULL, 0, 35, 0, MODE_SMA, PRICE_MEDIAN, i),hhv);
}
if( ( hhv == (iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_MEDIAN, shift)-iMA(NULL, 0, 35, 0, MODE_SMA, PRICE_MEDIAN, shift))&& trend == 0)) trend=1;
if( ( llv == (iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_MEDIAN, shift)-iMA(NULL, 0, 35, 0, MODE_SMA, PRICE_MEDIAN, shift))&& trend == 0)) trend=-1;
if( ( llv<0 && trend == -1 && (iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_MEDIAN, shift)-iMA(NULL, 0, 35, 0, MODE_SMA, PRICE_MEDIAN, shift))>-1*triger*llv)) trend=1;
if( ( hhv>0 && trend == 1 && (iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_MEDIAN, shift)-iMA(NULL, 0, 35, 0, MODE_SMA, PRICE_MEDIAN, shift))<-1*triger*hhv)) trend=-1;
SetIndexValue(shift, trend);
}
return(0);
}
Comments