ÿþ
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link "https://mql5.com"
#property version "1.00"
#property description "Multitimeframe CCI and MA info-panel."
#property description "Indicator analyzed the position of price with a determined moving average"
#property description "in a multi time frame mode and also the position of the CCI in regards of"
#property description "buying and selling levels also in MTF mode."
#property description "Colored slope and arrows for position of price/MA and CCI/Levels"
#include <Canvas\Canvas.mqh>
enum ENUM_MOUSE_STATE
{
MOUSE_STATE_NOT_PRESSED,
MOUSE_STATE_PRESSED_OUTSIDE_WINDOW,
MOUSE_STATE_PRESSED_INSIDE_WINDOW,
MOUSE_STATE_PRESSED_INSIDE_HEADER,
MOUSE_STATE_OUTSIDE_WINDOW,
MOUSE_STATE_INSIDE_WINDOW,
MOUSE_STATE_INSIDE_HEADER
};
class CWnd
{
protected:
CCanvas m_canvas;
CCanvas m_field;
long m_chart_id;
int m_chart_w;
int m_chart_h;
int m_sub_wnd;
string m_name;
string m_caption;
string m_caption_font;
string m_name_gv_x;
string m_name_gv_y;
color m_color_bg;
color m_color_border;
color m_color_bg_header;
color m_color_caption;
color m_color_texts;
uchar m_alpha_bg;
uchar m_alpha_head;
int m_x;
int m_y;
int m_w;
int m_h;
int m_y_act;
int m_caption_font_size;
uint m_caption_alignment;
uint m_x_caption;
bool m_is_visible;
bool m_header_on;
bool m_movable;
bool m_wider_wnd;
bool m_higher_wnd;
ENUM_PROGRAM_TYPE m_program_type;
ENUM_MOUSE_STATE m_mouse_state;
ENUM_MOUSE_STATE MouseButtonState(const int x,const int y,bool pressed);
void Move(int x,int y);
bool CreateCanvas(CCanvas &canvas,const int wnd_id,const int x,const int y,const int w,const int h);
void DrawHeaderArea(const string caption);
void RedrawHeaderArea(const color clr_area,const color clr_caption);
string TimeframeToString(const ENUM_TIMEFRAMES timeframe);
int CoordX1(void) const { return this.m_x; }
int CoordX2(void) const { return this.m_x+this.m_w; }
int CoordY1(void) const { return this.m_y; }
int CoordY2(void) const { return this.m_y+this.m_h; }
int CoordYAct(void) const { return this.m_y+this.m_y_act; }
color RGBToColor(const double r,const double g,const double b);
void ColorToRGB(const color clr,double &r,double &g,double &b);
double GetR(const color clr) { return clr&0xff ; }
double GetG(const color clr) { return(clr>>8)&0xff; }
double GetB(const color clr) { return(clr>>16)&0xff; }
int ChartWidth(void) const { return this.m_chart_w; }
int ChartHeight(void) const { return this.m_chart_h; }
bool HigherWnd(void) const { return(this.m_h+2>this.m_chart_h); }
bool WiderWnd(void) const { return(this.m_w+2>this.m_chart_w); }
public:
bool CreateWindow(const string caption_text,const int x,const int y,const int w,const int h,const bool header,bool movable);
void Resize(const int w,const int h);
void SetColors(const color clr_bg,const color clr_bd,const color clr_hd,const color clr_capt,const color clr_text,uchar alpha_bg=128,uchar alpha_hd=200);
CCanvas* GetFieldCanvas(void) { return &this.m_field; }
void DrawSeparateVLine(const int x,const int y1,const int y2,const color clr1,const color clr2,const uchar w=1);
void DrawSeparateHLine(const int x,const int y1,const int y2,const color clr1,const color clr2,const uchar w=1);
color NewColor(color base_color, int shift_red, int shift_green, int shift_blue);
string Caption(void) const { return this.m_caption; }
string NameCaptionFont(void) const { return this.m_caption_font; }
color ColorCaption(void) const { return this.m_color_caption; }
color ColorBackground(void) const { return this.m_color_bg; }
color ColorHeaderBackground(void) const { return this.m_color_bg_header; }
color ColorTexts(void) const { return this.m_color_texts; }
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
CWnd(void);
~CWnd(void);
};
CWnd::CWnd(void) : m_chart_id(::ChartID()),
m_program_type((ENUM_PROGRAM_TYPE)::MQLInfoInteger(MQL_PROGRAM_TYPE)),
m_name(::MQLInfoString(MQL_PROGRAM_NAME)),
m_name_gv_x(m_name+"_GVX"),
m_name_gv_y(m_name+"_GVY"),
m_sub_wnd(m_program_type==PROGRAM_EXPERT || m_program_type==PROGRAM_SCRIPT ? 0 : ::ChartWindowFind()),
m_chart_w((int)::ChartGetInteger(m_chart_id,CHART_WIDTH_IN_PIXELS,m_sub_wnd)),
m_chart_h((int)::ChartGetInteger(m_chart_id,CHART_HEIGHT_IN_PIXELS,m_sub_wnd)),
m_caption(""),
m_caption_font("Calibri"),
m_caption_font_size(-100),
m_alpha_bg(128),
m_alpha_head(200),
m_color_bg(C'200,200,200'),
m_color_bg_header(clrDarkGray),
m_color_border(clrDarkGray),
m_color_caption(clrYellow),
m_color_texts(clrSlateGray),
m_h(100),
m_w(160),
m_x(3),
m_y(::ChartGetInteger(m_chart_id,CHART_SHOW_ONE_CLICK) ? 79 : 20),
m_y_act(10),
m_is_visible(false),
m_movable(true),
m_header_on(true),
m_x_caption(4),
m_caption_alignment(TA_LEFT|TA_VCENTER),
m_mouse_state(MOUSE_STATE_NOT_PRESSED)
{
::ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
if(!::GlobalVariableCheck(this.m_name_gv_x))
::GlobalVariableSet(this.m_name_gv_x,this.m_x);
else
this.m_x=(int)::GlobalVariableGet(this.m_name_gv_x);
if(!::GlobalVariableCheck(this.m_name_gv_y))
::GlobalVariableSet(this.m_name_gv_y,this.m_y);
else
this.m_y=(int)::GlobalVariableGet(this.m_name_gv_y);
this.m_higher_wnd=this.HigherWnd();
this.m_wider_wnd=this.WiderWnd();
}
CWnd::~CWnd(void)
{
::ObjectsDeleteAll(this.m_chart_id,m_name);
::GlobalVariableSet(this.m_name_gv_x,this.m_x);
::GlobalVariableSet(this.m_name_gv_y,this.m_y);
}
void CWnd::OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
if(id==CHARTEVENT_CHART_CHANGE)
{
this.m_sub_wnd=(this.m_program_type==PROGRAM_EXPERT || this.m_program_type==PROGRAM_SCRIPT ? 0 : ::ChartWindowFind());
int w=(int)::ChartGetInteger(this.m_chart_id,CHART_WIDTH_IN_PIXELS,this.m_sub_wnd);
int h=(int)::ChartGetInteger(this.m_chart_id,CHART_HEIGHT_IN_PIXELS,this.m_sub_wnd);
this.m_higher_wnd=this.HigherWnd();
this.m_wider_wnd=this.WiderWnd();
if(this.m_chart_h!=h)
{
this.m_chart_h=h;
int y=this.CoordY1();
if(this.CoordY1()+this.m_h>h-1) y=h-this.m_h-1;
if(y<1) y=1;
this.Move(this.CoordX1(),y);
}
if(this.m_chart_w!=w)
{
this.m_chart_w=w;
int x=this.CoordX1();
if(this.CoordX1()+this.m_w>w-1) x=w-this.m_w-1;
if(x<1) x=1;
this.Move(x,this.CoordY1());
}
}
if(!this.m_movable)
return;
static int diff_x=0;
static int diff_y=0;
bool pressed=(sparam=="1" || sparam=="" ? true : false);
int mouse_x=(int)lparam;
int mouse_y=(int)dparam-(int)::ChartGetInteger(this.m_chart_id,CHART_WINDOW_YDISTANCE,this.m_sub_wnd);
ENUM_MOUSE_STATE state=this.MouseButtonState(mouse_x,mouse_y,pressed);
if(id==CHARTEVENT_MOUSE_MOVE)
{
if(state==MOUSE_STATE_PRESSED_INSIDE_WINDOW)
{
::ChartSetInteger(0,CHART_MOUSE_SCROLL,false);
::ChartRedraw(this.m_chart_id);
return;
}
else if(state==MOUSE_STATE_PRESSED_INSIDE_HEADER)
{
::ChartSetInteger(0,CHART_MOUSE_SCROLL,false);
this.Move(mouse_x-diff_x,mouse_y-diff_y);
return;
}
else
{
::ChartSetInteger(0,CHART_MOUSE_SCROLL,true);
diff_x=mouse_x-this.CoordX1();
diff_y=mouse_y-this.CoordY1();
}
}
}
ENUM_MOUSE_STATE CWnd::MouseButtonState(const int x,const int y,bool pressed)
{
if(pressed)
{
if(this.m_mouse_state!=MOUSE_STATE_NOT_PRESSED)
return this.m_mouse_state;
if(x>this.CoordX1() && x<this.CoordX2() && y>this.CoordY1() && y<this.CoordY2())
{
if(y>this.CoordY1() && y<this.CoordYAct())
{
this.RedrawHeaderArea(this.NewColor(this.m_color_bg_header,30,30,30),this.m_color_caption);
this.m_mouse_state=MOUSE_STATE_PRESSED_INSIDE_HEADER;
return this.m_mouse_state;
}
else if(y>this.CoordY1() && y<this.CoordY2())
{
this.m_mouse_state=(this.m_header_on ? MOUSE_STATE_PRESSED_INSIDE_WINDOW : MOUSE_STATE_PRESSED_INSIDE_HEADER);
return this.m_mouse_state;
}
}
else
{
this.m_mouse_state=MOUSE_STATE_PRESSED_OUTSIDE_WINDOW;
return this.m_mouse_state;
}
}
else
{
this.m_mouse_state=MOUSE_STATE_NOT_PRESSED;
if(x>this.CoordX1() && x<this.CoordX2() && y>this.CoordY1() && y<this.CoordY2())
{
if(y>this.CoordY1() && y<this.CoordYAct())
{
this.RedrawHeaderArea(this.NewColor(this.m_color_bg_header,20,20,20),this.m_color_caption);
return MOUSE_STATE_INSIDE_HEADER;
}
else
{
this.RedrawHeaderArea(this.m_color_bg_header,this.m_color_caption);
return MOUSE_STATE_INSIDE_WINDOW;
}
}
}
this.RedrawHeaderArea(this.m_color_bg_header,this.m_color_caption);
return MOUSE_STATE_NOT_PRESSED;
}
void CWnd::Move(int x,int y)
{
if(!this.m_wider_wnd)
{
if(x+this.m_w>this.m_chart_w-1) x=this.m_chart_w-this.m_w-1;
if(x<1) x=1;
}
else
{
if(x>1) x=1;
if(x<this.m_chart_w-this.m_w-1) x=this.m_chart_w-this.m_w-1;
}
if(!this.m_higher_wnd)
{
if(y+this.m_h>this.m_chart_h-2) y=this.m_chart_h-this.m_h-2;
if(y<1) y=1;
}
else
{
if(y>1) y=1;
if(y<this.m_chart_h-this.m_h-2) y=this.m_chart_h-this.m_h-2;
}
this.m_x=x;
this.m_y=y;
::ObjectSetInteger(this.m_chart_id,this.m_name+"0",OBJPROP_XDISTANCE,this.m_x);
::ObjectSetInteger(this.m_chart_id,this.m_name+"0",OBJPROP_YDISTANCE,this.m_y);
::ObjectSetInteger(this.m_chart_id,this.m_name+"1",OBJPROP_XDISTANCE,this.m_x+1);
::ObjectSetInteger(this.m_chart_id,this.m_name+"1",OBJPROP_YDISTANCE,this.m_y+this.m_y_act+1);
this.m_canvas.Update(true);
}
bool CWnd::CreateCanvas(CCanvas &canvas,const int wnd_id,const int x,const int y,const int w,const int h)
{
if(!canvas.CreateBitmapLabel(this.m_chart_id,this.m_sub_wnd,this.m_name+(string)wnd_id,x,y,w,h,COLOR_FORMAT_ARGB_NORMALIZE))
return false;
if(wnd_id==0)
{
this.m_x=x;
this.m_y=y;
this.m_w=w;
this.m_h=h;
}
::ObjectSetInteger(this.m_chart_id,this.m_name+(string)wnd_id,OBJPROP_SELECTABLE,false);
::ObjectSetInteger(this.m_chart_id,this.m_name+(string)wnd_id,OBJPROP_SELECTED,false);
::ObjectSetInteger(this.m_chart_id,this.m_name+(string)wnd_id,OBJPROP_HIDDEN,true);
return true;
}
bool CWnd::CreateWindow(const string caption_text,const int x,const int y,const int w,const int h,const bool header,bool movable)
{
if(!this.CreateCanvas(this.m_canvas,0,x,y,w,h))
return false;
this.m_header_on=header;
if(!header)
this.m_y_act=0;
this.m_movable=movable;
this.m_caption=caption_text;
this.m_canvas.Erase(::ColorToARGB(this.m_color_bg,this.m_alpha_bg));
this.m_canvas.Rectangle(0,0,this.m_w-1,this.m_h-1,::ColorToARGB(this.m_color_border));
this.DrawHeaderArea(this.m_caption);
this.m_canvas.Update(true);
if(!this.CreateCanvas(this.m_field,1,this.m_x+1,this.m_y+this.m_y_act+1,this.m_w-2,this.m_h-this.m_y_act-2))
return false;
return true;
}
void CWnd::Resize(const int w,const int h)
{
this.m_w=w;
this.m_h=h;
this.m_canvas.Resize(this.m_w,this.m_h);
this.m_field.Resize(this.m_w-2,this.m_h-this.m_y_act-2);
this.m_canvas.Erase(::ColorToARGB(this.m_color_bg,this.m_alpha_bg));
this.m_canvas.Rectangle(0,0,this.m_w-1,this.m_h-1,::ColorToARGB(this.m_color_border));
this.DrawHeaderArea(this.m_caption);
this.m_canvas.Update(false);
this.m_field.Update(true);
}
void CWnd::DrawHeaderArea(const string caption)
{
if(!this.m_header_on) return;
this.m_canvas.FillRectangle(0,0,this.m_w,this.m_y_act,::ColorToARGB(this.m_color_bg_header,this.m_alpha_head));
this.m_canvas.FontSet(this.m_caption_font,this.m_caption_font_size,FW_NORMAL);
this.m_canvas.TextOut(this.m_x_caption,this.m_y_act/2,caption,::ColorToARGB(this.m_color_caption),this.m_caption_alignment);
}
void CWnd::RedrawHeaderArea(const color clr_area,const color clr_caption)
{
if(!this.m_header_on) return;
this.m_canvas.FillRectangle(0,0,this.m_w,this.m_y_act,::ColorToARGB(clr_area,this.m_alpha_head));
this.m_canvas.FontSet(this.m_caption_font,this.m_caption_font_size,FW_NORMAL);
this.m_canvas.TextOut(this.m_x_caption,this.m_y_act/2,this.m_caption,::ColorToARGB(clr_caption),this.m_caption_alignment);
this.m_canvas.Update();
}
void CWnd::DrawSeparateVLine(const int x,const int y1,const int y2,const color clr1,const color clr2,const uchar w=1)
{
this.m_field.LineVertical(x,y1,y2,::ColorToARGB(clr1,this.m_alpha_bg));
this.m_field.LineVertical(x+w,y1,y2,::ColorToARGB(clr2,this.m_alpha_bg));
}
void CWnd::DrawSeparateHLine(const int x1,const int x2,const int y,const color clr1,const color clr2,const uchar w=1)
{
this.m_field.LineHorizontal(x1,x2,y,::ColorToARGB(clr1,this.m_alpha_bg));
this.m_field.LineHorizontal(x1,x2,y+w,::ColorToARGB(clr2,this.m_alpha_bg));
}
color CWnd::NewColor(color base_color, int shift_red, int shift_green, int shift_blue)
{
double clR=0, clG=0, clB=0;
this.ColorToRGB(base_color,clR,clG,clB);
double clRn=(clR+shift_red < 0 ? 0 : clR+shift_red > 255 ? 255 : clR+shift_red);
double clGn=(clG+shift_green< 0 ? 0 : clG+shift_green> 255 ? 255 : clG+shift_green);
double clBn=(clB+shift_blue < 0 ? 0 : clB+shift_blue > 255 ? 255 : clB+shift_blue);
return this.RGBToColor(clRn,clGn,clBn);
}
color CWnd::RGBToColor(const double r,const double g,const double b)
{
int int_r=(int)::round(r);
int int_g=(int)::round(g);
int int_b=(int)::round(b);
int clr=0;
clr=int_b;
clr<<=8;
clr|=int_g;
clr<<=8;
clr|=int_r;
return (color)clr;
}
void CWnd::ColorToRGB(const color clr,double &r,double &g,double &b)
{
r=GetR(clr);
g=GetG(clr);
b=GetB(clr);
}
string CWnd::TimeframeToString(const ENUM_TIMEFRAMES timeframe)
{
return ::StringSubstr(::EnumToString(timeframe==PERIOD_CURRENT ? Period() : timeframe),7);
}
void CWnd::SetColors(const color clr_bg,const color clr_bd,const color clr_hd,const color clr_capt,const color clr_text,uchar alpha_bg=128,uchar alpha_hd=200)
{
this.m_color_bg=clr_bg;
this.m_color_border=clr_bd;
this.m_color_bg_header=clr_hd;
this.m_color_caption=clr_capt;
this.m_color_texts=clr_text;
this.m_alpha_bg=alpha_bg;
this.m_alpha_head=alpha_hd;
}
#include <Indicators\Trend.mqh>
#include <Indicators\Oscilators.mqh>
class CMaCCI : public CiMA
{
protected:
ENUM_MA_METHOD m_method;
ENUM_APPLIED_PRICE m_price;
int m_index_x;
int m_index_y;
int m_period_ma;
int m_period_cci;
int m_refresh_flags;
CiMA m_ma;
CiCCI m_cci;
bool CreateMA(void) { return(this.m_ma.Create(this.m_symbol,this.m_period,this.m_period_ma,0,this.m_method,this.m_price)); }
bool CreateCCI(void) { return(this.m_cci.Create(this.m_symbol,this.m_period,this.m_period_cci,PRICE_TYPICAL)); }
datetime Time(const int shift) const { datetime array[]; return(::CopyTime(this.Symbol(),this.Period(),1,1,array)==1 ? array[0] : 0); }
public:
bool CreateIND(void);
void Refresh(void);
void SetRefreshFlags(const bool refresh_current,const int refresh_periods);
void SetIndexX(const int x) { this.m_index_x=x; }
void SetIndexY(const int y) { this.m_index_y=y; }
int IndexX(void) const { return this.m_index_x; }
int IndexY(void) const { return this.m_index_y; }
double Close(const int shift) const { double array[]; return(::CopyClose(this.Symbol(),this.Period(),shift,1,array)==1 ? array[0] : 0); }
double GetDataMA(const int shift) const { return this.m_ma.Main(shift); }
double GetDataCCI(const int shift) const { return this.m_cci.Main(shift); }
bool CheckLoadHistory(void) { return CSeries::CheckLoadHistory(this.BufferSize()); }
string TimeframeDescription(void) const { return ::StringSubstr(::EnumToString(this.m_period==PERIOD_CURRENT ? ::Period() : this.m_period),7); }
void OnTimer(void) { this.Time(1); }
CMaCCI(const string symbol_name,
const ENUM_TIMEFRAMES timeframe,
const int period_ma,
const int period_cci,
const ENUM_MA_METHOD method,
const ENUM_APPLIED_PRICE price);
~CMaCCI(void){;}
};
CMaCCI::CMaCCI(const string symbol_name,
const ENUM_TIMEFRAMES timeframe,
const int period_ma,
const int period_cci,
const ENUM_MA_METHOD method,
const ENUM_APPLIED_PRICE price) : m_refresh_flags(OBJ_ALL_PERIODS),m_index_x(0),m_index_y(0)
{
this.SetSymbolPeriod(symbol_name,timeframe);
this.m_period_ma=period_ma;
this.m_period_cci=period_cci;
this.m_method=method;
this.m_price=price;
this.m_refresh_current=false;
}
bool CMaCCI::CreateIND(void)
{
return(this.CreateMA() && this.CreateCCI());
}
void CMaCCI::SetRefreshFlags(const bool refresh_current,const int refresh_periods)
{
this.RefreshCurrent(refresh_current);
this.m_refresh_flags=refresh_periods;
}
void CMaCCI::Refresh(void)
{
this.m_ma.Refresh(this.m_refresh_flags);
this.m_cci.Refresh(this.m_refresh_flags);
}
#include <Arrays\ArrayObj.mqh>
#include <Arrays\ArrayInt.mqh>
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
enum ENUM_INPUT_YES_NO
{
INPUT_YES = 1,
INPUT_NO = 0
};
input uint InpPeriodMA = 100;
input ENUM_MA_METHOD InpMethod = MODE_SMA;
input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE;
input uint InpPeriodCCI = 100;
input double InpCCILevelB = 0;
input double InpCCILevelS = 0;
input ENUM_INPUT_YES_NO InpUseM1 = INPUT_YES;
input ENUM_INPUT_YES_NO InpUseM2 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseM3 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseM4 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseM5 = INPUT_YES;
input ENUM_INPUT_YES_NO InpUseM6 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseM10 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseM12 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseM15 = INPUT_YES;
input ENUM_INPUT_YES_NO InpUseM20 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseM30 = INPUT_YES;
input ENUM_INPUT_YES_NO InpUseH1 = INPUT_YES;
input ENUM_INPUT_YES_NO InpUseH2 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseH3 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseH4 = INPUT_YES;
input ENUM_INPUT_YES_NO InpUseH6 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseH8 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseH12 = INPUT_NO;
input ENUM_INPUT_YES_NO InpUseD1 = INPUT_YES;
input ENUM_INPUT_YES_NO InpUseW1 = INPUT_YES;
input ENUM_INPUT_YES_NO InpUseMN1 = INPUT_YES;
input uint InpCoordX = 10;
input uint InpCoordY = 10;
input color InpColorPanel = C'240,240,240';
input color InpColorBorder = C'200,200,200';
input color InpColorHeader = clrDarkGray;
input color InpColorCaption = clrBeige;
input color InpColorLabels = clrSlateGray;
input color InpColorUP = clrLimeGreen;
input color InpColorDN = clrDarkOrange;
input uchar InpAlphaBackgrnd = 128;
CArrayInt list_timeframes;
CArrayObj list_ind;
CWnd panel;
double level_b;
double level_s;
int period_ind_ma;
int period_ind_cci;
string gv_name;
int OnInit()
{
EventSetTimer(90);
period_ind_ma=int(InpPeriodMA<1 ? 1 : InpPeriodMA);
period_ind_cci=int(InpPeriodCCI<2 ? 2 : InpPeriodCCI);
level_b=(InpCCILevelB>0 ? 0 : InpCCILevelB);
level_s=(InpCCILevelS<0 ? 0 : InpCCILevelS);
gv_name="MTF_CCI_MA";
list_timeframes.Clear();
for(int i=0;i<21;i++)
{
int tf=GetInputTimeframe(i);
if(tf==WRONG_VALUE)
continue;
list_timeframes.Add((int)tf);
}
int total_tfs=list_timeframes.Total();
for(int t=0;t<total_tfs;t++)
{
ENUM_TIMEFRAMES timeframe=(ENUM_TIMEFRAMES)list_timeframes.At(t);
CMaCCI* ind=new CMaCCI(Symbol(),timeframe,period_ind_ma,period_ind_cci,InpMethod,InpAppliedPrice);
if(ind==NULL)
continue;
list_ind.Add(ind);
if(!ind.CreateIND())
{
Print(ind.Symbol()," ",ind.TimeframeDescription(),": Failed to create MA or CCI handle. Please restart the indicator");
return INIT_FAILED;
}
else
{
ind.SetRefreshFlags(true,OBJ_ALL_PERIODS);
ind.SetIndexX(t);
ind.SetIndexY(0);
ind.Refresh();
}
}
int w=180,h=84;
int x=int(!GlobalVariableCheck(gv_name+"_GVX") ? int(ChartGetInteger(0,CHART_WIDTH_IN_PIXELS)-w-InpCoordX) : GlobalVariableGet(gv_name+"_GVX"));
int y=int(!GlobalVariableCheck(gv_name+"_GVY") ? (int)InpCoordY : GlobalVariableGet(gv_name+"_GVY"));
panel.SetColors(InpColorPanel,InpColorBorder,InpColorHeader,InpColorCaption,InpColorLabels,InpAlphaBackgrnd,200);
string name=gv_name;
StringReplace(name,"_"," ");
if(!panel.CreateWindow(name,x,y,w,h,true,true))
{
Print("Failed to create panel. Please restart the indicator");
return INIT_FAILED;
}
RedrawField();
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
RedrawField();
return(rates_total);
}
void OnTimer()
{
int total=list_ind.Total();
for(int i=0;i<total;i++)
{
CMaCCI* ind=list_ind.At(i);
if(ind==NULL)
continue;
ind.OnTimer();
}
}
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
panel.OnChartEvent(id,lparam,dparam,sparam);
}
void RedrawField()
{
int row=2;
int col=list_timeframes.Total();
CCanvas* canvas=panel.GetFieldCanvas();
if(canvas==NULL)
{
Print(__FUNCTION__,": Error: Canvas not available.");
return;
}
int shiftV=14,shiftH=28,startH=58,startV=15;
panel.Resize(startH+col*shiftH,shiftV+row*shiftV+14);
canvas.Erase(ColorToARGB(panel.ColorBackground(),0));
panel.DrawSeparateHLine(1,canvas.Width()-2,13,panel.NewColor(panel.ColorBackground(),-5,-5,-5),panel.NewColor(panel.ColorBackground(),45,45,45));
panel.DrawSeparateVLine(52,14,canvas.Height()-2,panel.NewColor(panel.ColorBackground(),-5,-5,-5),panel.NewColor(panel.ColorBackground(),45,45,45));
int total=list_ind.Total();
for(int i=0;i<total;i++)
{
CMaCCI* ind=list_ind.At(i);
if(ind==NULL)
continue;
if(!ind.CheckLoadHistory())
{
Print(ind.Symbol(),": loading history");
return;
}
ind.Refresh();
int x=ind.IndexX();
int y=ind.IndexY();
if(y==0)
{
string tf=ind.TimeframeDescription();
canvas.FontSet(panel.NameCaptionFont(),-80,FW_BLACK);
canvas.TextOut(startH+x*shiftH,6,tf,ColorToARGB(panel.ColorTexts()),TA_LEFT|TA_VCENTER);
if(x==0)
canvas.TextOut(22,0,ind.Symbol(),ColorToARGB(panel.ColorTexts()),TA_CENTER);
}
if(x==0)
{
canvas.FontSet(panel.NameCaptionFont(),-80,FW_BLACK);
canvas.TextOut(4,startV,"Price/MA",ColorToARGB(panel.ColorTexts()));
canvas.TextOut(34,startV+shiftV,"CCI",ColorToARGB(panel.ColorTexts()));
}
double ma0=ind.GetDataMA(0);
double ma1=ind.GetDataMA(1);
double cci0=ind.GetDataCCI(0);
double cci1=ind.GetDataCCI(1);
double cls=ind.Close(0);
int gx=6+startH+x*shiftH;
int gy=6+startV;
color clr_ma=(ma0>ma1 ? InpColorUP : ma0<ma1 ? InpColorDN : InpColorLabels);
if(cls>ma0)
TriangleUp(canvas,gx,gy,panel.NewColor(clr_ma,-90,-90,-90),clr_ma);
else if(cls<ma0)
TriangleDown(canvas,gx,gy,panel.NewColor(clr_ma,-90,-90,-90),clr_ma);
else
TriangleRight(canvas,gx,gy,clrDimGray,clrGray);
color clr_cci=(cci0>cci1 ? InpColorUP : cci0<cci1 ? InpColorDN : InpColorLabels);
if(level_b!=level_s)
{
if(cci0>level_b && cci0<0)
TriangleUp(canvas,gx,gy+shiftV,panel.NewColor(clr_ma,-90,-90,-90),clr_cci);
else if(cci0<level_s && cci0>0)
TriangleDown(canvas,gx,gy+shiftV,panel.NewColor(clr_ma,-90,-90,-90),clr_cci);
else
Circle(canvas,gx,gy+shiftV,3,clr_cci,panel.NewColor(clr_cci,40,40,40));
}
else
{
if(cci0>level_b)
TriangleUp(canvas,gx,gy+shiftV,panel.NewColor(clr_ma,-90,-90,-90),clr_cci);
else if(cci0<level_s)
TriangleDown(canvas,gx,gy+shiftV,panel.NewColor(clr_ma,-90,-90,-90),clr_cci);
else
Circle(canvas,gx,gy+shiftV,3,clr_cci,panel.NewColor(clr_cci,40,40,40));
}
}
canvas.Update(true);
}
void TriangleUp(CCanvas* canvas,const int x,const int y,const color clr_bd,const color clr_bg)
{
if(canvas==NULL)
return;
int x1=x-4;
int y1=y+2;
int x2=x;
int y2=y-2;
int x3=x+4;
int y3=y1;
canvas.FillTriangle(x1,y1,x2,y2,x3,y3,ColorToARGB(clr_bg));
canvas.TriangleWu(x1,y1,x2,y2,x3,y3,ColorToARGB(clr_bd),STYLE_SOLID);
}
void TriangleDown(CCanvas* canvas,const int x,const int y,const color clr_bd,const color clr_bg)
{
if(canvas==NULL)
return;
int x1=x-4;
int y1=y-2;
int x2=x;
int y2=y+2;
int x3=x+4;
int y3=y1;
canvas.FillTriangle(x1,y1,x2,y2,x3,y3,ColorToARGB(clr_bg));
canvas.TriangleWu(x1,y1,x2,y2,x3,y3,ColorToARGB(clr_bd),STYLE_SOLID);
}
void TriangleRight(CCanvas* canvas,const int x,const int y,const color clr_bd,const color clr_bg)
{
if(canvas==NULL)
return;
int x1=x-2;
int y1=y-3;
int x2=x+3;
int y2=y;
int x3=x-2;
int y3=y+3;
canvas.FillTriangle(x1,y1,x2,y2,x3,y3,ColorToARGB(clr_bg));
canvas.TriangleWu(x1,y1,x2,y2,x3,y3,ColorToARGB(clr_bd),STYLE_SOLID);
}
void Circle(CCanvas* canvas,const int x,const int y,const double r,const color clr_bd,const color clr_bg)
{
if(canvas==NULL)
return;
canvas.FillCircle(x,y,(int)r,ColorToARGB(clr_bg));
canvas.CircleWu(x,y,r,ColorToARGB(clr_bd),STYLE_SOLID);
}
bool SymbolCheck(const string symbol_name)
{
long select=0;
ResetLastError();
if(!SymbolInfoInteger(symbol_name,SYMBOL_SELECT,select))
{
int err=GetLastError();
Print("Error: ",err," Symbol ",symbol_name," does not exist");
return false;
}
else
{
if(select) return true;
ResetLastError();
if(!SymbolSelect(symbol_name,true))
{
int err=GetLastError();
Print("Error selected ",symbol_name,": ",err);
}
}
return false;
}
int IndexSymbol(const ENUM_TIMEFRAMES timeframe)
{
int total=list_timeframes.Total();
for(int i=0;i<total;i++)
if((ENUM_TIMEFRAMES)list_timeframes.At(i)==timeframe)
return i;
return WRONG_VALUE;
}
int GetInputTimeframe(const int index)
{
switch(index)
{
case 0 : return (InpUseM1 ? PERIOD_M1 : WRONG_VALUE);
case 1 : return (InpUseM2 ? PERIOD_M2 : WRONG_VALUE);
case 2 : return (InpUseM3 ? PERIOD_M3 : WRONG_VALUE);
case 3 : return (InpUseM4 ? PERIOD_M4 : WRONG_VALUE);
case 4 : return (InpUseM5 ? PERIOD_M5 : WRONG_VALUE);
case 5 : return (InpUseM6 ? PERIOD_M6 : WRONG_VALUE);
case 6 : return (InpUseM10 ? PERIOD_M10 : WRONG_VALUE);
case 7 : return (InpUseM12 ? PERIOD_M12 : WRONG_VALUE);
case 8 : return (InpUseM15 ? PERIOD_M15 : WRONG_VALUE);
case 9 : return (InpUseM20 ? PERIOD_M20 : WRONG_VALUE);
case 10 : return (InpUseM30 ? PERIOD_M30 : WRONG_VALUE);
case 11 : return (InpUseH1 ? PERIOD_H1 : WRONG_VALUE);
case 12 : return (InpUseH2 ? PERIOD_H2 : WRONG_VALUE);
case 13 : return (InpUseH3 ? PERIOD_H3 : WRONG_VALUE);
case 14 : return (InpUseH4 ? PERIOD_H4 : WRONG_VALUE);
case 15 : return (InpUseH6 ? PERIOD_H6 : WRONG_VALUE);
case 16 : return (InpUseH8 ? PERIOD_H8 : WRONG_VALUE);
case 17 : return (InpUseH12 ? PERIOD_H12 : WRONG_VALUE);
case 18 : return (InpUseD1 ? PERIOD_D1 : WRONG_VALUE);
case 19 : return (InpUseW1 ? PERIOD_W1 : WRONG_VALUE);
default : return (InpUseMN1 ? PERIOD_MN1 : WRONG_VALUE);
}
}
Comments