TrendForce_3
Download scriptThis script is designed to provide traders with a comprehensive visual representation of market momentum by aggregating data from multiple technical analysis tools simultaneously. Instead of relying on a single indicator, it acts as a "consensus engine," scanning various market signals to determine the overall strength and direction of a trend.
Core Logic Overview
The primary logic of this script revolves around Multi-Timeframe Aggregation and Signal Voting. Here is how it functions step-by-step:
1. Multi-Timeframe Scanning Rather than looking only at the chart you are currently viewing, the script simultaneously analyzes data across seven different timeframes (ranging from the 1-minute chart up to the Daily chart). This ensures that short-term price "noise" doesn't mislead the user about the broader market direction.
2. The "Voting" System For every single timeframe analyzed, the script calculates 13 distinct technical indicators. Each indicator is assigned a "vote" based on its current behavior:
- Moving Averages: It checks three different speeds (Fast, Medium, and Slow) to see if the price is moving up or down relative to historical averages.
- Momentum & Oscillators: It evaluates several popular tools, including RSI (Relative Strength Index), MACD, CCI (Commodity Channel Index), Stochastic Oscillators, DeMarker, and Momentum.
- Power Indicators: It specifically looks at "Bulls Power" and "Bears Power" to see which side of the market has more aggressive energy.
3. Calculation of Trend Force The script tallies all these votes to create a percentage score:
- If the majority of indicators across all timeframes are bullish, the "Upward Force" percentage increases.
- If the majority are bearish, the "Downward Force" percentage increases.
4. Visual Representation The results are presented to the user in three distinct ways on the chart:
- The Histogram: A visual bar at the bottom of the screen shows the net strength of the trend. Positive values (Green) indicate upward pressure, while negative values (Red) indicate downward pressure.
- Live Percentage Labels: The script displays real-time text labels on the corner of your screen showing the exact percentage of "UP" vs. "DOWN" force currently detected by the system.
- Dynamic Scaling: The final visual output is centered at zero, allowing traders to see exactly how much the market is leaning in one direction or the other relative to a neutral state.
Summary for the User
In plain terms, this tool tells you what the "wisdom of the crowd" (in this case, the crowd of indicators) says about the market. By checking dozens of different mathematical signals across various timeframes at once, it filters out minor fluctuations to show you whether the prevailing trend is strongly bullish, strongly bearish, or currently neutral.
//+------------------------------------------------------------------+
//| TrendForce_3.mq4 |
//+------------------------------------------------------------------+
//| Ðàñ÷åò ñèëû òåíäåíöèè äâèæåíèÿ íà ðûíêå, íàáîð èíäèêàòîðîâ è èõ
//| ïàðàìåòðû ïîëíîñòüþ âçÿòû èç:
//| -----------------------------------------------------------------+
//| FerruFx_Multi_info+_light_chart_v1.1-Ndisc.mq4 |
//| Copyright © 2007, FerruFx |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Bookkeeper"
#property link "yuzefovich@gmail.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_minimum -50
#property indicator_maximum 50
#property indicator_level1 25.0
#property indicator_level2 -25.0
extern int MaxBars = 500;
//---- Indicators parameters
//---- Moving Average Settings
int FastMAPeriod = 20; // Fast Moving Average period
int MediumMAPeriod = 50; // Medium Moving Average period
int SlowMAPeriod = 100; // Slow Moving Average period
int MAMethod = MODE_EMA; // Moving Average method
int MAPrice = PRICE_CLOSE; // Moving Average price
//---- CCI Settings
int CCIPeriod = 14; // Commodity Channel Index period
int CCIPrice = PRICE_CLOSE; // CCI price
//---- MACD Settings
int MACDFast = 12; // MACD fast EMA period
int MACDSlow = 26; // MACD slow EMA period
int MACDSignal = 9; // MACD signal SMA period
//---- ADX Settings ===";
int ADXPeriod = 14; // Average Directional movement period
int ADXPrice = PRICE_CLOSE; // ADX price
//---- BULLS Settings ===";
int BULLSPeriod = 13; // Bulls Power period
int BULLSPrice = PRICE_CLOSE; // Bulls Power price
//---- BEARS Settings ===";
int BEARSPeriod = 13; // Bears Power period
int BEARSPrice = PRICE_CLOSE; // Bears Power price
//---- STOCHASTIC Settings ===";
int STOKPeriod = 5; // Stochastic %K period
int STODPeriod = 3; // Stochastic %D period
int STOSlowing = 3; // Stochastic slowing
//---- RSI Settings ===";
int RSIPeriod = 14; // RSI period
//---- FORCE INDEX Settings ===";
int FIPeriod = 14; // Force Index period
int FIMethod = MODE_SMA; // Force Index method
int FIPrice = PRICE_CLOSE; // Force Index price
//---- MOMENTUM INDEX Settings ===";
int MOMPeriod = 14; // Momentum period
int MOMPrice = PRICE_CLOSE; // Momentum price
//---- DeMARKER Settings ===";
int DEMPeriod = 14; // DeMarker period
double UpForce_Buffer[];
double DnForce_Buffer[];
int TF[7]={PERIOD_D1,
PERIOD_H4,
PERIOD_H1,
PERIOD_M30,
PERIOD_M15,
PERIOD_M5,
PERIOD_M1};
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,UpForce_Buffer);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,DnForce_Buffer);
ObjectCreate("Trend_text", OBJ_LABEL, 0, 0, 0);
ObjectSetText("Trend_text","Trend Force",9, "System", Blue);
ObjectSet("Trend_text", OBJPROP_CORNER, 1);
ObjectSet("Trend_text", OBJPROP_XDISTANCE, 15);
ObjectSet("Trend_text", OBJPROP_YDISTANCE, 10);
ObjectCreate("Trend_UP_text", OBJ_LABEL, 0, 0, 0);
ObjectSet("Trend_UP_text", OBJPROP_CORNER, 1);
ObjectSet("Trend_UP_text", OBJPROP_XDISTANCE, 50);
ObjectSet("Trend_UP_text", OBJPROP_YDISTANCE, 30);
ObjectCreate("Trend_UP_value", OBJ_LABEL, 0, 0, 0);
ObjectSet("Trend_UP_value", OBJPROP_CORNER, 1);
ObjectSet("Trend_UP_value", OBJPROP_XDISTANCE, 15);
ObjectSet("Trend_UP_value", OBJPROP_YDISTANCE, 30);
ObjectCreate("Trend_DOWN_text", OBJ_LABEL, 0, 0, 0);
ObjectSet("Trend_DOWN_text", OBJPROP_CORNER, 1);
ObjectSet("Trend_DOWN_text", OBJPROP_XDISTANCE, 50);
ObjectSet("Trend_DOWN_text", OBJPROP_YDISTANCE, 45);
ObjectCreate("Trend_DOWN_value", OBJ_LABEL, 0, 0, 0);
ObjectSet("Trend_DOWN_value", OBJPROP_CORNER, 1);
ObjectSet("Trend_DOWN_value", OBJPROP_XDISTANCE, 15);
ObjectSet("Trend_DOWN_value", OBJPROP_YDISTANCE, 45);
return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("Trend_text");
ObjectDelete("Trend_UP_text");
ObjectDelete("Trend_UP_value");
ObjectDelete("Trend_DOWN_text");
ObjectDelete("Trend_DOWN_value");
return(0);
}
//+------------------------------------------------------------------+
int start()
{
if( Period() > PERIOD_D1 ) return(0);
int i, limit, counted_bars=IndicatorCounted();
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-counted_bars+1;
if(limit>MaxBars) limit=MaxBars;
//if(limit>Bars-SlowMAPeriod-2) limit=Bars-SlowMAPeriod-2;
for(i=0;i<=limit;i++)
{
int shift, SUM_UP=0, SUM_DOUN=0;
for(int j=0; j<7; j++)
{
int TimeFrame=TF[j];
if(i==0) shift=0;
else
{
if( Period() == TimeFrame ) shift=i;
if( Period() < TimeFrame ) shift=iBarShift(NULL,TimeFrame,Time[i],false);
if( Period() > TimeFrame ) shift=iBarShift(NULL,TimeFrame,Time[i-1],false)+1;
}
double FastMA_1 = iMA(NULL,TimeFrame,FastMAPeriod,0,MAMethod,MAPrice,shift);
double FastMA_2 = iMA(NULL,TimeFrame,FastMAPeriod,0,MAMethod,MAPrice,shift+1);
if ((FastMA_1 > FastMA_2)) SUM_UP++;
if ((FastMA_1 < FastMA_2)) SUM_DOUN++;
double MediumMA_1 = iMA(NULL,TimeFrame,MediumMAPeriod,0,MAMethod,MAPrice,shift);
double MediumMA_2 = iMA(NULL,TimeFrame,MediumMAPeriod,0,MAMethod,MAPrice,shift+1);
if ((MediumMA_1 > MediumMA_2)) SUM_UP++;
if ((MediumMA_1 < MediumMA_2)) SUM_DOUN++;
double SlowMA_1 = iMA(NULL,TimeFrame,SlowMAPeriod,0,MAMethod,MAPrice,shift);
double SlowMA_2 = iMA(NULL,TimeFrame,SlowMAPeriod,0,MAMethod,MAPrice,shift+1);
if ((SlowMA_1 > SlowMA_2)) SUM_UP++;
if ((SlowMA_1 < SlowMA_2)) SUM_DOUN++;
double cci=iCCI(NULL,TimeFrame,CCIPeriod,CCIPrice,shift);
if ((cci > 0)) SUM_UP++;
if ((cci < 0)) SUM_DOUN++; //
double MACD_m=iMACD(NULL,TimeFrame,MACDFast,MACDSlow,MACDSignal,PRICE_CLOSE,MODE_MAIN,shift);
double MACD_s=iMACD(NULL,TimeFrame,MACDFast,MACDSlow,MACDSignal,PRICE_CLOSE,MODE_SIGNAL,shift);
if ((MACD_m > MACD_s)) SUM_UP++;
if ((MACD_m < MACD_s)) SUM_DOUN++;
double ADX_plus=iADX(NULL,TimeFrame,ADXPeriod,ADXPrice,MODE_PLUSDI,shift);
double ADX_minus=iADX(NULL,TimeFrame,ADXPeriod,ADXPrice,MODE_MINUSDI,shift);
if ((ADX_plus > ADX_minus)) SUM_UP++;
if ((ADX_plus < ADX_minus)) SUM_DOUN++;
double bulls=iBullsPower(NULL,TimeFrame,BULLSPeriod,BULLSPrice,shift);
if ((bulls > 0)) SUM_UP++;
if ((bulls < 0)) SUM_DOUN++;
double bears=iBearsPower(NULL,TimeFrame,BEARSPeriod,BEARSPrice,shift);
if ((bears > 0)) SUM_UP++;
if ((bears < 0)) SUM_DOUN++;
double stoch_m=iStochastic(NULL,TimeFrame,STOKPeriod,STODPeriod,STOSlowing,MODE_SMA,1,MODE_MAIN,shift);
double stoch_s=iStochastic(NULL,TimeFrame,STOKPeriod,STODPeriod,STOSlowing,MODE_SMA,1,MODE_SIGNAL,shift);
if (stoch_m >= stoch_s) SUM_UP++;
if (stoch_m < stoch_s) SUM_DOUN++;
double rsi=iRSI(NULL,TimeFrame,RSIPeriod,PRICE_CLOSE,shift);
if (rsi >= 50) SUM_UP++;
if (rsi < 50) SUM_DOUN++;
double fi=iForce(NULL,TimeFrame,FIPeriod,FIMethod,FIPrice,shift);
if (fi >= 0) SUM_UP++;
if (fi < 0) SUM_DOUN++;
double momentum=iMomentum(NULL,TimeFrame,MOMPeriod,MOMPrice,shift);
if (momentum >= 100) SUM_UP++;
if (momentum < 100) SUM_DOUN++;
double demarker_0=iDeMarker(NULL,TimeFrame,DEMPeriod,shift);
double demarker_1=iDeMarker(NULL,TimeFrame,DEMPeriod,shift+1);
if (demarker_0 >= demarker_1) SUM_UP++;
if (demarker_0 < demarker_1) SUM_DOUN++;
}
double v=100.0*SUM_UP/(SUM_UP+SUM_DOUN);
if(i==0)
{
string Trend_UP=DoubleToStr(v,0);
string Trend_DOWN=DoubleToStr((100.0-v),0);
ObjectSetText("Trend_UP_text","UP",10, "System", ForestGreen);
ObjectSetText("Trend_UP_value",Trend_UP+"%",10, "System", ForestGreen);
ObjectSetText("Trend_DOWN_text","DOWN",10, "System", Red);
ObjectSetText("Trend_DOWN_value",Trend_DOWN+"%",10, "System", Red);
}
v=v-50.0;
if(v>0) { UpForce_Buffer[i]=v; DnForce_Buffer[i]=0; }
else { UpForce_Buffer[i]=0; DnForce_Buffer[i]=v; }
}
return(0);
}
Comments