Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Stochastic_5M+15M
//+------------------------------------------------------------------+
//| Stochastic_5M+15M.mq4 |
//| Zen_Leow |
//| |
//+------------------------------------------------------------------+
#property copyright "Zen_Leow"
#property link ""
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Yellow
#property indicator_width1 1
#property indicator_width2 1
#property indicator_level1 80
#property indicator_level2 20
extern string _ = "Stochastic Inputs";
extern int Timeframe1 = PERIOD_M5;
extern int K_Period1 = 14;
extern int D_Period1 = 1;
extern int Slowing1 = 1;
extern string PriceField_Setting1 = "0 - Low/High or 1 - Close/Close";
extern int PriceField1 = 0;
extern string MA_Method_Setting1 = "0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA";
extern int MA_Method1 = 0;
extern int Timeframe2 = PERIOD_M15;
extern int K_Period2 = 14;
extern int D_Period2 = 3;
extern int Slowing2 = 3;
extern string PriceField_Setting2 = "0 - Low/High or 1 - Close/Close";
extern int PriceField2 = 0;
extern string MA_Method_Setting2 = "0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA";
extern int MA_Method2 = 0;
extern bool AudioAlertActive = true;
int ArrowCode = 251; // This is the wingdings code for the TF15 Stochastic symbol
int ArrowDist = 10;
double TF1Buffer[];
double TF2Buffer[];
double UpBuffer[];
double DownBuffer[];
double LastClosed15MStoch;
datetime TimeOfCrossConfirmation;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(4);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2, TF1Buffer);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,ArrowCode);
SetIndexBuffer(3, TF2Buffer);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexBuffer(0, UpBuffer);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(1, DownBuffer);
//---- name for DataWindow and indicator subwindow label
string short_name="Stoch_5M+15M("+K_Period1+","+D_Period1+","+Slowing1+"--"+K_Period2+","+D_Period2+","+Slowing2+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"5M_Stoch");
SetIndexLabel(1,"15M_Stoch");
//---- Set Start point of drawing
int draw_begin1=K_Period1+Slowing1;
int draw_begin2=K_Period2+Slowing2;
SetIndexDrawBegin(2,draw_begin1);
SetIndexDrawBegin(3,draw_begin1);
SetIndexDrawBegin(0,draw_begin1);
SetIndexDrawBegin(1,draw_begin2);
//----
// Alert("Done");
LastClosed15MStoch = EMPTY_VALUE;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
PlotTimeFrame2Graph();
PlotTimeFrame1Graph();
PlotTimeFrame2Graph();
if (Time[0] > TimeOfCrossConfirmation && AudioAlertActive)
{
CheckForAlerts();
}
return(0);
}
double GetStochasticValueTF1(int index)
{
return (iStochastic( Symbol(), Timeframe1, K_Period1, D_Period1, Slowing1, MA_Method1, PriceField1, 0, index));
}
double GetStochasticValueTF2(int index)
{
return (iStochastic( Symbol(), Timeframe2, K_Period2, D_Period2, Slowing2, MA_Method2, PriceField2, 0, index));
}
// Draw the 15M Stochastic
// For this I count from bar 0 onwards.
void PlotTimeFrame2Graph()
{
int i=0; // Bar index
int x=0; // Timeframe2 index
int Counted_bars; // Number of counted bars
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
while(i<=Bars-Counted_bars-1) // Loop for uncounted bars
{
if (MathMod(TimeMinute(Time[i]),Timeframe2)==0)
{
TF2Buffer[i]=GetStochasticValueTF2(x);
x++;
}
else
{
TF2Buffer[i]=EMPTY_VALUE;
}
i++; // Calculating index of the next bar
}
}
// Draws 5M Stochastic and Up down arrows when cross occurs
void PlotTimeFrame1Graph()
{
int i; // Bar index
int Counted_bars; // Number of counted bars
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
TF1Buffer[i]=GetStochasticValueTF1(i);
if (TF2Buffer[i+1]!=EMPTY_VALUE)
{
LastClosed15MStoch = TF2Buffer[i+1];
}
if (TF1Buffer[i+1] > LastClosed15MStoch)
{
if (TF1Buffer[i+2] < LastClosed15MStoch)
{
UpBuffer[i+1] = TF1Buffer[i+1] - ArrowDist;
if (UpBuffer[i+1] > 100)
{
UpBuffer[i+1] = 100;
}
if (UpBuffer[i+1] < 0)
{
UpBuffer[i+1] = 0;
}
}
else
{
UpBuffer[i+1] = EMPTY_VALUE;
}
}
else
{
UpBuffer[i+1] = EMPTY_VALUE;
}
if (TF1Buffer[i+1] < LastClosed15MStoch)
{
if (TF1Buffer[i+2] > LastClosed15MStoch)
{
DownBuffer[i+1] = TF1Buffer[i+1] + ArrowDist;
if (DownBuffer[i+1] > 100)
{
DownBuffer[i+1] = 100;
}
if (DownBuffer[i+1] < 0)
{
DownBuffer[i+1] = 0;
}
}
else
{
DownBuffer[i+1] = EMPTY_VALUE;
}
}
else
{
DownBuffer[i+1] = EMPTY_VALUE;
}
i--; // Calculating index of the next bar
}
}
// Codes here for the alert are independent from the visual indicator.
void CheckForAlerts()
{
if(GetStochasticValueTF1(1) > GetStochasticValueTF2(1))
{
if(GetStochasticValueTF1(2) < GetStochasticValueTF2(1)) // Confirmed there was a cross
{
TimeOfCrossConfirmation = TimeCurrent();
Alert("5M Stoch has crossed ABOVE 15M Stoch!!!");
}
}
if(GetStochasticValueTF1(1) < GetStochasticValueTF2(1))
{
if(GetStochasticValueTF1(2) > GetStochasticValueTF2(1)) // Confirmed there was a cross
{
TimeOfCrossConfirmation = TimeCurrent();
Alert("5M Stoch has crossed BELOW 15M Stoch!!!");
}
}
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---