DayTrend-T01
Download scriptThis script is designed as a technical analysis tool for the MetaTrader platform, specifically intended to identify and visualize market trends by calculating momentum and price extremes. It operates in a separate window rather than directly on the price chart, allowing traders to observe trend movements independently of price fluctuations.
Core Logic and Functionality
Trend Analysis & Smoothing The script focuses on identifying the underlying direction of the market. It calculates the "trend" by comparing current closing prices against historical values over a specific timeframe. To ensure that minor price "noise" doesn't trigger false signals, it uses a multi-stage smoothing process. By passing the trend data through several consecutive layers of calculation (weighted averages), it filters out erratic movements to reveal a smoother, more stable representation of the market's trajectory.
The Momentum Oscillator Once the smoothed trend is established, the script calculates a specialized momentum value. This value acts as an oscillator that measures the strength and direction of the movement:
- Positive Values: Indicate upward momentum.
- Negative Values: Indicate downward momentum.
This calculation provides a visual representation of how aggressively the price is moving in a specific direction at any given moment.
Dynamic Level Indicators The tool provides two distinct visual components to help with trade planning:
- Momentum Signal (Primary Line): The script plots a main line (in Gold) that reflects the calculated momentum. Traders can use this to see if the market is accelerating, decelerating, or reversing.
- Trigger Levels: It uses specific threshold parameters (positive and negative limits). When the momentum exceeds these levels, it effectively "triggers" a state change, helping traders identify overbought or oversold conditions relative to the current trend.
Price Extreme Tracking In addition to the momentum oscillator, the script performs an automated search of historical price data within a rolling window. It identifies:
- The highest high reached during that period.
- The lowest low reached during that period.
- A calculated "Mid-Level" based on these extremes.
The script then projects this Mid-Level as a horizontal reference line on your chart. This allows you to see the "equilibrium" point of the recent price action, providing a clear visual boundary for potential support and resistance.
Summary for the User
Essentially, this tool acts as a trend-smoothing engine. It takes raw, jagged price data and converts it into a smooth momentum indicator while simultaneously identifying key historical highs and lows to draw a "fair value" line on your chart. It is designed to help you stay aligned with the prevailing market direction while providing clear visual cues for when that momentum might be reaching an extreme point.
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| DayTrend-T01.mq4 |
//| |
//| |
//| Converted by Mql2Mq4 v1.0 |
//| http://yousky.free.fr |
//| Copyright © 2006, Yousky Soft |
//+------------------------------------------------------------------+
#property copyright " Author := Copyright © 2006, HomeSoft-Tartan Corp."
#property link " spiky@transkeino.ru"
#property indicator_separate_window
#property indicator_color1 Gold
#property indicator_buffers 2
#property indicator_color2 Red
//+------------------------------------------------------------------+
//| Common External variables |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| External variables |
//+------------------------------------------------------------------+
extern double t3_period = 14;
extern double b = 0.7;
extern double ppor = 50;
extern double mpor = -50;
extern double mBar = 300;
extern double sm = 6;
//+------------------------------------------------------------------+
//| Special Convertion Functions |
//+------------------------------------------------------------------+
int LastTradeTime;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];
void SetLoopCount(int loops)
{
}
void SetIndexValue(int shift, double value)
{
ExtHistoBuffer[shift] = value;
}
void SetIndexValue2(int shift, double value)
{
ExtHistoBuffer2[shift] = value;
}
bool MoveObject(string name, int type, datetime Atime, double Aprice, datetime Atime2 = 0, double Aprice2 = 0, color Acolor = CLR_NONE, int Aweight = 0, int Astyle = 0)
{
if (ObjectFind(name) != -1)
{
int OType = ObjectType(name);
if ((OType == OBJ_VLINE) ||
(OType == OBJ_HLINE) ||
(OType == OBJ_TRENDBYANGLE) ||
(OType == OBJ_TEXT) ||
(OType == OBJ_ARROW) ||
(OType == OBJ_LABEL))
{
return(ObjectMove(name, 0, Atime, Aprice));
}
if ((OType == OBJ_GANNLINE) ||
(OType == OBJ_GANNFAN) ||
(OType == OBJ_GANNGRID) ||
(OType == OBJ_FIBO) ||
(OType == OBJ_FIBOTIMES) ||
(OType == OBJ_FIBOFAN) ||
(OType == OBJ_FIBOARC) ||
(OType == OBJ_RECTANGLE) ||
(OType == OBJ_ELLIPSE) ||
(OType == OBJ_CYCLES) ||
(OType == OBJ_TREND) ||
(OType == OBJ_STDDEVCHANNEL) ||
(OType == OBJ_REGRESSION))
{
return(ObjectMove(name, 0, Atime, Aprice) && ObjectMove(name, 1, Atime2, Aprice2));
}
}
else
{
return(ObjectCreate(name, type, 0, Atime, Aprice, Atime2, Aprice2, 0, 0) && ObjectSet(name, OBJPROP_COLOR, Acolor));
}
}
//+------------------------------------------------------------------+
//| End |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Initialization |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(1, ExtHistoBuffer2);
return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables |
//+------------------------------------------------------------------+
double e1 = 0;
double e2 = 0;
double e3 = 0;
double e4 = 0;
double e5 = 0;
double e6 = 0;
double c1 = 0;
double c2 = 0;
double c3 = 0;
double c4 = 0;
double n = 0;
double w1 = 0;
double w2 = 0;
double b2 = 0;
double b3 = 0;
int shift = 0;
int cnt = 0;
double per = 0;
double trend = 0;
double top = 0;
double oldtop = 0;
double MaxH = 0;
double MinL = 0;
double MidL = 0;
double trig = 0;
double t3 = 0;
bool ft = true;
//-----------------------------
if( ft ) {
b2=b*b;
b3=b2*b;
c1=-b3;
c2=(3*(b2+b3));
c3=-3*(2*b2+b+b3);
c4=(1+3*b+b3+3*b2);
n=t3_period;
if( n<1 ) n=1;
n = 1 + 0.5*(n-1);
w1 = 2 / (n + 1);
w2 = 1 - w1;ft=false;}
SetLoopCount(0);
// loop from first bar to current bar (with shift=0)
for(shift=Bars-1;shift>=0 ;shift--){ SetIndexValue(shift, 0);SetIndexValue2(shift, 0);}
per=24*60/Period();
for(shift=mBar ;shift>=0 ;shift--){
MaxH=0;MinL=1000;trend=0;
for(cnt=shift+sm;cnt<=shift+per+sm ;cnt++){
if( MaxH<High[cnt] ) MaxH=High[cnt];
if( MinL>Low[cnt] ) MinL=Low[cnt];oldtop=Close[cnt];}
top=Close[shift];MidL=MathRound(((MaxH-MinL)/Point)/2);
trend=MathRound((top-oldtop)/Point);
e1 = w1*trend + w2*e1;
e2 = w1*e1 + w2*e2;
e3 = w1*e2 + w2*e3;
e4 = w1*e3 + w2*e4;
e5 = w1*e4 + w2*e5;
e6 = w1*e5 + w2*e6;
t3 = c1*e6 + c2*e5 + c3*e4 + c4*e3;
if( t3 == 0 ) t3=0.0001;
SetIndexValue(shift,t3);
if( t3 == 0 ) trend=0.00001;
if( t3>0 ) trig=ppor;
if( t3<0 ) trig=mpor;
SetIndexValue2(shift,trig);
if( shift == 0 ) MoveObject("MIDL",OBJ_HLINE,Time[30],MidL,Time[0],MidL,Gold,1,STYLE_DOT);} return(0);
}
Comments