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
+376
View File
@@ -0,0 +1,376 @@
//---------------------------------------------------------------------
#property copyright "Dima S., 2010 ã."
#property link "dimascub@mail.com"
#property version "1.01"
#property description "Market Watch"
//---------------------------------------------------------------------
#property indicator_chart_window
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Version history:
//---------------------------------------------------------------------
// 11.10.2010. - V1.00
// - FIRST RELEASE;
//
// 20.10.2010. - V1.01
// - ADDED - parameters for vertical and horizontal shift of the table;
//
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Include libraries:
//---------------------------------------------------------------------
#include <MarketWatch.mqh>
//---------------------------------------------------------------------
//=====================================================================
// External input parameters:
//=====================================================================
input string CurrencylList = "EURUSD; GBPUSD; EURGBP; AUDUSD; NZDUSD; AUDNZD; USDJPY; USDCHF; USDCAD; EURJPY; GBPJPY; AUDJPY; NZDJPY; CHFJPY; CADJPY; XAUUSD;";
input string TimeFrameList = "H1; H4; D1; MN";
input int UpDownBorderShift=1;
input int LeftRightBorderShift=1;
input color TitlesColor=LightCyan;
//---------------------------------------------------------------------
//---------------------------------------------------------------------
string Symbol_Array[ ]; // list of symbols
string TimeFrame_Array[ ]; // list of timeframes
ENUM_TIMEFRAMES TFs[];
string Titles_Array[]={ "Bid:","Spread:","StopLev:","ToOpen:","Hi-Lo:","DailyAv:" };
//---------------------------------------------------------------------
//---------------------------------------------------------------------
SymbolWatchDisplay *Watches[];
TableDisplay TitlesDisplay;
//---------------------------------------------------------------------
//---------------------------------------------------------------------
int currencies_count;
int timeframes_count;
bool is_first_init=true;
//---------------------------------------------------------------------
#define WIDTH 128
#define HEIGHT 128
#define FONTSIZE 10
//---------------------------------------------------------------------
// OnInit event handler
//---------------------------------------------------------------------
int OnInit()
{
// List of symbols:
currencies_count=StringToArrayString(CurrencylList,Symbol_Array);
if(currencies_count>16)
{
currencies_count=16;
}
// List of timeframes:
timeframes_count=StringToArrayString(TimeFrameList,TimeFrame_Array);
ArrayResize(TFs,timeframes_count);
for(int k=0; k<timeframes_count; k++)
{
TFs[k]=get_timeframe_from_string(TimeFrame_Array[k]);
}
if(is_first_init!=true)
{
DeleteGraphObjects();
}
InitGraphObjects();
is_first_init=false;
RefreshInfo();
EventSetTimer(1);
ChartRedraw(0);
return(0);
}
//---------------------------------------------------------------------
// OnCalculate event handler
//---------------------------------------------------------------------
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
return(rates_total);
}
//---------------------------------------------------------------------
// OnTimer event handler
//---------------------------------------------------------------------
void OnTimer()
{
RefreshInfo();
ChartRedraw(0);
}
//---------------------------------------------------------------------
// OnDeinit event handler
//---------------------------------------------------------------------
void OnDeinit(const int _reason)
{
EventKillTimer();
DeleteGraphObjects();
}
//---------------------------------------------------------------------
// Initialization of graphic objects
//---------------------------------------------------------------------
void InitGraphObjects()
{
//Print( "Creating..." );
// Titles
TitlesDisplay.SetParams(0,0,CORNER_LEFT_UPPER);
for(int k=0; k<3; k++)
{
TitlesDisplay.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + 5, UpDownBorderShift + k * 2 + 5, Titles_Array[ k ], TitlesColor, "Arial", FONTSIZE );
TitlesDisplay.SetAnchor( k, ANCHOR_RIGHT );
}
TitlesDisplay.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + 5, UpDownBorderShift + 12, Titles_Array[ 3 ], TitlesColor, "Arial", 10 );
TitlesDisplay.SetAnchor( 3, ANCHOR_RIGHT );
for(int k=4; k<6; k++)
{
TitlesDisplay.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + 5, UpDownBorderShift + 2 * k + 7, Titles_Array[ k ], TitlesColor, "Arial", FONTSIZE );
TitlesDisplay.SetAnchor( k, ANCHOR_RIGHT );
}
// Timeframes
for(int k=0; k<timeframes_count; k++)
{
TitlesDisplay.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + 5, UpDownBorderShift + k * 2 + 20, TimeFrame_Array[ k ] + "%:", TitlesColor, "Arial", FONTSIZE );
TitlesDisplay.SetAnchor( 6 + k, ANCHOR_RIGHT );
}
ArrayResize(Watches,currencies_count);
for(int i=0; i<currencies_count; i++)
{
// Creating Symbol Watch for every symbol:
Watches[i]=new SymbolWatchDisplay();
Watches[i].Create(Symbol_Array[i],0,0,WIDTH,HEIGHT,UpDownBorderShift,LeftRightBorderShift+6+i*7,get_currency_color(Symbol_Array[i]),TFs);
}
}
//---------------------------------------------------------------------
// Delete graphic objects
//---------------------------------------------------------------------
void DeleteGraphObjects()
{
//Print( "Delete..." );
TitlesDisplay.Clear();
for(int i=0; i<currencies_count; i++)
{
if(CheckPointer(Watches[i])!=POINTER_INVALID)
{
// Delete element for one symbol:
delete(Watches[i]);
}
}
}
//---------------------------------------------------------------------
// Refresh symbol information:
//---------------------------------------------------------------------
void RefreshInfo()
{
for(int i=0; i<currencies_count; i++)
{
Watches[ i ].RefreshSymbolInfo( );
Watches[ i ].RedrawSymbolInfo( );
}
}
//+----------------------------------------------------------------------------+
//| Author : Kim Igor aka KimIV, http://www.kimiv.ru |
//! Modified : Dima S., 2010 ã. !
//+----------------------------------------------------------------------------+
//| Version : 10.10.2008 |
//| Descr. : It parses the string with words into the array |
//+----------------------------------------------------------------------------+
//| Parameters: |
//| st - string with words, separated with specified delimiter |
//| ad - array of words |
//+----------------------------------------------------------------------------+
//| Returned value: |
//| Number of elements in array |
//+----------------------------------------------------------------------------+
int StringToArrayString(string st,string &ad[],string _delimiter=";")
{
int i=0,np;
string stp;
ArrayResize(ad,0);
while(StringLen(st)>0)
{
np=StringFind(st,_delimiter);
if(np<0)
{
stp= st;
st = "";
}
else
{
stp= StringSubstr(st,0,np);
st = StringSubstr(st,np+1);
}
i++;
ArrayResize(ad,i);
StringTrimLeft(stp);
ad[i-1]=stp;
}
return(ArraySize(ad));
}
//---------------------------------------------------------------------
// Get color depending on symbol
//---------------------------------------------------------------------
color get_currency_color(string _currency)
{
int i;
for(i=0; i<currencies_count; i++)
{
if(StringFind(Symbol_Array[i],_currency)!=-1)
{
if(StringFind(_currency,"GOLD")!=-1)
{
return(Gold);
}
else if(StringFind(_currency,"XAU")!=-1)
{
return(Gold);
}
else if(StringFind(_currency,"JPY")!=-1)
{
return(NavajoWhite);
}
else if(StringFind(_currency,"EUR")!=-1)
{
return(DeepSkyBlue);
}
else if(StringFind(_currency,"GBP")!=-1)
{
return(DeepSkyBlue);
}
else if(StringFind(_currency,"QM")!=-1)
{
return(Brown);
}
else if(StringFind(_currency,"ES")!=-1)
{
return(LightSalmon);
}
else if(StringFind(_currency,"NQ")!=-1)
{
return(LightSalmon);
}
else if(StringFind(_currency,"CHF")!=-1)
{
return(SpringGreen);
}
else if(StringFind(_currency,"CAD")!=-1)
{
return(SpringGreen);
}
else if(StringFind(_currency,"AUD")!=-1)
{
return(GreenYellow);
}
else if(StringFind(_currency,"NZD")!=-1)
{
return(GreenYellow);
}
return(Silver);
}
}
return(Silver);
}
//---------------------------------------------------------------------
// Converts string with timeframe into integer value
//---------------------------------------------------------------------
ENUM_TIMEFRAMES get_timeframe_from_string(string _str)
{
if(_str=="M1")
{
return(PERIOD_M1);
}
if(_str=="M2")
{
return(PERIOD_M2);
}
if(_str=="M3")
{
return(PERIOD_M3);
}
if(_str=="M4")
{
return(PERIOD_M4);
}
if(_str=="M5")
{
return(PERIOD_M5);
}
if(_str=="M6")
{
return(PERIOD_M6);
}
if(_str=="M10")
{
return(PERIOD_M10);
}
if(_str=="M12")
{
return(PERIOD_M12);
}
if(_str=="M15")
{
return(PERIOD_M15);
}
if(_str=="M20")
{
return(PERIOD_M20);
}
if(_str=="M30")
{
return(PERIOD_M30);
}
if(_str=="H1")
{
return(PERIOD_H1);
}
if(_str=="H2")
{
return(PERIOD_H2);
}
if(_str=="H3")
{
return(PERIOD_H3);
}
if(_str=="H4")
{
return(PERIOD_H4);
}
if(_str=="H6")
{
return(PERIOD_H6);
}
if(_str=="H8")
{
return(PERIOD_H8);
}
if(_str=="H12")
{
return(PERIOD_H12);
}
if(_str=="D1")
{
return(PERIOD_D1);
}
if(_str=="W1")
{
return(PERIOD_W1);
}
if(_str=="MN1")
{
return(PERIOD_MN1);
}
return(PERIOD_D1);
}
//+------------------------------------------------------------------+
+270
View File
@@ -0,0 +1,270 @@
//=====================================================================
// A library for Market Watch on the chart
//=====================================================================
//---------------------------------------------------------------------
#property copyright "Dima S., 2010 ã."
#property link "dimascub@mail.com"
//---------------------------------------------------------------------
// Include libraries
//---------------------------------------------------------------------
#include <TextDisplay.mqh>
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// SymbolWatchDisplay class
//---------------------------------------------------------------------
class SymbolWatchDisplay : public TableDisplay
{
private:
string symbol; // symbol
double point;
int digits;
double point_multiplier; // conversion coefficient for 3/5 digits
private:
MqlTick curr_tick; // current ticl
datetime times;
double prev_bid;
MqlRates D1_rates[ ]; // daily rates
MqlRates TF_rates[ ]; // bars of the current timeframe
private:
ENUM_TIMEFRAMES time_frames[];
private:
double curr_HiLo; // current daily range
double curr_AvD; // average daily range
private:
int up_down_shift; // Y coordinate
int left_right_shift; // X coordinate
public:
void RefreshSymbolInfo(); // Refresh symbol info
void SymbolWatchDisplay();
void ~SymbolWatchDisplay();
bool Create(string _symbol,long _chart_id,int _window,int _cols,int _lines,int _ud_shift,int _lr_shift,color _ttl,ENUM_TIMEFRAMES &_tfs[]);
void RedrawSymbolInfo(); // Redraw information
};
//---------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------
void SymbolWatchDisplay::SymbolWatchDisplay()
{
this.symbol=NULL;
this.up_down_shift=0;
this.left_right_shift=0;
this.curr_HiLo= 0.0;
this.curr_AvD = 0.0;
this.times=0;
this.prev_bid=0.0;
}
//---------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------
void SymbolWatchDisplay::~SymbolWatchDisplay()
{
//// this.Clear( );
}
//---------------------------------------------------------------------
// Refresh information
//---------------------------------------------------------------------
void SymbolWatchDisplay::RedrawSymbolInfo()
{
// Get tick data
ResetLastError();
if(SymbolInfoTick(this.symbol,this.curr_tick)!=true)
{
this.SetText( 0, "Err " + DoubleToString( GetLastError( ), 0 ));
this.SetColor( 0, Yellow );
this.SetText( 1, "" );
this.SetText( 2, "" );
this.SetText( 3, "" );
this.SetText( 4, "" );
this.SetText( 5, "" );
for(int k=0; k<ArraySize(this.time_frames); k++)
{
this.SetText(k+6,"");
}
return;
}
// If data has changed (or it's the first call), show them:
if(this.curr_tick.time>this.times || this.times==0)
{
this.SetText(0,DoubleToString(this.curr_tick.bid,digits));
if(this.curr_tick.bid>this.prev_bid && this.prev_bid>0.1)
{
this.SetColor(0,Lime);
}
else if(this.curr_tick.bid<this.prev_bid && this.prev_bid>0.1)
{
this.SetColor(0,Red);
}
else
{
this.SetColor(0,Yellow);
}
this.prev_bid=this.curr_tick.bid;
this.times=this.curr_tick.time;
}
this.SetText( 1, DoubleToString( this.point_multiplier * ( this.curr_tick.ask - this.curr_tick.bid ) / this.point, 1 ));
this.SetText( 2, DoubleToString( this.point_multiplier * SymbolInfoInteger( this.symbol, SYMBOL_TRADE_STOPS_LEVEL ), 1 ));
// get daily bars
if(CopyRates(this.symbol,PERIOD_D1,0,21,this.D1_rates)!=21)
{
this.SetText( 3, "loading.." );
this.SetColor( 3, Yellow );
this.SetText( 4, "loading.." );
this.SetColor( 4, Yellow );
this.SetText( 5, "loading.." );
this.SetColor( 5, Yellow );
return;
}
// calculate points from the open price
if(this.D1_rates[20].close>this.D1_rates[20].open)
{
this.SetColor( 3, Lime );
this.SetText( 3, DoubleToString( this.point_multiplier * ( this.D1_rates[ 20 ].close - this.D1_rates[ 20 ].open ) / this.point, 1 ));
}
else if(D1_rates[20].close<D1_rates[20].open)
{
this.SetColor( 3, Red );
this.SetText( 3, DoubleToString( this.point_multiplier * ( this.D1_rates[ 20 ].open - this.D1_rates[ 20 ].close ) / this.point, 1 ));
}
else
{
this.SetText( 3, "0.0" );
this.SetColor( 3, Yellow );
}
// current daily range
this.SetText( 4, DoubleToString( this.point_multiplier * ( this.D1_rates[ 20 ].high - this.D1_rates[ 20 ].low ) / this.point, 1 ));
this.SetColor( 4, PowderBlue );
// Average daily range
double av,av_20=0.0,av_10=0.0,av_5=0.0,av_1;
for(int i=0; i<20; i++)
{
av_20+=this.D1_rates[i].high-this.D1_rates[i].low;
}
for(int i=10; i<20; i++)
{
av_10+=this.D1_rates[i].high-this.D1_rates[i].low;
}
for(int i=15; i<20; i++)
{
av_5+=this.D1_rates[i].high-this.D1_rates[i].low;
}
av_1=this.D1_rates[19].high-this.D1_rates[19].low;
av =(av_1+av_5/ 5.0+av_10/ 10.0+av_20/ 20.0)/ 4.0;
av/=(this.point);
this.SetText( 5, DoubleToString( this.point_multiplier * av, 1 ));
this.SetColor( 5, LightGoldenrod );
// Get bars on the current timeframe
for(int k=0; k<ArraySize(this.time_frames); k++)
{
if(CopyRates(this.symbol,this.time_frames[k],0,1,this.TF_rates)!=1)
{
this.SetText( k + 6, "loading.." );
this.SetColor( k + 6, Yellow );
continue;
}
double dev=100.0 *(this.TF_rates[0].close-this.TF_rates[0].open)/this.TF_rates[0].open;
if(dev>0.0005)
{
this.SetText( k + 6, "+" + DoubleToString( dev, 3 ));
this.SetColor( k + 6, PaleGreen );
}
else if(dev<-0.0005)
{
this.SetText( k + 6, " " + DoubleToString( dev, 3 ));
this.SetColor( k + 6, Pink );
}
else
{
this.SetText( k + 6, " " + DoubleToString( 0.0, 3 ));
this.SetColor( k + 6, Silver );
}
}
}
//---------------------------------------------------------------------
// Create graphic object
//---------------------------------------------------------------------
bool SymbolWatchDisplay::Create(string _symbol,long _chart_id,int _window,int _cols,int _lines,int _ud_shift,int _lr_shift,color _ttl,ENUM_TIMEFRAMES &_tfs[])
{
this.symbol=_symbol;
this.up_down_shift=_ud_shift;
this.left_right_shift=_lr_shift;
this.RefreshSymbolInfo( );
this.SetParams( _chart_id, _window, CORNER_LEFT_UPPER );
ArrayResize(this.time_frames,ArraySize(_tfs));
for(int i=0; i<ArraySize(_tfs); i++)
{
this.time_frames[i]=_tfs[i];
}
// Price
this.AddFieldObject( _cols, _lines, this.left_right_shift, this.up_down_shift + 5, Gold, "Arial", 10 );
this.SetAnchor( 0, ANCHOR_LEFT );
// Spread
this.AddFieldObject( _cols, _lines, this.left_right_shift, this.up_down_shift + 7, Gold, "Arial", 10 );
this.SetAnchor( 1, ANCHOR_LEFT );
// Stop level
this.AddFieldObject( _cols, _lines, this.left_right_shift, this.up_down_shift + 9, Gold, "Arial", 10 );
this.SetAnchor( 2, ANCHOR_LEFT );
// Points from open price
this.AddFieldObject( _cols, _lines, this.left_right_shift, this.up_down_shift + 12, PowderBlue, "Arial", 10 );
this.SetAnchor( 3, ANCHOR_LEFT );
// Daily range
this.AddFieldObject( _cols, _lines, this.left_right_shift, this.up_down_shift + 15, PowderBlue, "Arial", 10 );
this.SetAnchor( 4, ANCHOR_LEFT );
// Average daily range
this.AddFieldObject( _cols, _lines, this.left_right_shift, this.up_down_shift + 17, LightGoldenrod, "Arial", 10 );
this.SetAnchor( 5, ANCHOR_LEFT );
// Percent change
for(int k=0; k<ArraySize(this.time_frames); k++)
{
this.AddFieldObject( _cols, _lines, this.left_right_shift, this.up_down_shift + 20 + 2 * k, PowderBlue, "Arial", 10 );
this.SetAnchor( k + 6, ANCHOR_LEFT );
}
// Title (symbol)
this.AddTitleObject( _cols, _lines, this.left_right_shift, this.up_down_shift + 2, this.symbol, _ttl, "Arial", 10 );
this.SetAnchor( ArraySize( this.time_frames ) + 6, ANCHOR_LEFT );
return(true);
}
//---------------------------------------------------------------------
// Refresh information on symbol
//---------------------------------------------------------------------
void SymbolWatchDisplay::RefreshSymbolInfo()
{
this.point=SymbolInfoDouble(this.symbol,SYMBOL_POINT);
this.digits=(int)SymbolInfoInteger(this.symbol,SYMBOL_DIGITS);
// 5/3 digits coefficient
if(this.digits==5 || this.digits==3)
{
this.point_multiplier=0.1;
}
else
{
this.point_multiplier=1.0;
}
}
//---------------------------------------------------------------------
+229
View File
@@ -0,0 +1,229 @@
//---------------------------------------------------------------------
#property copyright "Dima S., 2010 ã."
#property link "dimascub@mail.com"
#property version "1.00"
#property description "Îòîáðàæåíèå ïàðàìåòðîâ ñèìâîëà"
//---------------------------------------------------------------------
#property indicator_chart_window
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Version History
//---------------------------------------------------------------------
// 11.10.2010ã. - V1.00
// - FIRST RELEASE;
//
// 20.10.2010ã. - V1.01
// - ADDED - setting angle for table output;
// - ADDED - horizontal and vertical shift of the table;
//
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Include library
//---------------------------------------------------------------------
#include <TextDisplay.mqh>
//---------------------------------------------------------------------
//=====================================================================
// External input parameters
//=====================================================================
input ENUM_BASE_CORNER Corner=CORNER_RIGHT_UPPER;
input int UpDownBorderShift=1;
input int LeftRightBorderShift=1;
input color TitlesColor=LightCyan;
//---------------------------------------------------------------------
//---------------------------------------------------------------------
TableDisplay Table1;
//---------------------------------------------------------------------
#define NUMBER 6
//---------------------------------------------------------------------
string titles[]={ "Spread:","Stop Level:","Pips to Open:","Hi to Lo:","Daily Av:" };
int c1_coord_y[ NUMBER ] = { 1, 3, 4, 6, 7, 8 };
int c2_coord_y[ NUMBER ] = { 9, 7, 6, 4, 3, 2 };
int c1_coord_x[ NUMBER ] = { 2, 4, 4, 4, 4, 4 };
int c2_coord_x[ NUMBER ] = { 4, 2, 2, 2, 2, 2 };
//---------------------------------------------------------------------
double rates= 0.0;
datetime times = 0;
MqlTick tick;
MqlRates bars[6];
//---------------------------------------------------------------------
#define WIDTH 50
#define HEIGHT 60
#define FONTSIZE 12
//---------------------------------------------------------------------
// OnInit event handler
//---------------------------------------------------------------------
int OnInit()
{
// Create table
Table1.SetParams(0,0,Corner);
// Show prices
for(int i=0; i<NUMBER; i++)
{
if(Corner==CORNER_LEFT_UPPER)
{
Table1.AddFieldObject( WIDTH, HEIGHT, LeftRightBorderShift + c1_coord_x[ i ] + 2, UpDownBorderShift + c1_coord_y[ i ], Gold, "Arial", FONTSIZE );
Table1.SetAnchor( i, ANCHOR_RIGHT );
}
else if(Corner==CORNER_LEFT_LOWER)
{
Table1.AddFieldObject( WIDTH, HEIGHT, LeftRightBorderShift + c1_coord_x[ i ] + 2, UpDownBorderShift + c2_coord_y[ i ], Gold, "Arial", FONTSIZE );
Table1.SetAnchor( i, ANCHOR_RIGHT );
}
else if(Corner==CORNER_RIGHT_UPPER)
{
Table1.AddFieldObject( WIDTH, HEIGHT, LeftRightBorderShift + c2_coord_x[ i ] - 2, UpDownBorderShift + c1_coord_y[ i ], Gold, "Arial", FONTSIZE );
Table1.SetAnchor( i, ANCHOR_RIGHT );
}
else if(Corner==CORNER_RIGHT_LOWER)
{
Table1.AddFieldObject( WIDTH, HEIGHT, LeftRightBorderShift + c2_coord_x[ i ] - 2, UpDownBorderShift + c2_coord_y[ i ], Gold, "Arial", FONTSIZE );
Table1.SetAnchor( i, ANCHOR_RIGHT );
}
else
{
Table1.AddFieldObject( WIDTH, HEIGHT, LeftRightBorderShift + c1_coord_x[ i ] + 2, UpDownBorderShift + c1_coord_y[ i ], Gold, "Arial", FONTSIZE );
Table1.SetAnchor( i, ANCHOR_RIGHT );
}
}
Table1.SetFont( 0, "Arial", 20 );
Table1.SetAnchor( 0, ANCHOR_CENTER );
// Show headers
for(int i=1; i<NUMBER; i++)
{
if(Corner==CORNER_LEFT_UPPER)
{
Table1.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + c1_coord_x[ i ], UpDownBorderShift + c1_coord_y[ i ], titles[ i - 1 ], TitlesColor, "Arial", FONTSIZE );
Table1.SetAnchor( NUMBER + i - 1, ANCHOR_RIGHT );
}
else if(Corner==CORNER_LEFT_LOWER)
{
Table1.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + c1_coord_x[ i ], UpDownBorderShift + c2_coord_y[ i ], titles[ i - 1 ], TitlesColor, "Arial", FONTSIZE );
Table1.SetAnchor( NUMBER + i - 1, ANCHOR_RIGHT );
}
else if(Corner==CORNER_RIGHT_UPPER)
{
Table1.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + c2_coord_x[ i ], UpDownBorderShift + c1_coord_y[ i ], titles[ i - 1 ], TitlesColor, "Arial", FONTSIZE );
Table1.SetAnchor( NUMBER + i - 1, ANCHOR_RIGHT );
}
else if(Corner==CORNER_RIGHT_LOWER)
{
Table1.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + c2_coord_x[ i ], UpDownBorderShift + c2_coord_y[ i ], titles[ i - 1 ], TitlesColor, "Arial", FONTSIZE );
Table1.SetAnchor( NUMBER + i - 1, ANCHOR_RIGHT );
}
else
{
Table1.AddTitleObject( WIDTH, HEIGHT, LeftRightBorderShift + c1_coord_x[ i ], UpDownBorderShift + c2_coord_y[ i ], titles[ i - 1 ], TitlesColor, "Arial", FONTSIZE );
Table1.SetAnchor( NUMBER + i - 1, ANCHOR_RIGHT );
}
}
RefreshInfo();
ChartRedraw(0);
EventSetTimer(1);
return(0);
}
//---------------------------------------------------------------------
// OnCalculate event handler
//---------------------------------------------------------------------
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
return(rates_total);
}
//---------------------------------------------------------------------
// OnTimer event handler
//---------------------------------------------------------------------
void OnTimer()
{
RefreshInfo();
ChartRedraw(0);
}
//---------------------------------------------------------------------
// OnDeInit event handler
//---------------------------------------------------------------------
void OnDeinit(const int _reason)
{
EventKillTimer();
// Delete table
Table1.Clear();
}
//---------------------------------------------------------------------
// Refresh info
//---------------------------------------------------------------------
void RefreshInfo()
{
// Get price data
ResetLastError();
if(SymbolInfoTick(Symbol(),tick)!=true)
{
Table1.SetText( 0, "Err " + DoubleToString( GetLastError( ), 0 ));
Table1.SetColor( 0, Yellow );
return;
}
// If the data has changed, show the recent values
if(tick.time>times || times==0)
{
Table1.SetText(0,DoubleToString(tick.bid,(int)(SymbolInfoInteger(Symbol(),SYMBOL_DIGITS))));
if(tick.bid>rates && rates>0.1)
{
Table1.SetColor(0,Lime);
}
else if(tick.bid<rates && rates>0.1)
{
Table1.SetColor(0,Red);
}
else
{
Table1.SetColor(0,Yellow);
}
rates = tick.bid;
times = tick.time;
}
Table1.SetText( 1, DoubleToString(( tick.ask - tick.bid ) / SymbolInfoDouble( Symbol( ), SYMBOL_POINT ), 0 ));
Table1.SetText( 2, DoubleToString( SymbolInfoInteger( Symbol( ), SYMBOL_TRADE_STOPS_LEVEL ), 0 ));
CopyRates(Symbol(),PERIOD_D1,0,6,bars);
// Points from day open price
if(bars[5].close>bars[5].open)
{
Table1.SetColor( 3, Lime );
Table1.SetText( 3, DoubleToString(( bars[ 5 ].close - bars[ 5 ].open ) / SymbolInfoDouble( Symbol( ), SYMBOL_POINT ), 0 ));
}
else if(bars[5].close<bars[5].open)
{
Table1.SetColor( 3, Red );
Table1.SetText( 3, DoubleToString(( bars[ 5 ].open - bars[ 5 ].close ) / SymbolInfoDouble( Symbol( ), SYMBOL_POINT ), 0 ));
}
else
{
Table1.SetText( 3, "0" );
Table1.SetColor( 3, Yellow );
}
// Current daily range
Table1.SetText(4,DoubleToString(( bars[5].high-bars[5].low)/SymbolInfoDouble(Symbol(),SYMBOL_POINT),0));
// Price range averaged (previous 5 days)
double av=0.0;
for(int i=0; i<5; i++)
{
av+=bars[i].high-bars[i].low;
}
av/=(SymbolInfoDouble(Symbol(),SYMBOL_POINT)*5.0);
Table1.SetText(5,DoubleToString(av,0));
}
//+------------------------------------------------------------------+
+208
View File
@@ -0,0 +1,208 @@
//---------------------------------------------------------------------
#property copyright "Dima S., 2010 ã."
#property link "dimascub@mail.com"
#property version "1.01"
#property description "Èíäèêàòîð äëÿ ïðîâåðêè ðàáîòû áèáëèîòåêè TextDisplay."
//---------------------------------------------------------------------
#property indicator_chart_window
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Version history
//---------------------------------------------------------------------
// 07.10.2010ã. - V1.00
// - FIRST RELEASE
//
// 20.10.2010ã. - V1.01
// - ADDED - setting angle for table output;
// - ADDED - horizontal and vertical shift of the table;
//
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Include libraries
//---------------------------------------------------------------------
#include <TextDisplay.mqh>
//---------------------------------------------------------------------
//=====================================================================
// External input parameters
//=====================================================================
input ENUM_BASE_CORNER Corner=CORNER_LEFT_UPPER;
input int UpDownBorderShift=2;
input int LeftRightBorderShift=1;
input color TitlesColor=White;
//---------------------------------------------------------------------
//---------------------------------------------------------------------
TableDisplay Table1;
//---------------------------------------------------------------------
#define NUMBER 8
//---------------------------------------------------------------------
string names[NUMBER]={ "EURUSD","GBPUSD","AUDUSD","NZDUSD","USDCHF","USDCAD","USDJPY","EURJPY" };
int c1_coord_y[ NUMBER ] = { 0, 1, 2, 3, 4, 5, 6, 7 };
int c2_coord_y[ NUMBER ] = { 7, 6, 5, 4, 3, 2, 1, 0 };
//---------------------------------------------------------------------
double rates[NUMBER];
datetime times[NUMBER];
MqlTick tick;
//---------------------------------------------------------------------
// Îáðàáîò÷èê ñîáûòèÿ èíèöèàëèçàöèè:
//---------------------------------------------------------------------
int OnInit()
{
ArrayInitialize(times,0);
ArrayInitialize(rates,0);
// Create table
Table1.SetParams(0,0,Corner);
// Show prices
for(int i=0; i<NUMBER; i++)
{
if(Corner==CORNER_LEFT_UPPER)
{
Table1.AddFieldObject(40,40,LeftRightBorderShift+2,UpDownBorderShift+c1_coord_y[i],Yellow);
}
else if(Corner==CORNER_LEFT_LOWER)
{
Table1.AddFieldObject(40,40,LeftRightBorderShift+2,UpDownBorderShift+c2_coord_y[i],Yellow);
}
else if(Corner==CORNER_RIGHT_UPPER)
{
Table1.AddFieldObject(40,40,LeftRightBorderShift+2,UpDownBorderShift+c1_coord_y[i],Yellow);
}
else if(Corner==CORNER_RIGHT_LOWER)
{
Table1.AddFieldObject(40,40,LeftRightBorderShift+2,UpDownBorderShift+c2_coord_y[i],Yellow);
}
else
{
Table1.AddFieldObject(40,40,LeftRightBorderShift+2,UpDownBorderShift+c1_coord_y[i],Yellow);
}
}
// Show spreads
for(int i=0; i<NUMBER; i++)
{
if(Corner==CORNER_LEFT_UPPER)
{
Table1.AddFieldObject(40,40,LeftRightBorderShift+4,UpDownBorderShift+c1_coord_y[i],Yellow);
}
else if(Corner==CORNER_LEFT_LOWER)
{
Table1.AddFieldObject(40,40,LeftRightBorderShift+4,UpDownBorderShift+c2_coord_y[i],Yellow);
}
else if(Corner==CORNER_RIGHT_UPPER)
{
Table1.AddFieldObject(40,40,LeftRightBorderShift,UpDownBorderShift+c1_coord_y[i],Yellow);
}
else if(Corner==CORNER_RIGHT_LOWER)
{
Table1.AddFieldObject(40,40,LeftRightBorderShift,UpDownBorderShift+c2_coord_y[i],Yellow);
}
else
{
Table1.AddFieldObject(40,40,LeftRightBorderShift+4,UpDownBorderShift+c1_coord_y[i],Yellow);
}
}
// Show headers
for(int i=0; i<NUMBER; i++)
{
if(Corner==CORNER_LEFT_UPPER)
{
Table1.AddTitleObject(40,40,LeftRightBorderShift,UpDownBorderShift+c1_coord_y[i],names[i]+":",TitlesColor);
}
else if(Corner==CORNER_LEFT_LOWER)
{
Table1.AddTitleObject(40,40,LeftRightBorderShift,UpDownBorderShift+c2_coord_y[i],names[i]+":",TitlesColor);
}
else if(Corner==CORNER_RIGHT_UPPER)
{
Table1.AddTitleObject(40,40,LeftRightBorderShift+4,UpDownBorderShift+c1_coord_y[i],names[i]+":",TitlesColor);
}
else if(Corner==CORNER_RIGHT_LOWER)
{
Table1.AddTitleObject(40,40,LeftRightBorderShift+4,UpDownBorderShift+c2_coord_y[i],names[i]+":",TitlesColor);
}
else
{
Table1.AddTitleObject(40,40,LeftRightBorderShift,UpDownBorderShift+c2_coord_y[i],names[i]+":",TitlesColor);
}
}
RefreshInfo();
ChartRedraw(0);
EventSetTimer(1);
return(0);
}
//---------------------------------------------------------------------
// OnCalculate event handler
//---------------------------------------------------------------------
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
return(rates_total);
}
//---------------------------------------------------------------------
// OnTimer event handler
//---------------------------------------------------------------------
void OnTimer()
{
RefreshInfo();
ChartRedraw(0);
}
//---------------------------------------------------------------------
// OnDeinit event handler
//---------------------------------------------------------------------
void OnDeinit(const int _reason)
{
EventKillTimer();
// Delete table
Table1.Clear();
}
//---------------------------------------------------------------------
// Refresh info
//---------------------------------------------------------------------
void RefreshInfo()
{
for(int i=0; i<NUMBER; i++)
{
// Get price data
ResetLastError();
if(SymbolInfoTick(names[i],tick)!=true)
{
Table1.SetText( i, "Err " + DoubleToString( GetLastError( ), 0 ));
Table1.SetColor( i, Yellow );
continue;
}
if(tick.time>times[i] || times[i]==0)
{
Table1.SetText(i,DoubleToString(tick.bid,(int)(SymbolInfoInteger(names[i],SYMBOL_DIGITS))));
if(tick.bid>rates[i] && rates[i]>0.1)
{
Table1.SetColor(i,Lime);
}
else if(tick.bid<rates[i] && rates[i]>0.1)
{
Table1.SetColor(i,Red);
}
else
{
Table1.SetColor(i,Yellow);
}
rates[ i ] = tick.bid;
times[ i ] = tick.time;
}
Table1.SetText(i+NUMBER,DoubleToString(( tick.ask-tick.bid)/SymbolInfoDouble(names[i],SYMBOL_POINT),0));
}
}
//+------------------------------------------------------------------+
+428
View File
@@ -0,0 +1,428 @@
//=====================================================================
// A library for output of text information on the chart.
//=====================================================================
//---------------------------------------------------------------------
#property copyright "Dima S., 2010 ã."
#property link "dimascub@mail.com"
//---------------------------------------------------------------------
//---------------------------------------------------------------------
#import "user32.dll"
int GetSystemMetrics(int _index);
#import
//---------------------------------------------------------------------
#define SM_CXSCREEN 0
#define SM_CYSCREEN 1
#define SM_CXFULLSCREEN 16
#define SM_CYFULLSCREEN 17
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Include libraries
//---------------------------------------------------------------------
#include <ChartObjects\ChartObjectsTxtControls.mqh>
#include <Arrays\List.mqh>
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// TTitleDisplay class
//---------------------------------------------------------------------
class TTitleDisplay : public CChartObjectLabel
{
protected:
long chart_id;
int sub_window;
long chart_width; // chart width in pixels
long chart_height; // chart height in pixels
long chart_width_step; // chart width step
long chart_height_step; // chart height step
int columns_number; // number of columns
int lines_number; // number of rows
int curr_column;
int curr_row;
private:
void SetParams(long _chart_id,int _window,int _cols,int _lines);// set object parameters
public:
string GetUniqName(); // get unique name
bool Create(long _chart_id,int _window,int _cols,int _lines,int _col,int _row);
void RecalcAndRedraw(); // recalculate coordinates and redraw
public:
void TTitleDisplay(); // constructor
void ~TTitleDisplay(); // destructor
};
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------
void TTitleDisplay::TTitleDisplay()
{
}
//---------------------------------------------------------------------
// Desctructor
//---------------------------------------------------------------------
void TTitleDisplay::~TTitleDisplay()
{
}
//---------------------------------------------------------------------
// Create object
//---------------------------------------------------------------------
bool TTitleDisplay::Create(long _chart_id,int _window,int _cols,int _lines,int _col,int _row)
{
this.curr_column=_col;
this.curr_row=_row;
SetParams(_chart_id,_window,_cols,_lines);
return(this.Create(this.chart_id,this.GetUniqName(),this.sub_window,(int)(_col*this.chart_width_step),(int)(_row*this.chart_height_step)));
}
//---------------------------------------------------------------------
// Set object parameters
//---------------------------------------------------------------------
void TTitleDisplay::SetParams(long _chart_id,int _window,int _cols,int _lines)
{
this.chart_id=_chart_id;
this.sub_window=_window;
this.columns_number=_cols;
this.lines_number=_lines;
// get chart width in pixels
this.chart_width=GetSystemMetrics(SM_CXFULLSCREEN);
this.chart_height=GetSystemMetrics(SM_CYFULLSCREEN);
// calculate steps
this.chart_width_step=this.chart_width/_cols;
this.chart_height_step=this.chart_height/_lines;
}
//---------------------------------------------------------------------
// Recalculate object parameters and redraw
//---------------------------------------------------------------------
void TTitleDisplay::RecalcAndRedraw()
{
// Get size of the chart (in pixels)
long width=GetSystemMetrics(SM_CXFULLSCREEN);
long height=GetSystemMetrics(SM_CYFULLSCREEN);
if(width==this.chart_width && height==this.chart_height)
{
return;
}
this.chart_width=width;
this.chart_height=height;
// Recalculate steps
this.chart_width_step=this.chart_width/this.columns_number;
this.chart_height_step=this.chart_height/this.lines_number;
// Move object to new coordinates
this.X_Distance(( int )( this.curr_column * this.chart_width_step ));
this.Y_Distance(( int )( this.curr_row * this.chart_height_step ));
}
//---------------------------------------------------------------------
// Get unique name
//---------------------------------------------------------------------
string TTitleDisplay::GetUniqName()
{
static uint prev_count=0;
uint count=GetTickCount();
while(1)
{
if(prev_count==UINT_MAX)
{
prev_count=0;
}
if(count<=prev_count)
{
prev_count++;
count=prev_count;
}
else
{
prev_count=count;
}
// Check the presence of the object with the same name
string name=TimeToString(TimeGMT(),TIME_DATE|TIME_MINUTES|TIME_SECONDS)+" "+DoubleToString(count,0);
if(ObjectFind(0,name)<0)
{
return(name);
}
}
return(NULL);
}
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// TFieldDisplay class
//---------------------------------------------------------------------
class TFieldDisplay : public CChartObjectEdit
{
protected:
long chart_id;
int sub_window;
long chart_width; // chart width in pixels
long chart_height; // chart height in pixels
long chart_width_step; // horizontal step size
long chart_height_step; // vertical step size
int columns_number; // number of columns
int limes_number; // number of rows
int curr_column;
int curr_row;
private:
int type; // edit field type ( string, numerical )
private:
void SetParams(long _chart_id,int _window,int _cols,int _lines);// set object parameters
public:
string GetUniqName(); // get unique name
bool Create(long _chart_id,int _window,int _cols,int _lines,int _col,int _row);
void RecalcAndRedraw(); // recalculate coordinates and redraw
public:
void TFieldDisplay(); // constructor
void ~TFieldDisplay(); // desctructor
};
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------
void TFieldDisplay::TFieldDisplay()
{
}
//---------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------
void TFieldDisplay::~TFieldDisplay()
{
}
//---------------------------------------------------------------------
// Create object
//---------------------------------------------------------------------
bool TFieldDisplay::Create(long _chart_id,int _window,int _cols,int _lines,int _col,int _row)
{
this.curr_column=_col;
this.curr_row=_row;
SetParams(_chart_id,_window,_cols,_lines);
return(this.Create(this.chart_id,this.GetUniqName(),this.sub_window,(int)(_col*this.chart_width_step),(int)(_row*this.chart_height_step)));
}
//---------------------------------------------------------------------
// Set object parameters
//---------------------------------------------------------------------
void TFieldDisplay::SetParams(long _chart_id,int _window,int _cols,int _lines)
{
this.chart_id=_chart_id;
this.sub_window=_window;
this.columns_number=_cols;
this.limes_number=_lines;
// get window width in pixels
this.chart_width=GetSystemMetrics(SM_CXFULLSCREEN);
this.chart_height=GetSystemMetrics(SM_CYFULLSCREEN);
// calculate steps
this.chart_width_step=this.chart_width/_cols;
this.chart_height_step=this.chart_height/_lines;
}
//---------------------------------------------------------------------
// Recalculate and redraw
//---------------------------------------------------------------------
void TFieldDisplay::RecalcAndRedraw()
{
// get window size (in pixels)
long width=GetSystemMetrics(SM_CXFULLSCREEN);
long height=GetSystemMetrics(SM_CYFULLSCREEN);
if(width==this.chart_width && height==this.chart_height)
{
return;
}
this.chart_width=width;
this.chart_height=height;
// Calculate steps
this.chart_width_step=this.chart_width/this.columns_number;
this.chart_height_step=this.chart_height/this.limes_number;
// Move object to new coordinates
this.X_Distance(( int )( this.curr_column * this.chart_width_step ));
this.Y_Distance(( int )( this.curr_row * this.chart_height_step ));
}
//---------------------------------------------------------------------
// Get unique name
//---------------------------------------------------------------------
string TFieldDisplay::GetUniqName()
{
static uint prev_count=0;
uint count=GetTickCount();
while(1)
{
if(prev_count==UINT_MAX)
{
prev_count=0;
}
if(count<=prev_count)
{
prev_count++;
count=prev_count;
}
else
{
prev_count=count;
}
// Ïðîâåðèì, íåò ëè óæå îáúåêòà ñ òàêèì èìåíåì:
string name=TimeToString(TimeGMT(),TIME_DATE|TIME_MINUTES|TIME_SECONDS)+" "+DoubleToString(count,0);
if(ObjectFind(0,name)<0)
{
return(name);
}
}
return(NULL);
}
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// TableDisplay class (List of objects)
//---------------------------------------------------------------------
class TableDisplay : public CList
{
protected:
long chart_id;
int sub_window;
ENUM_BASE_CORNER corner;
public:
void SetParams(long _chart_id,int _window,ENUM_BASE_CORNER _corner=CORNER_LEFT_UPPER);
int AddTitleObject(int _cols,int _lines,int _col,int _row,string _title,color _color,string _fontname="Arial",int _fontsize=10);
int AddFieldObject(int _cols,int _lines,int _col,int _row,color _color,string _fontname="Arial",int _fontsize=10);
bool SetColor(int _index,color _color);
bool SetFont(int _index,string _fontname,int _fontsize);
bool SetText(int _index,string _text);
bool SetAnchor(int _index,ENUM_ANCHOR_POINT _anchor);
public:
void TableDisplay();
void ~TableDisplay();
};
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------
void TableDisplay::TableDisplay()
{
this.chart_id=0;
this.sub_window=0;
this.corner=CORNER_LEFT_UPPER;
}
//---------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------
void TableDisplay::~TableDisplay()
{
// Delete all objects
this.Clear();
}
//---------------------------------------------------------------------
// Set common parameters for all list objects
//---------------------------------------------------------------------
void TableDisplay::SetParams(long _chart_id,int _window,ENUM_BASE_CORNER _corner)
{
this.chart_id=_chart_id;
this.sub_window=_window;
this.corner=_corner;
}
//---------------------------------------------------------------------
// Add a header (title) object
//---------------------------------------------------------------------
int TableDisplay::AddTitleObject(int _cols,int _lines,int _col,int _row,string _title,color _color,string _fontname,int _fontsize)
{
TTitleDisplay *title=new TTitleDisplay();
title.Create( this.chart_id, this.sub_window, _cols, _lines, _col, _row );
title.Description( _title );
title.Color( _color );
title.Font( _fontname );
title.FontSize( _fontsize );
title.Corner( this.corner );
return(this.Add(title));
}
//---------------------------------------------------------------------
// Add Edit Field object
//---------------------------------------------------------------------
int TableDisplay::AddFieldObject(int _cols,int _lines,int _col,int _row,color _color,string _fontname,int _fontsize)
{
TFieldDisplay *field=new TFieldDisplay();
field.Create( this.chart_id, this.sub_window, _cols, _lines, _col, _row );
field.Description( "" );
field.Color( _color );
field.Font( _fontname );
field.FontSize( _fontsize );
field.Corner( this.corner );
return(this.Add(field));
}
//---------------------------------------------------------------------
// Set Anchor points
//---------------------------------------------------------------------
bool TableDisplay::SetAnchor(int _index,ENUM_ANCHOR_POINT _anchor)
{
CChartObjectText *object=GetNodeAtIndex(_index);
if(object==NULL)
{
return(false);
}
return(object.Anchor(_anchor));
}
//---------------------------------------------------------------------
// Set color of graphic object
//---------------------------------------------------------------------
bool TableDisplay::SetColor(int _index,color _color)
{
CChartObjectText *object=GetNodeAtIndex(_index);
if(object==NULL)
{
return(false);
}
return(object.Color(_color));
}
//---------------------------------------------------------------------
// Set font
//---------------------------------------------------------------------
bool TableDisplay::SetFont(int _index,string _fontname,int _fontsize)
{
CChartObjectText *object=GetNodeAtIndex(_index);
if(object==NULL)
{
return(false);
}
if(object.Font(_fontname)==false)
{
return(false);
}
return(object.FontSize(_fontsize));
}
//---------------------------------------------------------------------
// Set text
//---------------------------------------------------------------------
bool TableDisplay::SetText(int _index,string _text)
{
CChartObjectText *object=GetNodeAtIndex(_index);
if(object==NULL)
{
return(false);
}
return(object.Description(_text));
}
//---------------------------------------------------------------------