Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
zlMACDzRSI
//+------------------------------------------------------------------+
//| ZeroLag MACD.mq4 |
//| RD |
//| marynarz15@wp.pl |
//+------------------------------------------------------------------+
#property copyright "RD"
#property link "marynarz15@wp.pl"
//----
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_color3 DodgerBlue
//---- input parameters
extern int FastEMA = 14;
extern int SlowEMA = 28;
extern int SignalEMA = 11;
//----------------------------
extern int RSIPeriod=5;
extern double caliber=4.0; //need for RSI caliber
//---- buffers
double MACDBuffer[];
double SignalBuffer[];
double FastEMABuffer[];
double SlowEMABuffer[];
double SignalEMABuffer[];
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexBuffer(0, MACDBuffer);
SetIndexBuffer(1, SignalBuffer);
SetIndexBuffer(2, RSIBuffer);
SetIndexBuffer(3, PosBuffer);
SetIndexBuffer(4, NegBuffer);
SetIndexBuffer(5, FastEMABuffer);
SetIndexBuffer(6, SlowEMABuffer);
SetIndexBuffer(7, SignalEMABuffer);
//------------------------------------
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
SetIndexDrawBegin(0, SlowEMA);
SetIndexDrawBegin(1, SlowEMA);
IndicatorDigits(Digits+1);
//---------------------------------------------------------------------------------
IndicatorShortName("zlMACD-RSI(" + FastEMA + "," + SlowEMA + "," + SignalEMA + "),("+RSIPeriod+")");
// SetIndexLabel(0, "MACD");
SetIndexLabel(1, "Signal");
// SetIndexLabel(5,"RSI");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
double rel,negative,positive;
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
double EMA, ZeroLagEMAp, ZeroLagEMAq;
for(int i = 0; i < limit; i++)
{
FastEMABuffer[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
SlowEMABuffer[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
}
for(i = 0; i < limit; i++)
{
EMA = iMAOnArray(FastEMABuffer, Bars, FastEMA, 0, MODE_EMA, i);
ZeroLagEMAp = FastEMABuffer[i] + FastEMABuffer[i] - EMA;
EMA = iMAOnArray(SlowEMABuffer, Bars, SlowEMA, 0, MODE_EMA, i);
ZeroLagEMAq = SlowEMABuffer[i] + SlowEMABuffer[i] - EMA;
MACDBuffer[i] = ZeroLagEMAp - ZeroLagEMAq;
}
for(i = 0; i < limit; i++)
SignalEMABuffer[i] = iMAOnArray(MACDBuffer, Bars, SignalEMA, 0, MODE_EMA, i);
for(i = 0; i < limit; i++)
{
EMA = iMAOnArray(SignalEMABuffer, Bars, SignalEMA, 0, MODE_EMA, i);
SignalBuffer[i] = SignalEMABuffer[i] + SignalEMABuffer[i] - EMA;
}
// return(0);
//}
//+------------------------------------------------------------------+
//=============================================================== RSI =
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=MACDBuffer[k]-MACDBuffer[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=MACDBuffer[i]-MACDBuffer[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;
}
PosBuffer[i]=positive;
NegBuffer[i]=negative;
if(negative==0.0) RSIBuffer[i]=0.0;
else RSIBuffer[i]=caliber*Point*(50.0-100.0/(1+positive/negative) );
i--;
}
return(0);
}
//+------------------------------------------------------------------+
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
---