LeManStop
Download scriptThis tool is designed to provide traders with a dynamic, visual guide for identifying potential "stop" levels on a price chart. Rather than using a static number, the script calculates a moving boundary based on current market momentum and historical price volatility.
Core Logic and Mechanics
The indicator operates by analyzing two primary components of the market: trend direction and price range.
1. Trend Detection The script begins by comparing two different types of Moving Averages (fast and slow). By measuring the distance between these two averages, the tool determines the overall "flow" of the market.
- If the fast average is above the slow average, the tool identifies an upward trend.
- If the fast average is below the slow average, it identifies a downward trend.
2. Volatility and Range Calculation To determine where to place the "stop" line, the script looks back at a specific number of previous price bars (a user-defined period).
- In an uptrend, it calculates the distance between the opening prices and the lowest points reached during that period. This helps measure how much "room" the market has moved downward recently.
- In a downtrend, it measures the distance between the opening prices and the highest points reached. This identifies the upward "stretch" of the price action.
3. The Calculation Formula The script takes the average of these historical price ranges and multiplies them by a coefficient (a multiplier). It then applies this value to the current price to project a line. This creates a buffer that adjusts automatically: if the market becomes more volatile, the line reacts accordingly; if the market calms down, the line tightens.
4. The "Ratchet" Effect (Trend Protection) One of the key features of this logic is its consistency. To prevent the stop level from moving in a way that would invalidate a trade prematurely, the script includes a comparison rule:
- In an uptrend, the calculated stop line is prevented from moving downward. It can only move up or stay flat.
- In a downtrend, the calculated stop line is prevented from moving upward. It can only move down or stay flat.
Summary for the User
Essentially, this script acts as a "smart trailing" mechanism. It automatically tracks the market's path, measuring out a safety zone based on recent price swings. By ensuring that the protective level never moves backward against your trade direction, it helps traders visualize where a trend might be considered exhausted or reversed, providing a more reactive and organic boundary than a standard fixed line.
//+------------------------------------------------------------------+
//| LeManStop.mq4 |
//| Copyright © 2009, LeMan. |
//| b-market@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, LeMan."
#property link "b-market@mail.ru"
//----
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 1
#property indicator_style1 2
//----
extern int per = 24;
extern int coef = 4;
extern int fastEMA = 9;
extern int slowEMA = 18;
//----
double ExtBuffer[];
//+------------------------------------------------------------------+
int init() {
//----
SetIndexBuffer(0,ExtBuffer);
SetIndexStyle(0,DRAW_LINE);
//----
return(0);
}
//+------------------------------------------------------------------+
int start() {
//----
double Stop = 0;
int counted_bars = IndicatorCounted();
int limit = Bars-per-3;
//----
for (int shift = limit; shift >= 0; shift--) {
double EMA0 = iMA(Symbol(),0,fastEMA,0,MODE_EMA,0,shift)-iMA(Symbol(),0,slowEMA,0,MODE_EMA,0,shift);
double EMA1 = iMA(Symbol(),0,fastEMA,0,MODE_EMA,0,shift+1)-iMA(Symbol(),0,slowEMA,0,MODE_EMA,0,shift+1);
double PreStop = ExtBuffer[shift+1];
double x = 0;
double Counter = 0;
if (EMA0 > 0) {
for (int value1 = 0; value1 <= per; value1++) {
x = Open[shift+value1]-Low[shift+value1]+x;
Counter++;
}
if (Counter != 0) {
Stop = Open[shift]-(coef*(x/Counter));
} else {
Stop = Open[shift]-(coef*x);
}
if ((Stop < PreStop) && (EMA1 > 0)) {
Stop = PreStop;
}
}
if (EMA0 < 0) {
for (value1 = 0; value1 <= per; value1++) {
x = High[shift+value1]-Open[shift+value1]+x;
Counter++;
}
if (Counter != 0) {
Stop = Open[shift+1]+(coef*(x/Counter));
} else {
Stop = Open[shift+1]+(coef*x);
}
if ((Stop > PreStop) && (EMA1 < 0)) {
Stop = PreStop;
}
}
PreStop = Stop;
ExtBuffer[shift] = Stop;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments