Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Heiken_Ashi_Smoothed_v4
//+------------------------------------------------------------------+
//| Heiken_Ashi_Smoothed.mq4 |
//| Rewritten under build 600 of MetaTrader4 by RickD |
//| RickD, info@e2e-fx.com |
//+------------------------------------------------------------------+
#property copyright "© 2014 RickD"
#property link "info@e2e-fx.com"
#property version "1.00"
#property strict
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 clrRed
#property indicator_color2 clrDodgerBlue
#property indicator_color3 clrRed
#property indicator_color4 clrDodgerBlue
//---- parameters
input int MaMetod = 2;
input int MaPeriod = 6;
input int MaMetod2 = 3;
input int MaPeriod2 = 2;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void OnInit()
{
//---- indicators
IndicatorBuffers(8);
SetIndexStyle(0, DRAW_HISTOGRAM, 0, 1);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1, DRAW_HISTOGRAM, 0, 1);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexStyle(2, DRAW_HISTOGRAM, 0, 3);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3, DRAW_HISTOGRAM, 0, 3);
SetIndexBuffer(3, ExtMapBuffer4);
//----
SetIndexDrawBegin(0, MaPeriod+MaPeriod2);
SetIndexDrawBegin(1, MaPeriod+MaPeriod2);
SetIndexDrawBegin(2, MaPeriod+MaPeriod2);
SetIndexDrawBegin(3, MaPeriod+MaPeriod2);
//---- indicator buffers mapping
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexBuffer(3, ExtMapBuffer4);
SetIndexBuffer(4, ExtMapBuffer5);
SetIndexBuffer(5, ExtMapBuffer6);
SetIndexBuffer(6, ExtMapBuffer7);
SetIndexBuffer(7, ExtMapBuffer8);
}
void OnDeinit(const int reason)
{
}
int OnCalculate (const int rates_total, // size of input time series
const int prev_calculated, // bars handled in previous call
const datetime& time[], // Time
const double& open[], // Open
const double& high[], // High
const double& low[], // Low
const double& close[], // Close
const long& tick_volume[], // Tick Volume
const long& volume[], // Real Volume
const int& spread[]) // Spread
{
if (rates_total <= 10) return (0);
double maOpen, maClose, maLow, maHigh;
double haOpen, haHigh, haLow, haClose;
int limit = rates_total-prev_calculated;
if (prev_calculated > 0) limit++;
int pos = limit;
if (pos > rates_total-1) pos = rates_total-1;
int pos2 = pos;
while (pos >= 0)
{
maOpen = iMA(NULL, 0, MaPeriod, 0, MaMetod, PRICE_OPEN, pos);
maClose = iMA(NULL, 0, MaPeriod, 0, MaMetod, PRICE_CLOSE, pos);
maLow = iMA(NULL, 0, MaPeriod, 0, MaMetod, PRICE_LOW, pos);
maHigh = iMA(NULL, 0, MaPeriod, 0, MaMetod, PRICE_HIGH, pos);
//----
if (pos+1 < rates_total-1)
{
haOpen = (ExtMapBuffer5[pos+1] + ExtMapBuffer6[pos+1])/2;
}
else
{
haOpen = open[pos];
}
haClose = (maOpen + maHigh + maLow + maClose)/4;
haHigh = MathMax(maHigh, MathMax(haOpen, haClose));
haLow = MathMin(maLow, MathMin(haOpen, haClose));
if (haOpen < haClose)
{
ExtMapBuffer7[pos] = haLow;
ExtMapBuffer8[pos] = haHigh;
}
else
{
ExtMapBuffer7[pos] = haHigh;
ExtMapBuffer8[pos] = haLow;
}
ExtMapBuffer5[pos] = haOpen;
ExtMapBuffer6[pos] = haClose;
pos--;
}
for (int i=0; i<limit; i++)
{
ExtMapBuffer1[i] = iMAOnArray(ExtMapBuffer7, 0, MaPeriod2, 0, MaMetod2, i);
ExtMapBuffer2[i] = iMAOnArray(ExtMapBuffer8, 0, MaPeriod2, 0, MaMetod2, i);
ExtMapBuffer3[i] = iMAOnArray(ExtMapBuffer5, 0, MaPeriod2, 0, MaMetod2, i);
ExtMapBuffer4[i] = iMAOnArray(ExtMapBuffer6, 0, MaPeriod2, 0, MaMetod2, i);
}
//----
return (rates_total);
}
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
---