This script is a technical analysis tool designed to identify and visualize market trends on a trading chart. It functions by analyzing price movements relative to moving averages to determine the current "momentum" of the market, providing traders with a clear visual representation of whether the trend is currently bullish (upward) or bearish (downward).
Core Logic and Functionality
1. Trend Identification The tool constantly monitors the relationship between the current closing price and two specific moving averages based on the high and low prices of the market. By comparing these values, the script classifies the market into a state of positive momentum (upward trend) or negative momentum (downward trend).
2. Dynamic Channel Mapping Once the trend is identified, the script draws a dynamic "channel" on the chart:
- In an Upward Trend: It calculates a boundary based on the lower price extremes to show the support level.
- In a Downward Trend: It shifts focus to the higher price extremes to highlight the resistance level. This creates a visual corridor that adjusts automatically as the market fluctuates, helping users see the "path" the price is currently following.
3. Visual Signals and Cues To make the data more actionable, the script includes an optional visual signaling system:
- Trend Arrows: If enabled in the settings, the tool can place specific markers on the chart at the exact moment the momentum shifts from down to up (or vice versa). These markers are positioned with a calculated buffer to ensure they are clearly visible and not overlapping with the price candles.
- Color Coding: The script uses distinct colors to differentiate between the various trend lines, allowing for quick identification of market structure at a glance.
4. Real-Time Notifications The tool is equipped with a notification system to alert traders immediately when a trend reversal occurs. Users can customize these alerts based on their preference, including:
- Pop-up Alerts: On-screen messages notifying of a trend change.
- Email Notifications: Sending an automated summary to a connected email account.
- Audio Cues: Playing a specific sound file when the market switches direction.
Summary for the User
Essentially, this script acts as a "trend tracker." It filters out market noise by focusing on price extremes and highlights whether the current movement is healthy enough to be considered an uptrend or a downtrend. It provides a visual channel for the price to follow and proactively alerts you the moment that trend flips, allowing for quicker reactions to market changes.
//+------------------------------------------------------------------+
//| SSL channel chart.mq4 |
//| mladen |
//| |
//| initial SSL for metatrader developed by Kalenzo |
//+------------------------------------------------------------------+
#property copyright "copyleft mladen"
#property link "mladenfx@gmail.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 OrangeRed
#property indicator_color4 Lime
#property indicator_width1 2
#property indicator_width2 2
//
//
//
//
//
extern int Lb = 10;
extern bool alertsOn = false;
extern bool alertsMessage = true;
extern bool alertsSound = false;
extern bool alertsEmail = false;
extern bool showArrows = false;
double ssld[];
double sslu[];
double sslad[];
double sslau[];
double Hlv[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
IndicatorBuffers(5);
SetIndexBuffer(0,ssld); SetIndexDrawBegin(0,Lb+1);
SetIndexBuffer(1,sslu); SetIndexDrawBegin(0,Lb+1);
SetIndexBuffer(2,sslad); SetIndexDrawBegin(0,Lb+1); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,234);
SetIndexBuffer(3,sslau); SetIndexDrawBegin(0,Lb+1); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,233);
SetIndexBuffer(4,Hlv);
return(0);
}
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//
//
//
//
//
for(i=limit;i>=0;i--)
{
Hlv[i] = Hlv[i+1];
if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1)) Hlv[i] = 1;
if(Close[i]<iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1)) Hlv[i] = -1;
if(Hlv[i] == -1)
{
ssld[i] = iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1);
sslu[i] = iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW ,i+1);
}
else
{
ssld[i] = iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW ,i+1);
sslu[i] = iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1);
}
//
//
//
//
//
sslau[i] = EMPTY_VALUE;
sslad[i] = EMPTY_VALUE;
if (showArrows)
{
if (Hlv[i]!=Hlv[i+1])
if (Hlv[i]==1)
sslau[i] = ssld[i]-iATR(NULL,0,15,i)/2.0;
else sslad[i] = ssld[i]+iATR(NULL,0,15,i)/2.0;
}
}
//
//
//
//
//
if (alertsOn)
if (Hlv[0] != Hlv[1])
if (Hlv[0] == 1)
doAlert("up");
else doAlert("down");
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
void doAlert(string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;
if (previousAlert != doWhat || previousTime != Time[0]) {
previousAlert = doWhat;
previousTime = Time[0];
//
//
//
//
//
message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," SSL trend changed to ",doWhat);
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol(),"SSL "),message);
if (alertsSound) PlaySound("alert2.wav");
}
}
Comments