This commit is contained in:
Pierre8rTeam
2018-04-06 20:55:57 +02:00
parent e317e4c330
commit f73c061349
96 changed files with 4266 additions and 0 deletions
@@ -0,0 +1,107 @@
//+------------------------------------------------------------------+
//| PriceChangeRow.mqh |
//| Marcin Konieczny |
//| |
//+------------------------------------------------------------------+
#property copyright "Marcin Konieczny"
#include <Row.mqh>
//+------------------------------------------------------------------+
//| CPriceChangeRow class |
//+------------------------------------------------------------------+
class CPriceChangeRow : public CRow
{
private:
bool percentChange;
bool useArrows;
public:
//--- constructor
CPriceChangeRow(bool arrows,bool percent=false);
//--- overrides default GetName() method from CRow
virtual string GetName();
//--- overrides default GetFont() method from CRow
virtual string GetFont(string symbol,ENUM_TIMEFRAMES tf);
//--- overrides default GetValue(..) method from CRow
virtual string GetValue(string symbol,ENUM_TIMEFRAMES tf);
//--- overrides default GetColor(..) method from CRow
virtual color GetColor(string symbol,ENUM_TIMEFRAMES tf);
};
//+------------------------------------------------------------------+
//| CPriceChangeRow class constructor |
//+------------------------------------------------------------------+
CPriceChangeRow::CPriceChangeRow(bool arrows,bool percent=false)
{
percentChange=percent;
useArrows=arrows;
}
//+------------------------------------------------------------------+
//| Overrides default GetName() method from CRow |
//+------------------------------------------------------------------+
string CPriceChangeRow::GetName()
{
return("PriceChg");
}
//+------------------------------------------------------------------+
//| Overrides default GetFont() method from CRow |
//+------------------------------------------------------------------+
string CPriceChangeRow::GetFont(string symbol,ENUM_TIMEFRAMES tf)
{
//--- we use Wingdings font to draw arrows (up/down)
if(useArrows)
return("Wingdings");
else
return("Arial");
}
//+------------------------------------------------------------------+
//| Overrides default GetValue(..) method from CRow |
//+------------------------------------------------------------------+
string CPriceChangeRow::GetValue(string symbol,ENUM_TIMEFRAMES tf)
{
double close[1];
double open[1];
//--- gets open and close of current bar
if(CopyClose(symbol,tf,0, 1, close) < 0) return(" ");
if(CopyOpen(symbol, tf, 0, 1, open) < 0) return(" ");
//--- current bar price change
double change=close[0]-open[0];
if(useArrows)
{
if(change > 0) return(CharToString(233)); // returns up arrow code
if(change < 0) return(CharToString(234)); // returns down arrow code
return(" ");
}else{
if(percentChange)
{
//--- calculates percent change
return(DoubleToString(change/open[0]*100.0,3)+"%");
}else{
return(DoubleToString(change,(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS)));
}
}
}
//+------------------------------------------------------------------+
//| Overrides default GetColor(..) method from CRow |
//+------------------------------------------------------------------+
color CPriceChangeRow::GetColor(string symbol,ENUM_TIMEFRAMES tf)
{
double close[1];
double open[1];
//--- gets open and close of current bar
if(CopyClose(symbol,tf,0, 1, close) < 0) return(clrWhite);
if(CopyOpen(symbol, tf, 0, 1, open) < 0) return(clrWhite);
if(close[0] > open[0]) return(clrLime);
if(close[0] < open[0]) return(clrRed);
return(clrWhite);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,118 @@
//+------------------------------------------------------------------+
//| PriceMARow.mqh |
//| Marcin Konieczny |
//| |
//+------------------------------------------------------------------+
#property copyright "Marcin Konieczny"
#include <Row.mqh>
//+------------------------------------------------------------------+
//| CPriceMARow class |
//+------------------------------------------------------------------+
class CPriceMARow : public CRow
{
private:
int maPeriod; // period of moving average
int maShift; // shift of moving average
ENUM_MA_METHOD maType; // SMA, EMA, SMMA or LWMA
string symbols[]; // symbols array
ENUM_TIMEFRAMES timeframes[]; // timeframes array
int handles[]; // array of MA handles
//--- finds the indicator handle for a given symbol and timeframe
int GetHandle(string symbol,ENUM_TIMEFRAMES tf);
public:
//--- constructor
CPriceMARow(ENUM_MA_METHOD type,int period,int shift);
//--- overrides default GetValue(..) method of CRow
virtual string GetValue(string symbol,ENUM_TIMEFRAMES tf);
// overrides default GetName() method CRow
virtual string GetName();
//--- overrides default Init(..) method from CRow
virtual void Init(string &symb[],ENUM_TIMEFRAMES &tfs[]);
};
//+------------------------------------------------------------------+
//| CPriceMARow class constructor |
//+------------------------------------------------------------------+
CPriceMARow::CPriceMARow(ENUM_MA_METHOD type,int period,int shift)
{
maPeriod= period;
maShift = shift;
maType=type;
}
//+------------------------------------------------------------------+
//| Overrides default Init(..) method from CRow |
//+------------------------------------------------------------------+
void CPriceMARow::Init(string &symb[],ENUM_TIMEFRAMES &tfs[])
{
int size=ArraySize(symb);
ArrayResize(symbols,size);
ArrayResize(timeframes,size);
ArrayResize(handles,size);
//--- copies arrays contents into own arrays
ArrayCopy(symbols,symb);
ArrayCopy(timeframes,tfs);
//--- gets MA handles for all used symbols or timeframes
for(int i=0; i<ArraySize(symbols); i++)
handles[i]=iMA(symbols[i],timeframes[i],maPeriod,maShift,maType,PRICE_CLOSE);
}
//+------------------------------------------------------------------+
//| Overrides default GetValue(..) method of CRow |
//+------------------------------------------------------------------+
string CPriceMARow::GetValue(string symbol,ENUM_TIMEFRAMES tf)
{
double value[1];
MqlTick tick;
//--- obtains MA indicator handle
int handle=GetHandle(symbol,tf);
if(handle==INVALID_HANDLE) return("err");
//--- gets the last MA value
if(CopyBuffer(handle,0,0,1,value)<0) return("-");
//--- gets the last price
if(!SymbolInfoTick(symbol,tick)) return("-");
//--- checking the condition: price > MA
if(tick.bid>value[0])
return("Yes");
else
return("No");
}
//+------------------------------------------------------------------+
//| Overrides default GetName() method of CRow |
//+------------------------------------------------------------------+
string CPriceMARow::GetName()
{
string name;
switch(maType)
{
case MODE_SMA: name = "SMA"; break;
case MODE_EMA: name = "EMA"; break;
case MODE_SMMA: name = "SMMA"; break;
case MODE_LWMA: name = "LWMA"; break;
}
return("Price>"+name+"("+IntegerToString(maPeriod)+")");
}
//+------------------------------------------------------------------+
//| finds the indicator handle for a given symbol and timeframe |
//+------------------------------------------------------------------+
int CPriceMARow::GetHandle(string symbol,ENUM_TIMEFRAMES tf)
{
for(int i=0; i<ArraySize(timeframes); i++)
if(symbols[i]==symbol && timeframes[i]==tf)
return(handles[i]);
return(INVALID_HANDLE);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,41 @@
//+------------------------------------------------------------------+
//| PriceRow.mqh |
//| Marcin Konieczny |
//| |
//+------------------------------------------------------------------+
#property copyright "Marcin Konieczny"
#include <Row.mqh>
//+------------------------------------------------------------------+
//| CPriceRow class |
//+------------------------------------------------------------------+
class CPriceRow : public CRow
{
public:
//--- overrides default GetValue(..) method from CRow
virtual string GetValue(string symbol,ENUM_TIMEFRAMES tf);
//--- overrides default GetName() method from CRow
virtual string GetName();
};
//+------------------------------------------------------------------+
//| Overrides default GetValue(..) method from CRow |
//+------------------------------------------------------------------+
string CPriceRow::GetValue(string symbol,ENUM_TIMEFRAMES tf)
{
MqlTick tick;
//--- gets current price
if(!SymbolInfoTick(symbol,tick)) return("-");
return(DoubleToString(tick.bid,(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS)));
}
//+------------------------------------------------------------------+
//| Overrides default GetName() method from CRow |
//+------------------------------------------------------------------+
string CPriceRow::GetName()
{
return("Price");
}
//+------------------------------------------------------------------+
@@ -0,0 +1,97 @@
//+------------------------------------------------------------------+
//| RSIRow.mqh |
//| Marcin Konieczny |
//| |
//+------------------------------------------------------------------+
#property copyright "Marcin Konieczny"
#include <Row.mqh>
//+------------------------------------------------------------------+
//| CRSIRow class |
//+------------------------------------------------------------------+
class CRSIRow : public CRow
{
private:
int rsiPeriod; // RSI period
string symbols[]; // symbols array
ENUM_TIMEFRAMES timeframes[]; // timeframes array
int handles[]; // array of RSI handles
//--- finds the indicator handle for a given symbol and timeframe
int GetHandle(string symbol,ENUM_TIMEFRAMES tf);
public:
//--- constructor
CRSIRow(int period);
//--- overrides default GetValue(..) method from CRow
virtual string GetValue(string symbol,ENUM_TIMEFRAMES tf);
//--- overrides default GetName() method from CRow
virtual string GetName();
//--- overrides default Init(..) method from CRow
virtual void Init(string &symb[],ENUM_TIMEFRAMES &tfs[]);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CRSIRow::CRSIRow(int period)
{
rsiPeriod=period;
}
//+------------------------------------------------------------------+
//| Overrides default Init(..) method from CRow |
//+------------------------------------------------------------------+
void CRSIRow::Init(string &symb[],ENUM_TIMEFRAMES &tfs[])
{
int size=ArraySize(symb);
ArrayResize(symbols,size);
ArrayResize(timeframes,size);
ArrayResize(handles,size);
//--- copies arrays contents into own arrays
ArrayCopy(symbols,symb);
ArrayCopy(timeframes,tfs);
//--- gets RSI handles for all used symbols or timeframes
for(int i=0; i<ArraySize(symbols); i++)
handles[i]=iRSI(symbols[i],timeframes[i],rsiPeriod,PRICE_CLOSE);
}
//+------------------------------------------------------------------+
//| Overrides default GetValue(..) method from CRow |
//+------------------------------------------------------------------+
string CRSIRow::GetValue(string symbol,ENUM_TIMEFRAMES tf)
{
double value[1];
//--- gets RSI indicator handle
int handle=GetHandle(symbol,tf);
if(handle==INVALID_HANDLE) return("err");
//--- gets current RSI value
if(CopyBuffer(handle,0,0,1,value)<0) return("-");
return(DoubleToString(value[0],2));
}
//+------------------------------------------------------------------+
//| Overrides default GetName() method from CRow |
//+------------------------------------------------------------------+
string CRSIRow::GetName()
{
return("RSI("+IntegerToString(rsiPeriod)+")");
}
//+------------------------------------------------------------------+
//| finds the indicator handle for a given symbol and timeframe |
//+------------------------------------------------------------------+
int CRSIRow::GetHandle(string symbol,ENUM_TIMEFRAMES tf)
{
for(int i=0; i<ArraySize(timeframes); i++)
if(symbols[i]==symbol && timeframes[i]==tf)
return(handles[i]);
return(INVALID_HANDLE);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,34 @@
//+------------------------------------------------------------------+
//| CRow.mqh |
//| Marcin Konieczny |
//| |
//+------------------------------------------------------------------+
#property copyright "Marcin Konieczny"
#include <Object.mqh>
//+------------------------------------------------------------------+
//| CRow class |
//+------------------------------------------------------------------+
//| Base class for creating custom table rows |
//| one or more methods of CRow should be overriden |
//| when creating own table rows |
//+------------------------------------------------------------------+
class CRow : public CObject
{
public:
//--- default initialization method
virtual void Init(string &symb[],ENUM_TIMEFRAMES &tfs[]) { }
//--- default method for obtaining string value to display in the table cell
virtual string GetValue(string symbol,ENUM_TIMEFRAMES tf) { return("-"); }
//--- default method for obtaining color for table cell
virtual color GetColor(string symbol,ENUM_TIMEFRAMES tf) { return(clrWhite); }
//--- default method for obtaining row name
virtual string GetName() { return("-"); }
//--- default method for obtaining font for table cell
virtual string GetFont(string symbol,ENUM_TIMEFRAMES tf) { return("Arial"); }
};
//+------------------------------------------------------------------+
@@ -0,0 +1,257 @@
//+------------------------------------------------------------------+
//| CTable.mqh |
//| Marcin Konieczny |
//| |
//+------------------------------------------------------------------+
#property copyright "Marcin Konieczny"
#include <Arrays\List.mqh>
#include <Row.mqh>
const string nameBase="Table_Coord#"; // prefix for all label objects used by table
//+------------------------------------------------------------------+
//| CTable class |
//+------------------------------------------------------------------+
class CTable
{
private:
int xDistance; // distance from right border of the chart
int yDistance; // distance from top of the chart
int cellHeight; // table cell height
int cellWidth; // table cell width
string font; // font name
int fontSize;
color fontColor;
CList *rowList; // list of row objects
bool tfMode; // is in multi-timeframe mode?
ENUM_TIMEFRAMES timeframes[]; // array of timeframes for multi-timeframe mode
string symbols[]; // array of currency pairs for multi-currency mode
//--- private methods
//--- sets default parameters of the table
void Init();
//--- draws text label in the specified table cell
void DrawLabel(int x,int y,string text,string font,color col);
//--- returns textual representation of given timeframe
string PeriodToString(ENUM_TIMEFRAMES period);
public:
//--- multi-timeframe mode constructor
CTable(ENUM_TIMEFRAMES &tfs[]);
//--- multi-currency mode constructor
CTable(string &symb[]);
//--- destructor
~CTable();
//--- redraws table
void Update();
//--- methods for setting table parameters
void SetDistance(int xDist,int yDist);
void SetCellSize(int cellW,int cellH);
void SetFont(string fnt,int size,color clr);
//--- appends CRow object to the of the table
void AddRow(CRow *row);
};
//+------------------------------------------------------------------+
//| Multi-timeframe mode constructor |
//+------------------------------------------------------------------+
CTable::CTable(ENUM_TIMEFRAMES &tfs[])
{
//--- copy all timeframes to own array
ArrayResize(timeframes,ArraySize(tfs),0);
ArrayCopy(timeframes,tfs);
tfMode=true;
//--- fill symbols array with current chart symbol
ArrayResize(symbols,ArraySize(tfs),0);
for(int i=0; i<ArraySize(tfs); i++)
symbols[i]=Symbol();
//--- set default parameters
Init();
}
//+------------------------------------------------------------------+
//| Multi-currency mode constructor |
//+------------------------------------------------------------------+
CTable::CTable(string &symb[])
{
//--- copy all symbols to own array
ArrayResize(symbols,ArraySize(symb),0);
ArrayCopy(symbols,symb);
tfMode=false;
//--- fill timeframe array with current timeframe
ArrayResize(timeframes,ArraySize(symb),0);
ArrayInitialize(timeframes,Period());
//--- set default parameters
Init();
//--- send SpyAgents to every requested symbol
for(int x=0; x<ArraySize(symbols); x++)
if(symbols[x]!=Symbol()) // don't send SpyAgent to own chart
if(iCustom(symbols[x],0,"SpyAgent",ChartID(),0)==INVALID_HANDLE)
{
Print("Error in setting of SpyAgent on "+symbols[x]);
return;
}
}
//+------------------------------------------------------------------+
//| Sets default parameters of the table |
//+------------------------------------------------------------------+
CTable::Init()
{
//--- create list for storing row objects
rowList=new CList;
//--- set defaults
xDistance = 10;
yDistance = 10;
cellWidth = 60;
cellHeight= 20;
font="Arial";
fontSize=10;
fontColor=clrWhite;
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CTable::~CTable()
{
int total=ObjectsTotal(0);
//--- remove all text labels from the chart (all object names starting with nameBase prefix)
for(int i=total-1; i>=0; i--)
if(StringFind(ObjectName(0,i),nameBase)!=-1)
ObjectDelete(0,ObjectName(0,i));
//--- delete list of rows and free memory
delete(rowList);
}
//+------------------------------------------------------------------+
//| Appends new row to the end of the table |
//+------------------------------------------------------------------+
CTable::AddRow(CRow *row)
{
rowList.Add(row);
row.Init(symbols,timeframes);
}
//+------------------------------------------------------------------+
//| Redraws the table |
//+------------------------------------------------------------------+
CTable::Update()
{
CRow *row;
string symbol;
ENUM_TIMEFRAMES tf;
int rows=rowList.Total(); // number of rows
int columns; // number of columns
if(tfMode)
columns=ArraySize(timeframes);
else
columns=ArraySize(symbols);
//--- draw first column (names of rows)
for(int y=0; y<rows; y++)
{
row=(CRow*)rowList.GetNodeAtIndex(y);
//--- note: we ask row object to return its name
DrawLabel(columns,y+1,row.GetName(),font,fontColor);
}
//--- draws first row (names of timeframes or currency pairs)
for(int x=0; x<columns; x++)
{
if(tfMode)
DrawLabel(columns-x-1,0,PeriodToString(timeframes[x]),font,fontColor);
else
DrawLabel(columns-x-1,0,symbols[x],font,fontColor);
}
//--- draws inside table cells
for(int y=0; y<rows; y++)
for(int x=0; x<columns; x++)
{
row=(CRow*)rowList.GetNodeAtIndex(y);
if(tfMode)
{
//--- in multi-timeframe mode use current symbol and different timeframes
tf=timeframes[x];
symbol=_Symbol;
}
else
{
//--- in multi-currency mode use current timeframe and different symbols
tf=Period();
symbol=symbols[x];
}
//--- note: we ask row object to return its font,
//--- color and current calculated value for given timeframe and symbol
DrawLabel(columns-x-1,y+1,row.GetValue(symbol,tf),row.GetFont(symbol,tf),row.GetColor(symbol,tf));
}
//--- forces chart to redraw
ChartRedraw();
}
//+------------------------------------------------------------------+
//| Draws text label in the specified cell of the table |
//+------------------------------------------------------------------+
CTable::DrawLabel(int x,int y,string text,string font,color col)
{
//--- create unique name for this cell
string name=nameBase+IntegerToString(x)+":"+IntegerToString(y);
//--- create label
if(ObjectFind(0,name)<0)
ObjectCreate(0,name,OBJ_LABEL,0,0,0);
//--- set label properties
ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_RIGHT_UPPER);
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,xDistance+x*cellWidth);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,yDistance+y*cellHeight);
ObjectSetString(0,name,OBJPROP_FONT,font);
ObjectSetInteger(0,name,OBJPROP_COLOR,col);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontSize);
//--- set label text
ObjectSetString(0,name,OBJPROP_TEXT,text);
}
//+------------------------------------------------------------------+
//| Sets cell size |
//+------------------------------------------------------------------+
CTable::SetCellSize(int cellW,int cellH)
{
cellWidth=cellW;
cellHeight=cellH;
}
//+------------------------------------------------------------------+
//| Sets font |
//+------------------------------------------------------------------+
CTable::SetFont(string fnt,int size,color clr)
{
font=fnt;
fontSize=size;
fontColor=clr;
}
//+------------------------------------------------------------------+
//| Sets distance |
//+------------------------------------------------------------------+
CTable::SetDistance(int xDist,int yDist)
{
xDistance = xDist;
yDistance = yDist;
}
//+------------------------------------------------------------------+
//| Converts ENUM_TIMEFRAMES to string |
//+------------------------------------------------------------------+
string CTable::PeriodToString(ENUM_TIMEFRAMES period)
{
return(StringSubstr(EnumToString(period),7));
}
//+------------------------------------------------------------------+
@@ -0,0 +1,28 @@
//+------------------------------------------------------------------+
//| SpyAgent.mq5 |
//| Marcin Konieczny |
//| |
//+------------------------------------------------------------------+
#property copyright "Marcin Konieczny"
#property indicator_chart_window
#property indicator_plots 0
input long chart_id=0; // chart id
input ushort custom_event_id=0; // event id
//+------------------------------------------------------------------+
//| Indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
if(prev_calculated==0)
EventChartCustom(chart_id,0,0,0.0,_Symbol); // sends initialization event
else
EventChartCustom(chart_id,(ushort)(custom_event_id+1),0,0.0,_Symbol); // sends new tick event
return(rates_total);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,79 @@
//+------------------------------------------------------------------+
//| TableSample.mq5 |
//| Marcin Konieczny |
//| |
//+------------------------------------------------------------------+
#property copyright "Marcin Konieczny"
#property version "1.00"
#property indicator_chart_window
#property indicator_plots 0
#include <Table.mqh>
#include <PriceRow.mqh>
#include <PriceChangeRow.mqh>
#include <RSIRow.mqh>
#include <PriceMARow.mqh>
CTable *table; // pointer to CTable object
//+------------------------------------------------------------------+
//| Indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- timeframes used in table (in multi-timeframe mode)
ENUM_TIMEFRAMES timeframes[4]={PERIOD_M1,PERIOD_H1,PERIOD_D1,PERIOD_W1};
//--- symbols used in table (in multi-currency mode)
string symbols[4]={"EURUSD","GBPUSD","USDJPY","AUDCHF" };
//-- CTable object creation
// table = new CTable(timeframes); // multi-timeframe mode
table=new CTable(symbols); // multi-currency mode
//--- adding rows to the table
table.AddRow(new CPriceRow()); // shows current price
table.AddRow(new CPriceChangeRow(false)); // shows change of price in the last bar
table.AddRow(new CPriceChangeRow(false,true)); // shows percent change of price in the last bar
table.AddRow(new CPriceChangeRow(true)); // shows change of price as arrows
table.AddRow(new CRSIRow(14)); // shows RSI(14)
table.AddRow(new CRSIRow(10)); // shows RSI(10)
table.AddRow(new CPriceMARow(MODE_SMA,20,0)); // shows if SMA(20) > current price
//--- setting table parameters
table.SetFont("Arial",10,clrYellow); // font, size, color
table.SetCellSize(60, 20); // width, height
table.SetDistance(10, 10); // distance from upper right chart corner
table.Update(); // forces table to redraw
return(0);
}
//+------------------------------------------------------------------+
//| Indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- calls table destructor and frees memory
delete(table);
}
//+------------------------------------------------------------------+
//| Indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- update table: recalculate/repaint
table.Update();
return(rates_total);
}
//+------------------------------------------------------------------+
//| OnChartEvent handler |
//| Handles CHARTEVENT_CUSTOM events sent by SpyAgent indicators |
//| Nedeed only in multi-currency mode! |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
table.Update(); // update table: recalculate/repaint
}
//+------------------------------------------------------------------+