StopReversalv2
Download scriptThis script is designed as a visual analysis tool for the MetaTrader 4 platform, specifically intended to help traders identify potential price reversals. By monitoring the movement of market prices across different time frames, it establishes dynamic support and resistance levels based on the momentum of recent price action.
Core Logic Overview
The primary objective of this script is to track a "Stop Level"—a theoretical price point that represents a pivot or a boundary. The logic calculates this level by observing how current prices interact with previous price movements. It essentially looks for moments where the market's direction changes or exhausts itself, marking those areas as significant zones where the price might turn around.
How the Price Level is Determined
The script evaluates the relationship between the current closing price and the previous price point using several logic gates:
- Trend Continuation: If the price continues to move in the same direction it was previously heading, the script adjusts the Stop Level slightly relative to the current price. This keeps the boundary "active" as the market moves.
- Directional Shifts: When the price shows signs of pushing against a previous level or moving into new territory, the script recalculates the Stop Level to accommodate the new range.
- Dynamic Adjustments: The calculation includes a specific sensitivity factor (measured in pips). This ensures that the Stop Level isn't just a static line but reacts fluidly to the immediate volatility of the candles.
Identification of Signals
Once these dynamic levels are established, the script looks for specific "breakout and reversal" patterns to provide visual cues on the chart:
- Buy Opportunities: The logic identifies a potential upward reversal when the current price closes above a previously established Stop Level, following a period where the previous movement was downward.
- Sell Opportunities: Conversely, it identifies a potential downward reversal when the price closes below a Stop Level after coming from an upward move.
Visual Representation
To make this data actionable for a human trader:
- The script plots visual markers (arrows) on the chart to highlight these specific reversal points.
- It draws a dotted line to represent the evolving Stop Level, allowing the user to see how the "boundary" is moving in real-time alongside the market price.
In summary, this tool automates the tedious process of tracking price boundaries and alerts the user when the market demonstrates a clear shift in momentum, signaling a potential transition from one trend to another.
//+------------------------------------------------------------------
//| Stopreversal Mt4.mq4
//|
//|
//| Conversion only Dr. Gaines
//| dr_richard_gaines@yahoo.com
//|
//+------------------------------------------------------------------
#property copyright " Dominic."
#property link " http://www.metaquotes.net/"
#property indicator_chart_window
#include <stdlib.mqh>
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2
#property indicator_color3 Magenta
#property indicator_width3 1
//+------------------------------------------------------------------
//| Common External variables
//+------------------------------------------------------------------
//+------------------------------------------------------------------
//| External variables
//+------------------------------------------------------------------
extern double nPips = 0.004;
//+------------------------------------------------------------------
//| Special Convertion Functions
//+------------------------------------------------------------------
int LastTradeTime;
double ExtHistoBuffer[];
double ExtHistoBuffer2[];
int up=0,dn=0;
double LBuffer[];
double SBuffer[];
void SetLoopCount(int loops)
{
}
void SetIndexValue(int shift, double value)
{
ExtHistoBuffer[shift] = value;
}
void SetIndexValue2(int shift, double value)
{
ExtHistoBuffer2[shift] = value;
}
//+------------------------------------------------------------------
//| End
//+------------------------------------------------------------------
//+------------------------------------------------------------------
//| Initialization
//+------------------------------------------------------------------
int init()
{
SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
SetIndexArrow(0, 233);
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
SetIndexArrow(1, 234);
SetIndexBuffer(0, ExtHistoBuffer);
SetIndexBuffer(1, ExtHistoBuffer2);
SetIndexBuffer(2, LBuffer);
SetIndexStyle(2, DRAW_LINE, STYLE_DOT);
return(0);
}
int start()
{
//+------------------------------------------------------------------
//| Local variables
//+------------------------------------------------------------------
int shift = 0;
double cnt = 0;
double TrStopLevel = 0;
double PREV = 0;
double pass = 0;
SetLoopCount(0);
// loop from first bar to current bar (with shift=0)
for(shift=Bars-2;shift>=0 ;shift--){
if( (Close[shift] == PREV) )
{
TrStopLevel=PREV;
}
else
{
if( (Close[shift+1])<PREV && (Close[shift]<PREV) )
{
TrStopLevel=MathMin(PREV,Close[shift]*(1+nPips));
}
else
{
if( ((Close[shift+1])>PREV) && (Close[shift]>PREV) )
{
TrStopLevel=MathMax(PREV,Close[shift]*(1-nPips));
}
else
{
if( (Close[shift]>PREV) )
{
TrStopLevel=Close[shift]*(1-nPips);
}
else TrStopLevel=Close[shift]*(1+nPips);
}
}
}
LBuffer[shift]=TrStopLevel;
if( Close[shift] > TrStopLevel && Close[shift+1]<PREV && PREV != 0 )
{
SetIndexValue(shift, TrStopLevel);
//SetOrder(OP_BUY,1,ask,2,0,ask+TakeProfit*Point,blue);
}
if( Close[shift] < TrStopLevel && Close[shift+1]>PREV && PREV != 0 )
{
//SetOrder(OP_SELL,1,bid,2,0,bid-TakeProfit*Point,Red);
SetIndexValue2(shift, TrStopLevel);
//Alert("Sell");
}
PREV=TrStopLevel;
//Alert(TrStopLevel);
}
return(0);
}
//+------------------------------------------------------------------+
Comments