StochasticDiNapoli_v1
Download scriptThis tool is a specialized financial analysis indicator designed to help traders identify momentum and potential reversal points in the market. It functions by calculating the relative position of the current price compared to its recent historical highs and lows, providing a visual representation of whether an asset is currently overextended or becoming undervalued.
Core Mechanics
The logic operates by scanning a specific number of previous bars (determined by the "FastK" setting) to find the highest peak and the lowest valley within that timeframe. By measuring where the current closing price sits between those two extremes, the tool generates a percentage value. This tells you how "far" the price has traveled toward one end of its recent range.
Smoothing and Signal Generation
To ensure the data is readable and not overly erratic due to minor market fluctuations, the script applies two layers of mathematical smoothing:
- The Main Line (Stochastic): Instead of jumping abruptly with every price tick, this line moves gradually toward the current percentage value. It uses a "SlowK" factor to dampen sharp movements, creating a smoother trend line that is easier for a human observer to follow.
- The Signal Line: This is a secondary moving average calculated based on the Main Line itself. It acts as a confirmation tool. When the main line moves significantly away from this signal line, it often indicates a strengthening trend; when they cross each other, it can suggest a change in momentum.
Visual Interpretation
The indicator appears in a separate window at the bottom of your trading chart, bounded between 0 and 100. It features two distinct lines:
- The Main Trend: Shows the primary momentum.
- The Signal: Helps filter out "noise" to confirm if a trend is actually shifting.
By observing these two lines in relation to established horizontal levels (typically 30 and 70), users can visually identify periods where the market may be "overbought" (pushing too high) or "oversold" (dropping too low), providing a clearer picture of potential trading opportunities.
//+------------------------------------------------------------------+
//| StochasticDiNapoli.mq4 |
//| Copyright © 2006, TrendLaboratory Ltd. |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//| E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 30
#property indicator_level2 70
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Orange
//---- input parameters
extern int FastK=8;
extern int SlowK=3;
extern int SlowD=3;
//---- buffers
double StoBuffer[];
double SigBuffer[];
//double MdBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(0,StoBuffer);
SetIndexBuffer(1,SigBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="Stochastic DiNapoli("+FastK+","+SlowK+","+SlowD+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"Stoch");
SetIndexLabel(1,"Signal");
//----
SetIndexDrawBegin(0,FastK);
SetIndexDrawBegin(1,FastK);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Stochastic DiNapoli |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
double high,low;
//----
if(Bars<=FastK) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=FastK;i++)
{StoBuffer[Bars-i]=0.0;SigBuffer[Bars-i]=0.0;}
//----
i=Bars-FastK-1;
if(counted_bars>=FastK) i=Bars-counted_bars-1;
while(i>=0)
{
low=Low[Lowest(NULL,0,MODE_LOW,FastK,i)];
high=High[Highest(NULL,0,MODE_HIGH,FastK,i)];
double Fast=(Close[i]-low)/(high-low)*100;
StoBuffer[i]=StoBuffer[i+1]+(Fast-StoBuffer[i+1])/SlowK;
SigBuffer[i]=SigBuffer[i+1]+(StoBuffer[i]-SigBuffer[i+1])/SlowD;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments