StochasticOnChart
Download scriptThis technical indicator is designed to provide traders with a visual representation of market momentum and trend direction by combining two primary financial tools: the Stochastic Oscillator and a Moving Average (MA).
Instead of showing these two tools separately, the script merges them into a single, cohesive visual signal on your chart. Here is a breakdown of how the logic works:
Core Visual Logic
The tool functions by taking a standard Moving Average (which tracks the general trend of the price) and adjusting its position based on the "overbought" or "oversold" status of the Stochastic Oscillator.
- Trend Baseline: The script calculates an Exponential Moving Average (EMA). This acts as the foundation for the indicator, showing you the primary direction of the market.
- Momentum Adjustment: It then looks at the Stochastic Oscillator—a tool that measures where the current price is relative to its recent range. If the oscillator is high (indicating momentum), it pulls the signal line in one direction; if it is low, it pulls it in the opposite direction.
- Visual Levels: The script can display three distinct lines on your chart:
- An Upper Level (+30 units)
- A Median Level (The Baseline)
- A Lower Level (-30 units) These levels provide a clear corridor to see how far the current price is deviating from the average.
Signal Generation (Extremums)
One of the most prominent features of this script is its ability to automatically identify potential "turning points" or reversals in the market.
The logic scans the historical data for specific patterns in the Stochastic Oscillator's movement:
- Bullish Signals: When the indicator detects a specific "V-shaped" reversal pattern (where the current price begins to rise while previous prices were lower), it places a Lime Green arrow at the bottom of the candle.
- Bearish Signals: Conversely, when it detects a "mountain-shaped" reversal (where the price begins to drop after a peak), it places a Red arrow at the top of the candle.
Summary for the Trader
Essentially, this tool simplifies your analysis by doing three things at once:
- It identifies the primary trend using a Moving Average.
- It shows you the strength of momentum by "warping" that average based on Stochastic values.
- It highlights potential entry or exit points by automatically placing colored arrows on the chart when specific price exhaustion patterns occur.
#property copyright "Dmitry Yakovlev, Russia,Omsk WM R865705290089"
#property link "http://fehu.nxt.ru/ dmitryyakv@yandex.ru"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 RoyalBlue
#property indicator_width1 2
#property indicator_color2 RoyalBlue
#property indicator_width2 1
#property indicator_color3 RoyalBlue
#property indicator_width3 1
#property indicator_color4 RoyalBlue
#property indicator_width4 1
#import "shell32.dll" //Connect a dll (provided with Windows)
int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);
#import "user32.dll"
int MessageBoxA(int hWnd ,string lpText,string lpCaption,int uType);
//------------------------------------------------------------------------------------------------------
//---- input parameters
extern int KPeriod=5;
extern int DPeriod=3;
extern int Slowing=3;
extern int MA=50;
extern int Scale=100;
extern int ShowLevels=1;
extern int ShowExtremums=1;
extern string _donate1="Äëÿ \"ñïàñèáî\" :-)";
extern string _donate2="R865705290089";
extern string _advert="Íàïèøó íà çàêàç,ïåðåäåëàþ.";
//---- buffers
double Signal[];
double Buffer1[];
double Buffer0[];
double Buffer5[];
double Stoch[];
//----
int draw_begin1=0;
int draw_begin2=0;
int _KPeriod=0;
int lblcnt=15;
int init()
{
int i;
string short_name;
_KPeriod=KPeriod;
string tmp;
for(int k=0;k<lblcnt;k++)
{
tmp="myStochSignal"+_KPeriod+"_"+k;
ObjectDelete(tmp);
}
CheckDonate();
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0, Signal);
if(ShowLevels==1)
{
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1, Buffer1);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2, Buffer5);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3, Buffer0);
}
else
for(i=1;i<=3;i++) SetIndexStyle(i,DRAW_NONE);
for(i=4;i<=7;i++) SetIndexStyle(i,DRAW_NONE);
//---- name for DataWindow and indicator subwindow label
short_name="Sto("+KPeriod+","+DPeriod+","+Slowing+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexLabel(1,"80%");
SetIndexLabel(2,"50%");
SetIndexLabel(3,"20%");
//----
draw_begin1=_KPeriod+Slowing;
draw_begin2=draw_begin1+DPeriod;
SetIndexDrawBegin(0,draw_begin1);
SetIndexDrawBegin(1,draw_begin1);
SetIndexDrawBegin(2,draw_begin1);
SetIndexDrawBegin(3,draw_begin1);
//----
ArraySetAsSeries(Stoch,true);
return(0);
}
void deinit()
{
string tmp;
for(int k=0;k<lblcnt;k++)
{
tmp="myStochSignal"+_KPeriod+"_"+k;
ObjectDelete(tmp);
}
}
//+------------------------------------------------------------------+
//| Stochastic oscillator |
//+------------------------------------------------------------------+
int start()
{
int i,k;
int counted_bars=IndicatorCounted();
double price;
//----
if(Bars<=draw_begin2) return(0);
if(ArraySize(Stoch)!=Bars) ArrayResize(Stoch,Bars);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=draw_begin2;i++)
{
Signal[Bars-i]=0;
Buffer0[Bars-i]=0;
Buffer1[Bars-i]=0;
Buffer5[Bars-i]=0;
Stoch[Bars-i]=0;
}
double kk=Point*Scale/100;
int limit=Bars-counted_bars;
for(i=0; i<limit; i++)
{
Stoch[i]=iStochastic(Symbol(),0,_KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_SIGNAL,i);
Signal[i]=iMA(Symbol(),0,MA,0,MODE_EMA,PRICE_MEDIAN,i)+(Stoch[i]-50)*kk;
if(ShowLevels==1)
{
Buffer1[i]=iMA(Symbol(),0,MA,0,MODE_EMA,PRICE_MEDIAN,i)+30*kk;
Buffer5[i]=iMA(Symbol(),0,MA,0,MODE_EMA,PRICE_MEDIAN,i);
Buffer0[i]=iMA(Symbol(),0,MA,0,MODE_EMA,PRICE_MEDIAN,i)-30*kk;
}
}
//<-signal
if(ShowExtremums==1)
{
int st;
double st0,st1,st2,st3,st4;
i=0;k=0;
while(k<lblcnt && i<Bars/*-counted_bars*/)
{
st=0;
while(i<Bars/*-counted_bars*/ && st==0)
{
st0=iStochastic(Symbol(),0,_KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_SIGNAL,i+0);
st1=iStochastic(Symbol(),0,_KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_SIGNAL,i+1);
st2=iStochastic(Symbol(),0,_KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_SIGNAL,i+2);
st3=iStochastic(Symbol(),0,_KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_SIGNAL,i+3);
//st4=iStochastic(Symbol(),0,_KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_SIGNAL,i+4);
if(st0>st1 && st2>st1 && st3>st2/* && st4>st2*/) st=+1;
if(st0<st1 && st2<st1 && st3<st2/* && st4<st2*/) st=-1;
if(st!=0) break;
i++;
}
string tmp="myStochSignal"+_KPeriod+"_"+k;
ObjectDelete(tmp);
if(st==+1)
{
ObjectCreate(tmp,OBJ_ARROW,0,Time[i],Low[i]);
ObjectSet(tmp,OBJPROP_ARROWCODE,108);
ObjectSet(tmp,OBJPROP_COLOR,Lime);
k++;
}
if(st==-1)
{
ObjectCreate(tmp,OBJ_ARROW,0,Time[i],High[i]+(WindowPriceMax()-WindowPriceMin())/10);
ObjectSet(tmp,OBJPROP_ARROWCODE,108);
ObjectSet(tmp,OBJPROP_COLOR,Red);
k++;
}
i+=1;
}
}
//->
return(0);
}
void CheckDonate()
{
int fd=0; string pay="0"; datetime dt=0;
string fn="StochOC.txt";
fd=FileOpen(fn,FILE_READ|FILE_CSV,";");
if(fd>=1)
{
pay=FileReadString(fd); if(pay!="0" && pay!="1") pay="0";
dt=StrToTime(FileReadString(fd));
}
else
{
dt=TimeCurrent();
fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
FileWrite(fd,"0",TimeToStr(dt,TIME_DATE));
}
FileClose(fd);
if(pay=="0" && (TimeCurrent()-dt)>10*24*60*60) // 5 äíåé
{
if(MessageBoxA(0,"Åñëè Âàì ïîíðàâèëñÿ èíäèêàòîð On Chart Stochastic,\n õîòèòå ïîìî÷ü àâòîðó ìàòåðèàëüíî?","Âîïðîñ",4)==6)
{
ShellExecuteA(0,"Open","iexplore.exe","wmk:payto?Purse=R865705290089&Amount=100&Desc=Indicator&BringToFront=Y&ExecEvenKeeperIsOffline=Y","",7);
pay="1";
}
dt=TimeCurrent();
fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
FileWrite(fd,pay,TimeToStr(dt,TIME_DATE));
FileClose(fd);
}
FileClose(fd);
}
Comments