91 lines
No EOL
5.8 KiB
MQL4
91 lines
No EOL
5.8 KiB
MQL4
//+------------------------------------------------------------------+
|
|
//| KG MA 1H.mq4|
|
|
//| Copyright © 2008, MetaQuotes Software Corp. |
|
|
//| http://www.metaquotes.net/ |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
|
|
#property link "http://www.metaquotes.net/"
|
|
|
|
#property indicator_chart_window
|
|
#property indicator_buffers 1
|
|
#property indicator_color1 White
|
|
|
|
#property indicator_width1 2
|
|
#property indicator_style1 0
|
|
|
|
|
|
//---- indicator parameters
|
|
//extern double MAPeriod=5;
|
|
int MAPeriod;
|
|
extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT;
|
|
extern int MAPeriode = 30;
|
|
|
|
extern ENUM_MA_METHOD MA_Mode = MODE_EMA;
|
|
extern ENUM_APPLIED_PRICE Price_Type= PRICE_CLOSE;
|
|
extern int MAShift=0;
|
|
datetime TimeArray[];
|
|
//---- buffers
|
|
double MovingBuffer[];
|
|
|
|
string short_name;
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Custom indicator initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int init()
|
|
{
|
|
|
|
int ActivePer=Period();
|
|
|
|
if (ActivePer == 10080) ActivePer = 7200;
|
|
if (ActivePer == 40320) ActivePer = 28800;
|
|
if (ActivePer == 161280) ActivePer = 115200;
|
|
|
|
MAPeriod = MAPeriode / ActivePer;
|
|
|
|
//---- indicators
|
|
|
|
SetIndexStyle(0,DRAW_LINE);
|
|
SetIndexBuffer(0,MovingBuffer);
|
|
//SetIndexDrawBegin(0,MAPeriode+MAShift);
|
|
short_name ="KG MA "+ MAPeriod+" ( "+ MAPeriode + ", " + IntegerToString(MA_Mode) + ", " + IntegerToString(Price_Type) + " )";
|
|
IndicatorShortName(short_name);
|
|
SetIndexLabel(0,short_name);
|
|
|
|
return(0);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Bollinger Bands |
|
|
//+------------------------------------------------------------------+
|
|
int start()
|
|
{
|
|
int i,y,counted_bars=IndicatorCounted();
|
|
|
|
//if(Period() >= MAPeriode) return(0);
|
|
/*
|
|
int ActivePer=Period();
|
|
|
|
if (ActivePer == 10080) ActivePer = 7200;
|
|
if (ActivePer == 40320) ActivePer = 28800;
|
|
|
|
MAPeriod = MAPeriode/ActivePer;
|
|
*/
|
|
//----
|
|
if(Bars<=MAPeriod) return(0);
|
|
|
|
|
|
//---- initial zero
|
|
|
|
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
|
|
if(counted_bars<1)
|
|
for(i=1;i<=MAPeriod;i++) MovingBuffer[Bars-i]=EMPTY_VALUE;
|
|
//----
|
|
int limit=Bars-counted_bars+TimeFrame/Period();
|
|
///if(counted_bars>0) limit++;
|
|
for(i=0, y=0; i<limit; i++){
|
|
if (Time[i]<TimeArray[y]) y++;
|
|
MovingBuffer[i]=iMA( NULL, TimeFrame, MAPeriod, MAShift, MA_Mode , Price_Type, y+MAShift);
|
|
}
|
|
return(0);
|
|
}
|
|
//+----------------- -------------------------------------------------+ |