//+------------------------------------------------------------------+
//| VIP_HeikenAshi.mq4 |
//| Copyright © 2010, KingLion |
//| http://www.metastock.org.ua/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, KingLion"
#property link "http://www.metastock.org.ua/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
#property indicator_width1 2
#property indicator_width2 2
#property indicator_minimum 0
#property indicator_maximum 1
//--- input parameters
extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame
extern string Custom_Indicator = "VIP Heiken Ashi";
extern string Copyright = "Copyright © 2010, KingLion";
extern string Web_Address = "www.metastock.org.ua";
//--- buffers
double HA_0[];
double HA_1[];
double HA_Open[];
double HA_Close[],count[];
string indicatorFileName;
#define _mtfCall(_buff,_ind) iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,"","","",_buff,_ind)
int init()
{
IndicatorBuffers(5);
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexBuffer(0, HA_0);
SetIndexLabel(0, "HA_0");
SetIndexStyle(1, DRAW_HISTOGRAM);
SetIndexBuffer(1, HA_1);
SetIndexLabel(1, "HA_1");
SetIndexBuffer(2, HA_Open);
SetIndexLabel(2, "HA_Open");
SetIndexBuffer(3, HA_Close);
SetIndexLabel(3, "HA_Close");
SetIndexBuffer(4,count);
SetIndexDrawBegin(0, 10);
SetIndexDrawBegin(1, 10);
indicatorFileName = WindowExpertName();
TimeFrame = fmax(TimeFrame,_Period);
IndicatorShortName(timeFrameToString(TimeFrame)+" vip heiken ashi");
return(0);
}
int deinit()
{
return(0);
}
int start()
{
int i,counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit = fmin(Bars-counted_bars,Bars-1); count[0] = limit;
if (TimeFrame != _Period)
{
limit = (int)MathMax(limit,fmin(Bars-1,_mtfCall(4,0)*TimeFrame/Period()));
for (i=limit; i>=0; i--)
{
int y = iBarShift(NULL,TimeFrame,Time);
HA_0 = _mtfCall(0,y);
HA_1 = _mtfCall(1,y);
}
return(0);
}
for(i=limit;i>=0;i--)
{
double OHLC4 = NormalizeDouble((Open + High + Low + Close) / 4.0, Digits);
OHLC4 = (OHLC4 + Close) / 2.0;
double OHLC8 = NormalizeDouble((HA_Open[i + 1] + (HA_Close[i + 1])) / 2.0, Digits);
double MaxHigh = MathMax(High, MathMax(OHLC8, OHLC4));
double MinLow = MathMin(Low, MathMin(OHLC8, OHLC4));
if (OHLC8 < OHLC4) {
HA_0 = EMPTY_VALUE;
HA_1 = 1;
} else {
HA_0 = 1;
HA_1 = EMPTY_VALUE;
}
HA_Open = OHLC8;
HA_Close = OHLC4;
}
return(0);
}
//+-------------------------------------------------------------------
//|
//+-------------------------------------------------------------------
//
//
//
//
//
string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
string timeFrameToString(int tf)
{
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tf==iTfTable) return(sTfTable);
return("");
}
|