Commit
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,278 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| My_First_EA.mq5 |
|
||||
//| Copyright 2010, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2010, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
//--- input parameters
|
||||
input int StopLoss=30; // Stop Loss
|
||||
input int TakeProfit=100; // Take Profit
|
||||
input int ADX_Period=8; // ADX Period
|
||||
input int MA_Period=8; // Moving Average Period
|
||||
input int EA_Magic=12345; // EA Magic Number
|
||||
input double Adx_Min=22.0; // Minimum ADX Value
|
||||
input double Lot=0.1; // Lots to Trade
|
||||
//--- Other parameters
|
||||
int adxHandle; // handle for our ADX indicator
|
||||
int maHandle; // handle for our Moving Average indicator
|
||||
double plsDI[],minDI[],adxVal[]; // Dynamic arrays to hold the values of +DI, -DI and ADX values for each bars
|
||||
double maVal[]; // Dynamic array to hold the values of Moving Average for each bars
|
||||
double p_close; // Variable to store the close value of a bar
|
||||
int STP, TKP; // To be used for Stop Loss & Take Profit values
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- Get handle for ADX indicator
|
||||
adxHandle=iADX(NULL,0,ADX_Period);
|
||||
//--- Get the handle for Moving Average indicator
|
||||
maHandle=iMA(_Symbol,_Period,MA_Period,0,MODE_EMA,PRICE_CLOSE);
|
||||
//--- What if handle returns Invalid Handle
|
||||
if(adxHandle<0 || maHandle<0)
|
||||
{
|
||||
Alert("Error Creating Handles for indicators - error: ",GetLastError(),"!!");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
//--- Let us handle currency pairs with 5 or 3 digit prices instead of 4
|
||||
STP = StopLoss;
|
||||
TKP = TakeProfit;
|
||||
if(_Digits==5 || _Digits==3)
|
||||
{
|
||||
STP = STP*10;
|
||||
TKP = TKP*10;
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//--- Release our indicator handles
|
||||
IndicatorRelease(adxHandle);
|
||||
IndicatorRelease(maHandle);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//--- Do we have enough bars to work with
|
||||
if(Bars(_Symbol,_Period)<60) // if total bars is less than 60 bars
|
||||
{
|
||||
Alert("We have less than 60 bars, EA will now exit!!");
|
||||
return;
|
||||
}
|
||||
|
||||
// We will use the static Old_Time variable to serve the bar time.
|
||||
// At each OnTick execution we will check the current bar time with the saved one.
|
||||
// If the bar time isn't equal to the saved time, it indicates that we have a new tick.
|
||||
|
||||
static datetime Old_Time;
|
||||
datetime New_Time[1];
|
||||
bool IsNewBar=false;
|
||||
|
||||
// copying the last bar time to the element New_Time[0]
|
||||
int copied=CopyTime(_Symbol,_Period,0,1,New_Time);
|
||||
if(copied>0) // ok, the data has been copied successfully
|
||||
{
|
||||
if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time
|
||||
{
|
||||
IsNewBar=true; // if it isn't a first call, the new bar has appeared
|
||||
if(MQL5InfoInteger(MQL5_DEBUGGING)) Print("We have new bar here ",New_Time[0]," old time was ",Old_Time);
|
||||
Old_Time=New_Time[0]; // saving bar time
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert("Error in copying historical times data, error =",GetLastError());
|
||||
ResetLastError();
|
||||
return;
|
||||
}
|
||||
|
||||
//--- EA should only check for new trade if we have a new bar
|
||||
if(IsNewBar==false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//--- Do we have enough bars to work with
|
||||
int Mybars=Bars(_Symbol,_Period);
|
||||
if(Mybars<60) // if total bars is less than 60 bars
|
||||
{
|
||||
Alert("We have less than 60 bars, EA will now exit!!");
|
||||
return;
|
||||
}
|
||||
|
||||
//--- Define some MQL5 Structures we will use for our trade
|
||||
MqlTick latest_price; // To be used for getting recent/latest price quotes
|
||||
MqlTradeRequest mrequest; // To be used for sending our trade requests
|
||||
MqlTradeResult mresult; // To be used to get our trade results
|
||||
MqlRates mrate[]; // To be used to store the prices, volumes and spread of each bar
|
||||
ZeroMemory(mrequest); // Initialization of mrequest structure
|
||||
/*
|
||||
Let's make sure our arrays values for the Rates, ADX Values and MA values
|
||||
is store serially similar to the timeseries array
|
||||
*/
|
||||
// the rates arrays
|
||||
ArraySetAsSeries(mrate,true);
|
||||
// the ADX DI+values array
|
||||
ArraySetAsSeries(plsDI,true);
|
||||
// the ADX DI-values array
|
||||
ArraySetAsSeries(minDI,true);
|
||||
// the ADX values arrays
|
||||
ArraySetAsSeries(adxVal,true);
|
||||
// the MA-8 values arrays
|
||||
ArraySetAsSeries(maVal,true);
|
||||
|
||||
|
||||
//--- Get the last price quote using the MQL5 MqlTick Structure
|
||||
if(!SymbolInfoTick(_Symbol,latest_price))
|
||||
{
|
||||
Alert("Error getting the latest price quote - error:",GetLastError(),"!!");
|
||||
return;
|
||||
}
|
||||
|
||||
//--- Get the details of the latest 3 bars
|
||||
if(CopyRates(_Symbol,_Period,0,3,mrate)<0)
|
||||
{
|
||||
Alert("Error copying rates/history data - error:",GetLastError(),"!!");
|
||||
ResetLastError();
|
||||
return;
|
||||
}
|
||||
|
||||
//--- Copy the new values of our indicators to buffers (arrays) using the handle
|
||||
if(CopyBuffer(adxHandle,0,0,3,adxVal)<0 || CopyBuffer(adxHandle,1,0,3,plsDI)<0
|
||||
|| CopyBuffer(adxHandle,2,0,3,minDI)<0)
|
||||
{
|
||||
Alert("Error copying ADX indicator Buffers - error:",GetLastError(),"!!");
|
||||
ResetLastError();
|
||||
return;
|
||||
}
|
||||
if(CopyBuffer(maHandle,0,0,3,maVal)<0)
|
||||
{
|
||||
Alert("Error copying Moving Average indicator buffer - error:",GetLastError());
|
||||
ResetLastError();
|
||||
return;
|
||||
}
|
||||
//--- we have no errors, so continue
|
||||
//--- Do we have positions opened already?
|
||||
bool Buy_opened=false; // variable to hold the result of Buy opened position
|
||||
bool Sell_opened=false; // variables to hold the result of Sell opened position
|
||||
|
||||
if(PositionSelect(_Symbol)==true) // we have an opened position
|
||||
{
|
||||
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
|
||||
{
|
||||
Buy_opened=true; //It is a Buy
|
||||
}
|
||||
else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
|
||||
{
|
||||
Sell_opened=true; // It is a Sell
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the bar close price for the previous bar prior to the current bar, that is Bar 1
|
||||
p_close=mrate[1].close; // bar 1 close price
|
||||
|
||||
/*
|
||||
1. Check for a long/Buy Setup : MA-8 increasing upwards,
|
||||
previous price close above it, ADX > 22, +DI > -DI
|
||||
*/
|
||||
//--- Declare bool type variables to hold our Buy Conditions
|
||||
bool Buy_Condition_1=(maVal[0]>maVal[1]) && (maVal[1]>maVal[2]); // MA-8 Increasing upwards
|
||||
bool Buy_Condition_2 = (p_close > maVal[1]); // previuos price closed above MA-8
|
||||
bool Buy_Condition_3 = (adxVal[0]>Adx_Min); // Current ADX value greater than minimum value (22)
|
||||
bool Buy_Condition_4 = (plsDI[0]>minDI[0]); // +DI greater than -DI
|
||||
|
||||
//--- Putting all together
|
||||
if(Buy_Condition_1 && Buy_Condition_2)
|
||||
{
|
||||
if(Buy_Condition_3 && Buy_Condition_4)
|
||||
{
|
||||
// any opened Buy position?
|
||||
if(Buy_opened)
|
||||
{
|
||||
Alert("We already have a Buy Position!!!");
|
||||
return; // Don't open a new Buy Position
|
||||
}
|
||||
ZeroMemory(mrequest);
|
||||
mrequest.action = TRADE_ACTION_DEAL; // immediate order execution
|
||||
mrequest.price = NormalizeDouble(latest_price.ask,_Digits); // latest ask price
|
||||
mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss
|
||||
mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit
|
||||
mrequest.symbol = _Symbol; // currency pair
|
||||
mrequest.volume = Lot; // number of lots to trade
|
||||
mrequest.magic = EA_Magic; // Order Magic Number
|
||||
mrequest.type = ORDER_TYPE_BUY; // Buy Order
|
||||
mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type
|
||||
mrequest.deviation=100; // Deviation from current price
|
||||
//--- send order
|
||||
OrderSend(mrequest,mresult);
|
||||
// get the result code
|
||||
if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
|
||||
{
|
||||
Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert("The Buy order request could not be completed -error:",GetLastError());
|
||||
ResetLastError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
2. Check for a Short/Sell Setup : MA-8 decreasing downwards,
|
||||
previous price close below it, ADX > 22, -DI > +DI
|
||||
*/
|
||||
//--- Declare bool type variables to hold our Sell Conditions
|
||||
bool Sell_Condition_1 = (maVal[0]<maVal[1]) && (maVal[1]<maVal[2]); // MA-8 decreasing downwards
|
||||
bool Sell_Condition_2 = (p_close <maVal[1]); // Previous price closed below MA-8
|
||||
bool Sell_Condition_3 = (adxVal[0]>Adx_Min); // Current ADX value greater than minimum (22)
|
||||
bool Sell_Condition_4 = (plsDI[0]<minDI[0]); // -DI greater than +DI
|
||||
|
||||
//--- Putting all together
|
||||
if(Sell_Condition_1 && Sell_Condition_2)
|
||||
{
|
||||
if(Sell_Condition_3 && Sell_Condition_4)
|
||||
{
|
||||
// any opened Sell position?
|
||||
if(Sell_opened)
|
||||
{
|
||||
Alert("We already have a Sell position!!!");
|
||||
return; // Don't open a new Sell Position
|
||||
}
|
||||
ZeroMemory(mrequest);
|
||||
mrequest.action=TRADE_ACTION_DEAL; // immediate order execution
|
||||
mrequest.price = NormalizeDouble(latest_price.bid,_Digits); // latest Bid price
|
||||
mrequest.sl = NormalizeDouble(latest_price.bid + STP*_Point,_Digits); // Stop Loss
|
||||
mrequest.tp = NormalizeDouble(latest_price.bid - TKP*_Point,_Digits); // Take Profit
|
||||
mrequest.symbol = _Symbol; // currency pair
|
||||
mrequest.volume = Lot; // number of lots to trade
|
||||
mrequest.magic = EA_Magic; // Order Magic Number
|
||||
mrequest.type= ORDER_TYPE_SELL; // Sell Order
|
||||
mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type
|
||||
mrequest.deviation=100; // Deviation from current price
|
||||
//--- send order
|
||||
OrderSend(mrequest,mresult);
|
||||
// get the result code
|
||||
if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
|
||||
{
|
||||
Alert("A Sell order has been successfully placed with Ticket#:",mresult.order,"!!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert("The Sell order request could not be completed -error:",GetLastError());
|
||||
ResetLastError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------
|
||||
@@ -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));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -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));
|
||||
}
|
||||
//---------------------------------------------------------------------
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,53 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SMA.mq5 |
|
||||
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 Red
|
||||
|
||||
input int MAPeriod= 13;
|
||||
input int MAShift = 0;
|
||||
|
||||
double ExtLineBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,MAShift);
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,MAPeriod);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
|
||||
{
|
||||
if(rates_total<MAPeriod-1)
|
||||
return(0);
|
||||
|
||||
int first,bar,iii;
|
||||
double Sum,SMA;
|
||||
|
||||
if(prev_calculated==0)
|
||||
first=MAPeriod-1+begin;
|
||||
else first=prev_calculated-1;
|
||||
|
||||
for(bar=first;bar<rates_total;bar++)
|
||||
{
|
||||
Sum=0.0;
|
||||
for(iii=0;iii<MAPeriod;iii++)
|
||||
Sum+=price[bar-iii];
|
||||
|
||||
SMA=Sum/MAPeriod;
|
||||
|
||||
ExtLineBuffer[bar]=SMA;
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,79 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SMA.mq5 |
|
||||
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
//---- the indicator will be plotted in the main window
|
||||
#property indicator_chart_window
|
||||
//---- one buffer will be used for the calculations and plot of the indicator
|
||||
#property indicator_buffers 1
|
||||
//---- only one graphic plot is used
|
||||
#property indicator_plots 1
|
||||
//---- the indicator should be plotted as a line
|
||||
#property indicator_type1 DRAW_LINE
|
||||
//---- the color of the indicator's line is red
|
||||
#property indicator_color1 Red
|
||||
|
||||
//---- indicator input parameters
|
||||
input int MAPeriod = 13; //Averaging period
|
||||
input int MAShift = 0; //Horizontal shift (in bars)
|
||||
|
||||
//---- the declaration of the dynamic array
|
||||
//that will be used further as an indicator's buffer
|
||||
double ExtLineBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//----+
|
||||
//---- assign the dynamic array ExtLineBuffer with 0th indicator's buffer
|
||||
SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
|
||||
//---- set plot shift along the horizontal axis by MAShift bars
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,MAShift);
|
||||
//---- set plot begin from the bar with number MAPeriod
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,MAPeriod);
|
||||
//----+
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(
|
||||
const int rates_total, // number of available bars in history at the current tick
|
||||
const int prev_calculated,// number of bars, calculated at previous tick
|
||||
const int begin, // index of the first bar
|
||||
const double &price[] // price array for the calculation
|
||||
)
|
||||
{
|
||||
//----+
|
||||
//---- check for the presence of bars, sufficient for the calculation
|
||||
if (rates_total < MAPeriod - 1 + begin)
|
||||
return(0);
|
||||
|
||||
//---- declaration of local variables
|
||||
int first, bar, iii;
|
||||
double Sum, SMA;
|
||||
|
||||
//---- calculation of starting index first of the main loop
|
||||
if(prev_calculated==0) // check for the first start of the indicator
|
||||
first=MAPeriod-1+begin; // start index for all the bars
|
||||
else first=prev_calculated-1; // start index for the new bars
|
||||
|
||||
//---- main loop of the calculation
|
||||
for(bar = first; bar < rates_total; bar++)
|
||||
{
|
||||
Sum=0.0;
|
||||
//---- summation loop for the current bar averaging
|
||||
for(iii=0;iii<MAPeriod;iii++)
|
||||
Sum+=price[bar-iii]; // It's equal to: Sum = Sum + price[bar - iii];
|
||||
|
||||
//---- calculate averaged value
|
||||
SMA=Sum/MAPeriod;
|
||||
|
||||
//---- set the element of the indicator buffer with the value of SMA we have calculated
|
||||
ExtLineBuffer[bar]=SMA;
|
||||
}
|
||||
//----+
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,135 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Pivot1.mq5 |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
//--- plot Pivot
|
||||
#property indicator_label1 "Pivot1"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDarkOrange
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- input parameters
|
||||
input int Variant=2;
|
||||
//--- indicator buffers
|
||||
double PivotBuffer[];
|
||||
double HighBuffer[];
|
||||
double LowBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,PivotBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,HighBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,LowBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
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[])
|
||||
{
|
||||
|
||||
int start=1;
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
start=prev_calculated-1;
|
||||
}
|
||||
for(int i=start;i<rates_total;i++)
|
||||
{
|
||||
PivotBuffer[i]=PivotBuffer[i-1];
|
||||
HighBuffer[i]=HighBuffer[i-1];
|
||||
LowBuffer[i]=LowBuffer[i-1];
|
||||
if(NewDay(time[i],time[i-1],Variant))
|
||||
{
|
||||
PivotBuffer[i]=(HighBuffer[i]+LowBuffer[i]+close[i-1])/3;
|
||||
HighBuffer[i]=high[i];
|
||||
LowBuffer[i]=low[i];
|
||||
}
|
||||
HighBuffer[i]=MathMax(HighBuffer[i],high[i]);
|
||||
LowBuffer[i]=MathMin(LowBuffer[i],low[i]);
|
||||
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewDay(datetime aTimeCur,datetime aTimePre,int aVariant=1)
|
||||
{
|
||||
switch(aVariant)
|
||||
{
|
||||
case 1:
|
||||
return(NewDay1(aTimeCur,aTimePre));
|
||||
break;
|
||||
case 2:
|
||||
return(NewDay2(aTimeCur,aTimePre));
|
||||
break;
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewDay1(datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
return((aTimeCur/86400)!=(aTimePre/86400));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewDay2(datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
//--- new day
|
||||
if(NewDay1(aTimeCur,aTimePre))
|
||||
{
|
||||
TimeToStruct(aTimeCur,stm);
|
||||
switch(stm.day_of_week)
|
||||
{
|
||||
case 6: // Saturday
|
||||
return(false);
|
||||
break;
|
||||
case 0: // Sunday
|
||||
return(true);
|
||||
break;
|
||||
case 1: // Monday
|
||||
TimeToStruct(aTimePre,stm);
|
||||
if(stm.day_of_week!=0)
|
||||
{ // preceded by any day of the week other than Sunday
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
break;
|
||||
default: // any other day of the week
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,126 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Pivot2.mq5 |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
//--- plot Pivot
|
||||
#property indicator_label1 "Pivot2"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDarkOrange
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- input parameters
|
||||
input int Hour=14;
|
||||
input int Minute=0;
|
||||
//--- indicator buffers
|
||||
double PivotBuffer[];
|
||||
double HighBuffer[];
|
||||
double LowBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,PivotBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,HighBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(2,LowBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
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[])
|
||||
{
|
||||
|
||||
int start=1;
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
start=prev_calculated-1;
|
||||
}
|
||||
for(int i=start;i<rates_total;i++)
|
||||
{
|
||||
PivotBuffer[i]=PivotBuffer[i-1];
|
||||
HighBuffer[i]=HighBuffer[i-1];
|
||||
LowBuffer[i]=LowBuffer[i-1];
|
||||
if(NewCustomDay(Hour,Minute,time[i],time[i-1]))
|
||||
{
|
||||
PivotBuffer[i]=(HighBuffer[i]+LowBuffer[i]+close[i-1])/3;
|
||||
HighBuffer[i]=high[i];
|
||||
LowBuffer[i]=low[i];
|
||||
}
|
||||
HighBuffer[i]=MathMax(HighBuffer[i],high[i]);
|
||||
LowBuffer[i]=MathMin(LowBuffer[i],low[i]);
|
||||
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewCustomDay(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
if(TimeCross(aHour,aMinute,aTimeCur,aTimePre))
|
||||
{
|
||||
TimeToStruct(aTimeCur,stm);
|
||||
if(stm.day_of_week==0 || stm.day_of_week==6)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool TimeCross(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
//--- specified time since the day start
|
||||
datetime PointTime=aHour*3600+aMinute*60;
|
||||
//--- current time since the day start
|
||||
aTimeCur=aTimeCur%86400;
|
||||
//--- previous time since the day start
|
||||
aTimePre=aTimePre%86400;
|
||||
if(aTimeCur<aTimePre)
|
||||
{
|
||||
//--- going past midnight
|
||||
if(aTimeCur>=PointTime || aTimePre<PointTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(aTimeCur>=PointTime && aTimePre<PointTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,106 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Session.mq5 |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_separate_window
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 2
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
//--- plot Session
|
||||
#property indicator_label1 "Session"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- input parameters
|
||||
input int StartHour=10;
|
||||
input int StartMinute=0;
|
||||
input int StopHour=14;
|
||||
input int StopMinute=0;
|
||||
//--- indicator buffers
|
||||
double SessionBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,SessionBuffer,INDICATOR_DATA);
|
||||
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,159);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
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[])
|
||||
{
|
||||
int start=0;
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
start=prev_calculated-1;
|
||||
}
|
||||
for(int i=start;i<rates_total;i++)
|
||||
{
|
||||
if(TimeSession(StartHour,StartMinute,StopHour,StopMinute,time[i]))
|
||||
{
|
||||
SessionBuffer[i]=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SessionBuffer[i]=EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool TimeSession(int aStartHour,int aStartMinute,int aStopHour,int aStopMinute,datetime aTimeCur)
|
||||
{
|
||||
//--- session start time
|
||||
int StartTime=3600*aStartHour+60*aStartMinute;
|
||||
//--- session end time
|
||||
int StopTime=3600*aStopHour+60*aStopMinute;
|
||||
//--- current time in seconds since the day start
|
||||
aTimeCur=aTimeCur%86400;
|
||||
if(StopTime<StartTime)
|
||||
{
|
||||
//--- going past midnight
|
||||
if(aTimeCur>=StartTime || aTimeCur<StopTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- within one day
|
||||
if(aTimeCur>=StartTime && aTimeCur<StopTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,152 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SessionWeek.mq5 |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_separate_window
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 2
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
//--- plot Session
|
||||
#property indicator_label1 "SessionWeek"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrGray
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
enum EWeekDay
|
||||
{
|
||||
Sunday = 0,
|
||||
Monday = 1,
|
||||
Tuesday = 2,
|
||||
Wednesday = 3,
|
||||
Thursday = 4,
|
||||
Friday = 5,
|
||||
Saturday = 6
|
||||
};
|
||||
|
||||
//--- input parameters
|
||||
|
||||
input EWeekDay StartDay = Monday;
|
||||
input int StartHour = 3;
|
||||
input int StartMinute = 0;
|
||||
input EWeekDay StopDay = Friday;
|
||||
input int StopHour = 18;
|
||||
input int StopMinute = 0;
|
||||
|
||||
bool WeekDays[7];
|
||||
//--- indicator buffers
|
||||
double SessionBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,SessionBuffer,INDICATOR_DATA);
|
||||
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,159);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
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[])
|
||||
{
|
||||
int start=0;
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
start=prev_calculated-1;
|
||||
}
|
||||
for(int i=start;i<rates_total;i++)
|
||||
{
|
||||
if(WeekSession(StartDay,StartHour,StartMinute,StopDay,StopHour,StopMinute,time[i]))
|
||||
{
|
||||
SessionBuffer[i]=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SessionBuffer[i]=EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool WeekSession(int aStartDay,int aStartHour,int aStartMinute,int aStopDay,int aStopHour,int aStopMinute,datetime aTimeCur)
|
||||
{
|
||||
//--- session start time since the week start
|
||||
int StartTime=aStartDay*86400+3600*aStartHour+60*aStartMinute;
|
||||
//--- session end time since the week start
|
||||
int StopTime=aStopDay*86400+3600*aStopHour+60*aStopMinute;
|
||||
//--- current time in seconds since the week start
|
||||
long TimeCur=SecondsFromWeekStart(aTimeCur,false);
|
||||
if(StopTime<StartTime)
|
||||
{
|
||||
//--- passing the turn of the week
|
||||
if(TimeCur>=StartTime || TimeCur<StopTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- within one week
|
||||
if(TimeCur>=StartTime && TimeCur<StopTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
long SecondsFromWeekStart(datetime aTime,bool aStartsOnMonday=false)
|
||||
{
|
||||
return(aTime-WeekStartTime(aTime,aStartsOnMonday));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
long WeekStartTime(datetime aTime,bool aStartsOnMonday=false)
|
||||
{
|
||||
long tmp=aTime;
|
||||
long Corrector;
|
||||
if(aStartsOnMonday)
|
||||
{
|
||||
Corrector=259200; // duration of three days (86400*3)
|
||||
}
|
||||
else
|
||||
{
|
||||
Corrector=345600; // duration of four days (86400*4)
|
||||
}
|
||||
tmp+=Corrector;
|
||||
tmp=(tmp/604800)*604800;
|
||||
tmp-=Corrector;
|
||||
return(tmp);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,124 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| sTestArea.mq5 |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Script program start function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart(){
|
||||
|
||||
//--- Bar generation option: 1 - no weekend bars, 2 - 4 bars at the end of Sunday, 3 - all weekend bars, 4 - Saturday bars but no Sunday bars
|
||||
int Variant=1;
|
||||
|
||||
//---
|
||||
|
||||
ObjectsDeleteAll(0);
|
||||
color Colors[]={clrGreen,clrBlue,0,0,0,clrRed,clrMagenta};
|
||||
int ColorIndex=-1;
|
||||
datetime ta[];
|
||||
int size=0;
|
||||
int i;
|
||||
switch(Variant){
|
||||
case 1:
|
||||
size=24*2;
|
||||
ArrayResize(ta,size);
|
||||
for(i=0;i<24;i++){
|
||||
ta[i]=86400+i*3600;
|
||||
}
|
||||
for(i=24;i<size;i++){
|
||||
ta[i]=86400*3+i*3600;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
size=24*2+4;
|
||||
ArrayResize(ta,size);
|
||||
for(i=0;i<24;i++){
|
||||
ta[i]=86400+i*3600;
|
||||
}
|
||||
ta[24]=86400*4-4*3600;
|
||||
ta[25]=86400*4-3*3600;
|
||||
ta[26]=86400*4-2*3600;
|
||||
ta[27]=86400*4-1*3600;
|
||||
for(i=28;i<size;i++){
|
||||
ta[i]=86400*4+(i-28)*3600;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
size=24*4;
|
||||
ArrayResize(ta,size);
|
||||
for(i=0;i<size;i++){
|
||||
ta[i]=86400+i*3600;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
size=24*3;
|
||||
ArrayResize(ta,size);
|
||||
for(i=0;i<48;i++){
|
||||
ta[i]=86400+i*3600;
|
||||
}
|
||||
for(i=48;i<size;i++){
|
||||
ta[i]=86400*2+i*3600;
|
||||
}
|
||||
break;
|
||||
}
|
||||
MqlDateTime stm;
|
||||
for(i=0;i<size;i++){
|
||||
TimeToStruct(ta[i],stm);
|
||||
Label("Label_Time_"+(string)i,8*i,100,TimeToString(ta[i],TIME_MINUTES),Colors[stm.day_of_week],90,"Arial",7);
|
||||
}
|
||||
LikeOnCalculate(size,ta);
|
||||
ChartRedraw(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
// Main experimental function
|
||||
//+------------------------------------------------------------------+
|
||||
void LikeOnCalculate(const int rates_total,const datetime & time[]){
|
||||
for(int i=0;i<rates_total;i++){
|
||||
SetMarker(i,0,clrChocolate);
|
||||
SetMarker(i,1,clrLime);
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
// Function for setting a marker |
|
||||
// Parameters: aBarIndex - bar index, aBufferIndex - marker row |
|
||||
// index, aColor - marker color |
|
||||
//+------------------------------------------------------------------+
|
||||
void SetMarker(int aBarIndex,int aBufferIndex,color aColor){
|
||||
Label("Label_Marker_"+(string)aBufferIndex+"_"+(string)aBarIndex,8*aBarIndex+1,99+8*aBufferIndex,CharToString(110),aColor,0,"Wingdings",9);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
// Function for creating the OBJ_LABEL graphical object |
|
||||
//+------------------------------------------------------------------+
|
||||
void Label(
|
||||
string aObjName = "ObjLabel",
|
||||
int aX = 30,
|
||||
int aY = 30,
|
||||
string aText = "ObjLabel",
|
||||
color aColor = clrRed,
|
||||
double aAngle = 0,
|
||||
string aFont = "Arial",
|
||||
int aSize = 8
|
||||
){
|
||||
ObjectCreate(0,aObjName,OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_BACK,false);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_COLOR,aColor);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_FONTSIZE,aSize);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_SELECTABLE,true);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_SELECTED,false);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_XDISTANCE,aX);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_YDISTANCE,aY);
|
||||
ObjectSetString(0,aObjName,OBJPROP_TEXT,aText);
|
||||
ObjectSetString(0,aObjName,OBJPROP_FONT,aFont);
|
||||
ObjectSetDouble(0,aObjName,OBJPROP_ANGLE,aAngle);
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| sTestArea_Pivot1.mq5 |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Script program start function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
|
||||
//--- Bar generation option: 1 - no weekend bars, 2 - 4 bars at the end of Sunday, 3 - all weekend bars, 4 - Saturday bars but no Sunday bars
|
||||
int Variant=1;
|
||||
|
||||
//---
|
||||
|
||||
ObjectsDeleteAll(0);
|
||||
color Colors[]={clrGreen,clrBlue,0,0,0,clrRed,clrMagenta};
|
||||
int ColorIndex=-1;
|
||||
datetime ta[];
|
||||
int size=0;
|
||||
int i;
|
||||
switch(Variant)
|
||||
{
|
||||
case 1:
|
||||
size=24*2;
|
||||
ArrayResize(ta,size);
|
||||
for(i=0;i<24;i++)
|
||||
{
|
||||
ta[i]=86400+i*3600;
|
||||
}
|
||||
for(i=24;i<size;i++)
|
||||
{
|
||||
ta[i]=86400*3+i*3600;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
size=24*2+4;
|
||||
ArrayResize(ta,size);
|
||||
for(i=0;i<24;i++)
|
||||
{
|
||||
ta[i]=86400+i*3600;
|
||||
}
|
||||
ta[24]=86400*4-4*3600;
|
||||
ta[25]=86400*4-3*3600;
|
||||
ta[26]=86400*4-2*3600;
|
||||
ta[27]=86400*4-1*3600;
|
||||
for(i=28;i<size;i++)
|
||||
{
|
||||
ta[i]=86400*4+(i-28)*3600;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
size=24*4;
|
||||
ArrayResize(ta,size);
|
||||
for(i=0;i<size;i++)
|
||||
{
|
||||
ta[i]=86400+i*3600;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
size=24*3;
|
||||
ArrayResize(ta,size);
|
||||
for(i=0;i<48;i++)
|
||||
{
|
||||
ta[i]=86400+i*3600;
|
||||
}
|
||||
for(i=48;i<size;i++)
|
||||
{
|
||||
ta[i]=86400*2+i*3600;
|
||||
}
|
||||
break;
|
||||
}
|
||||
MqlDateTime stm;
|
||||
for(i=0;i<size;i++)
|
||||
{
|
||||
TimeToStruct(ta[i],stm);
|
||||
//Alert(stm.day_of_week);
|
||||
Label("Label_Time_"+(string)i,8*i,100,TimeToString(ta[i],TIME_MINUTES),Colors[stm.day_of_week],90,"Arial",7);
|
||||
}
|
||||
LikeOnCalculate(size,ta);
|
||||
ChartRedraw(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
// Main experimental function
|
||||
//+------------------------------------------------------------------+
|
||||
void LikeOnCalculate(const int rates_total,const datetime &time[])
|
||||
{
|
||||
for(int i=1;i<rates_total;i++)
|
||||
{
|
||||
if(NewDay(time[i],time[i-1],2))
|
||||
{
|
||||
SetMarker(i,0,clrChocolate);
|
||||
}
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewDay(datetime aTimeCur,datetime aTimePre,int aVariant=1)
|
||||
{
|
||||
switch(aVariant)
|
||||
{
|
||||
case 1:
|
||||
return(NewDay1(aTimeCur,aTimePre));
|
||||
break;
|
||||
case 2:
|
||||
return(NewDay2(aTimeCur,aTimePre));
|
||||
break;
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewDay1(datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
return((aTimeCur/86400)!=(aTimePre/86400));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewDay2(datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
//--- new day
|
||||
if(NewDay1(aTimeCur,aTimePre))
|
||||
{
|
||||
TimeToStruct(aTimeCur,stm);
|
||||
switch(stm.day_of_week)
|
||||
{
|
||||
case 6: // Saturday
|
||||
return(false);
|
||||
break;
|
||||
case 0: // Sunday
|
||||
return(true);
|
||||
break;
|
||||
case 1: // Monday
|
||||
TimeToStruct(aTimePre,stm);
|
||||
if(stm.day_of_week!=0)
|
||||
{ // preceded by any day of the week other than Sunday
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
break;
|
||||
default: // any other day of the week
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
// Function for setting a marker |
|
||||
// Parameters: aBarIndex - bar index, aBufferIndex - marker row |
|
||||
// index, aColor - marker color |
|
||||
//+------------------------------------------------------------------+
|
||||
void SetMarker(int aBarIndex,int aBufferIndex,color aColor)
|
||||
{
|
||||
Label("Label_Marker_"+(string)aBufferIndex+"_"+(string)aBarIndex,8*aBarIndex+1,99+8*aBufferIndex,CharToString(110),aColor,0,"Wingdings",9);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
// Function for creating the OBJ_LABEL graphical object |
|
||||
//+------------------------------------------------------------------+
|
||||
void Label(
|
||||
string aObjName = "ObjLabel",
|
||||
int aX = 30,
|
||||
int aY = 30,
|
||||
string aText = "ObjLabel",
|
||||
color aColor = clrRed,
|
||||
double aAngle = 0,
|
||||
string aFont = "Arial",
|
||||
int aSize = 8
|
||||
)
|
||||
{
|
||||
ObjectCreate(0,aObjName,OBJ_LABEL,0,0,0);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_BACK,false);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_COLOR,aColor);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_FONTSIZE,aSize);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_SELECTABLE,true);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_SELECTED,false);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_XDISTANCE,aX);
|
||||
ObjectSetInteger(0,aObjName,OBJPROP_YDISTANCE,aY);
|
||||
ObjectSetString(0,aObjName,OBJPROP_TEXT,aText);
|
||||
ObjectSetString(0,aObjName,OBJPROP_FONT,aFont);
|
||||
ObjectSetDouble(0,aObjName,OBJPROP_ANGLE,aAngle);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,538 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| TimeFuncions.mqh |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the time of the first bar on a lower time frame|
|
||||
//| in a bar on a higher time frame |
|
||||
//+------------------------------------------------------------------+
|
||||
bool LowerTFFirstBarTime(string aSymbol,ENUM_TIMEFRAMES aLowerTF,datetime aUpperTFBarTime,datetime &aLowerTFFirstBarTime)
|
||||
{
|
||||
datetime tm[];
|
||||
//--- determine the bar time on a lower time frame corresponding to the bar time on a higher time frame
|
||||
if(CopyTime(aSymbol,aLowerTF,aUpperTFBarTime,1,tm)==-1)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
if(tm[0]<aUpperTFBarTime)
|
||||
{
|
||||
//--- we got the time of the preceding bar
|
||||
datetime tm2[];
|
||||
//--- determine the time of the last bar on a lower time frame
|
||||
if(CopyTime(aSymbol,aLowerTF,0,1,tm2)==-1)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
if(tm[0]<tm2[0])
|
||||
{
|
||||
//--- there is a bar following the bar of a lower time frame
|
||||
//--- that precedes the occurrence of the bar on a higher time frame
|
||||
int start=Bars(aSymbol,aLowerTF,tm[0],tm2[0])-2;
|
||||
//--- the Bars() function returns the number of bars, whereas we need to determine the index of the bar
|
||||
//--- following the bar with time tm[0], so
|
||||
//--- 2 is subtracted. 1 for getting the index of the bar
|
||||
//--- with time tm[0] and 1 for getting the index
|
||||
//--- of the following bar
|
||||
if(CopyTime(aSymbol,aLowerTF,start,1,tm)==-1)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//---there is no bar of a lower time frame contained
|
||||
//--- in the bar on a higher time frame
|
||||
aLowerTFFirstBarTime=0;
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
//--- assign the obtained value to the variable
|
||||
aLowerTFFirstBarTime=tm[0];
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the time of the last bar on a lower time frame|
|
||||
//| in a bar on a higher time frame |
|
||||
//+------------------------------------------------------------------+
|
||||
bool LowerTFLastBarTime(string aSymbol,ENUM_TIMEFRAMES aUpperTF,ENUM_TIMEFRAMES aLowerTF,datetime aUpperTFBarTime,datetime &aLowerTFFirstBarTime)
|
||||
{
|
||||
//--- time of the next bar on a higher time frame
|
||||
datetime NextBarTime=aUpperTFBarTime+PeriodSeconds(aUpperTF);
|
||||
datetime tm[];
|
||||
if(CopyTime(aSymbol,aLowerTF,NextBarTime,1,tm)==-1)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
if(tm[0]==NextBarTime)
|
||||
{
|
||||
//--- There is a bar on a lower time frame corresponding to the time of the next bar on a higher time frame.
|
||||
//--- Determine the time of the last bar on a lower time frame
|
||||
datetime tm2[];
|
||||
if(CopyTime(aSymbol,aLowerTF,0,1,tm2)==-1)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
//--- determine the preceding bar index on a lower time frame
|
||||
int start=Bars(aSymbol,aLowerTF,tm[0],tm2[0]);
|
||||
//--- determine the time of this bar
|
||||
if(CopyTime(aSymbol,aLowerTF,start,1,tm)==-1)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
//--- assign the obtained value to the variable
|
||||
aLowerTFFirstBarTime=tm[0];
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Normalization of time by bar length |
|
||||
//+------------------------------------------------------------------+
|
||||
datetime BarTimeNormalize(datetime aTime,ENUM_TIMEFRAMES aTimeFrame)
|
||||
{
|
||||
int BarLength=PeriodSeconds(aTimeFrame);
|
||||
return(BarLength*(aTime/BarLength));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining time in seconds since the day start |
|
||||
//| aTime - time in seconds, |
|
||||
//| int &aH, int &aM, int &aS - returns hours, |
|
||||
//| minutes and seconds by reference |
|
||||
//+------------------------------------------------------------------+
|
||||
int TimeFromDayStart(datetime aTime,int &aH,int &aM,int &aS)
|
||||
{
|
||||
//--- Number of seconds elapsed since the day start (aTime%86400)
|
||||
//--- divided by the number of seconds in an hour is the number of hours
|
||||
aH=(int)((aTime%86400)/3600);
|
||||
//--- Number of seconds elapsed since the last hour (aTime%3600)
|
||||
//--- divided by the number of seconds in a minute is the number of minutes
|
||||
aM=(int)((aTime%3600)/60);
|
||||
//--- Number of seconds elapsed since the last minute
|
||||
aS=(int)(aTime%60);
|
||||
//--- Number of seconds since the day start
|
||||
return(int(aTime%86400));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the number of the week since the beginning of the epoch|
|
||||
//| datetime aTime - time, |
|
||||
//| bool aStartsOnMonday=false - the week starts on Monday |
|
||||
//+------------------------------------------------------------------+
|
||||
long WeekNum(datetime aTime,bool aStartsOnMonday=false)
|
||||
{
|
||||
//--- if the week starts on Sunday, add the duration of 4 days (Wednesday+Tuesday+Monday+Sunday),
|
||||
// if it starts on Monday, add 3 days (Wednesday, Tuesday, Monday)
|
||||
if(aStartsOnMonday)
|
||||
{
|
||||
aTime+=259200; // duration of three days (86400*3)
|
||||
}
|
||||
else
|
||||
{
|
||||
aTime+=345600; // duration of four days (86400*4)
|
||||
}
|
||||
return(aTime/604800);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the time of the week start |
|
||||
//| datetime aTime - time, |
|
||||
//| bool aStartsOnMonday=false - the week starts on Monday |
|
||||
//+------------------------------------------------------------------+
|
||||
long WeekStartTime(datetime aTime,bool aStartsOnMonday=false)
|
||||
{
|
||||
long tmp=aTime;
|
||||
long Corrector;
|
||||
if(aStartsOnMonday)
|
||||
{
|
||||
Corrector=259200; // duration of three days (86400*3)
|
||||
}
|
||||
else
|
||||
{
|
||||
Corrector=345600; // duration of four days (86400*4)
|
||||
}
|
||||
tmp+=Corrector;
|
||||
tmp=(tmp/604800)*604800;
|
||||
tmp-=Corrector;
|
||||
return(tmp);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the time in seconds since the week start|
|
||||
//| datetime aTime - time, |
|
||||
//| bool aStartsOnMonday=false - the week starts on Monday |
|
||||
//+------------------------------------------------------------------+
|
||||
long SecondsFromWeekStart(datetime aTime,bool aStartsOnMonday=false)
|
||||
{
|
||||
return(aTime-WeekStartTime(aTime,aStartsOnMonday));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the number of the week since a given date|
|
||||
//| datetime aTime - time for which the number of the week is determined,|
|
||||
//| datetime aStartTime - start time, |
|
||||
//| bool aStartsOnMonday=false - the week starts on Monday |
|
||||
//+------------------------------------------------------------------+
|
||||
long WeekNumFromDate(datetime aTime,datetime aStartTime,bool aStartsOnMonday=false)
|
||||
{
|
||||
long Time,StartTime,Corrector;
|
||||
MqlDateTime stm;
|
||||
Time=aTime;
|
||||
StartTime=aStartTime;
|
||||
//--- determine the beginning of the reference epoch
|
||||
StartTime=(StartTime/86400)*86400;
|
||||
//--- determine the time that elapsed
|
||||
//--- since the beginning of the reference epoch
|
||||
Time-=StartTime;
|
||||
//--- determine the day of the week of the beginning of the reference epoch
|
||||
TimeToStruct(StartTime,stm);
|
||||
//--- if the week starts on Monday,
|
||||
//--- numbers of days of the week are decreased by 1 and
|
||||
//--- the day with number 0 becomes a day with number 6
|
||||
if(aStartsOnMonday)
|
||||
{
|
||||
if(stm.day_of_week==0)
|
||||
{
|
||||
stm.day_of_week=6;
|
||||
}
|
||||
else
|
||||
{
|
||||
stm.day_of_week--;
|
||||
}
|
||||
}
|
||||
//--- calculate the value of the time corrector
|
||||
Corrector=86400*stm.day_of_week;
|
||||
//--- time correction
|
||||
Time+=Corrector;
|
||||
//--- calculate and return the number of the week
|
||||
return(Time/604800);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Determining the time of the year start |
|
||||
//| datetime aTime - time |
|
||||
//+------------------------------------------------------------------+
|
||||
datetime YearStartTime(datetime aTime)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
TimeToStruct(aTime,stm);
|
||||
stm.day=1;
|
||||
stm.mon=1;
|
||||
stm.hour=0;
|
||||
stm.min=0;
|
||||
stm.sec=0;
|
||||
return(StructToTime(stm));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Determining the time of the month start |
|
||||
//| datetime aTime - time |
|
||||
//+------------------------------------------------------------------+
|
||||
datetime MonthStartTime(datetime aTime)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
TimeToStruct(aTime,stm);
|
||||
stm.day=1;
|
||||
stm.hour=0;
|
||||
stm.min=0;
|
||||
stm.sec=0;
|
||||
return(StructToTime(stm));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the number of the week in a year |
|
||||
//| datetime aTime - time, |
|
||||
//| bool aStartsOnMonday=false - the week starts on Monday |
|
||||
//+------------------------------------------------------------------+
|
||||
long WeekNumYear(datetime aTime,bool aStartsOnMonday=false)
|
||||
{
|
||||
return(WeekNumFromDate(aTime,YearStartTime(aTime),aStartsOnMonday));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
long WeekNumMonth(datetime aTime,bool aStartsOnMonday=false)
|
||||
{
|
||||
return(WeekNumFromDate(aTime,MonthStartTime(aTime),aStartsOnMonday));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the new calendar day |
|
||||
//| datetime aTimeCur - current time, |
|
||||
//| datetime aTimePre - previous time, |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewDay1(datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
return((aTimeCur/86400)!=(aTimePre/86400));
|
||||
}
|
||||
//+-------------------------------------------------------------------+
|
||||
//| Function for determining the new day for quotes with a Sunday bar |
|
||||
//| datetime aTimeCur - current time, |
|
||||
//| datetime aTimePre - previous time, |
|
||||
//+-------------------------------------------------------------------+
|
||||
bool NewDay2(datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
//--- new day
|
||||
if(NewDay1(aTimeCur,aTimePre))
|
||||
{
|
||||
TimeToStruct(aTimeCur,stm);
|
||||
switch(stm.day_of_week)
|
||||
{
|
||||
case 6: // Saturday
|
||||
return(false);
|
||||
break;
|
||||
case 0: // Sunday
|
||||
return(true);
|
||||
break;
|
||||
case 1: // Monday
|
||||
TimeToStruct(aTimePre,stm);
|
||||
if(stm.day_of_week!=0)
|
||||
{ // preceded by any day of the week other than Sunday
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
break;
|
||||
default: // any other day of the week
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the new day |
|
||||
//| datetime aTimeCur - current time, |
|
||||
//| datetime aTimePre - previous time, |
|
||||
//| int aVariant=1 - 1 - calendar day as is, 2 - Sunday |
|
||||
//| is treated as Monday |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewDay(datetime aTimeCur,datetime aTimePre,int aVariant=1)
|
||||
{
|
||||
switch(aVariant)
|
||||
{
|
||||
case 1:
|
||||
return(NewDay1(aTimeCur,aTimePre));
|
||||
break;
|
||||
case 2:
|
||||
return(NewDay2(aTimeCur,aTimePre));
|
||||
break;
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining an intraday session |
|
||||
//| int aStartHour - start hour, |
|
||||
//| int aStartMinute - start minutes, |
|
||||
//| int aStopHour - end hour, |
|
||||
//| int aStopMinute - end minutes, |
|
||||
//| datetime aTimeCur - current time |
|
||||
//+------------------------------------------------------------------+
|
||||
bool TimeSession(int aStartHour,int aStartMinute,int aStopHour,int aStopMinute,datetime aTimeCur)
|
||||
{
|
||||
//--- session start time
|
||||
int StartTime=3600*aStartHour+60*aStartMinute;
|
||||
//--- session end time
|
||||
int StopTime=3600*aStopHour+60*aStopMinute;
|
||||
//--- current time in seconds since the day start
|
||||
aTimeCur=aTimeCur%86400;
|
||||
if(StopTime<StartTime)
|
||||
{
|
||||
//--- going past midnight
|
||||
if(aTimeCur>=StartTime || aTimeCur<StopTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- within one day
|
||||
if(aTimeCur>=StartTime && aTimeCur<StopTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the occurrence of a given point of time |
|
||||
//| int aHour - day start hour, |
|
||||
//| int aMinute - day start minutes, |
|
||||
//| datetime aTimeCur - current time, |
|
||||
//| datetime aTimePre - previous time |
|
||||
//+------------------------------------------------------------------+
|
||||
bool TimeCross(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
//--- specified time since the day start
|
||||
datetime PointTime=aHour*3600+aMinute*60;
|
||||
//--- current time since the day start
|
||||
aTimeCur=aTimeCur%86400;
|
||||
//--- previous time since the day start
|
||||
aTimePre=aTimePre%86400;
|
||||
if(aTimeCur<aTimePre)
|
||||
{
|
||||
//--- going past midnight
|
||||
if(aTimeCur>=PointTime || aTimePre<PointTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(aTimeCur>=PointTime && aTimePre<PointTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the start of a new user-defined day |
|
||||
//| int aHour - day start hour, |
|
||||
//| int aMinute - day start minutes, |
|
||||
//| datetime aTimeCur - current time, |
|
||||
//| datetime aTimePre - previous time |
|
||||
//+------------------------------------------------------------------+
|
||||
bool NewCustomDay(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
if(TimeCross(aHour,aMinute,aTimeCur,aTimePre))
|
||||
{
|
||||
TimeToStruct(aTimeCur,stm);
|
||||
if(stm.day_of_week==0 || stm.day_of_week==6)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Variables for the WeekDays_Check() function |
|
||||
//+------------------------------------------------------------------+
|
||||
input bool Sunday = true; // Sunday
|
||||
input bool Monday = true; // Monday
|
||||
input bool Tuesday = true; // Tuesday
|
||||
input bool Wednesday = true; // Wednesday
|
||||
input bool Thursday = true; // Thursday
|
||||
input bool Friday = true; // Friday
|
||||
input bool Saturday = true; // Saturday
|
||||
|
||||
bool WeekDays[7];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for the preparation of an array for the WeekDays_Check() function|
|
||||
//+------------------------------------------------------------------+
|
||||
void WeekDays_Init()
|
||||
{
|
||||
WeekDays[0]=Sunday;
|
||||
WeekDays[1]=Monday;
|
||||
WeekDays[2]=Tuesday;
|
||||
WeekDays[3]=Wednesday;
|
||||
WeekDays[4]=Thursday;
|
||||
WeekDays[5]=Friday;
|
||||
WeekDays[6]=Saturday;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Checking the day of the week |
|
||||
//| datetime aTime - time for which we check whether |
|
||||
//| a certain day of the week is allowed |
|
||||
//+------------------------------------------------------------------+
|
||||
bool WeekDays_Check(datetime aTime)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
TimeToStruct(aTime,stm);
|
||||
return(WeekDays[stm.day_of_week]);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining a trading session within a week |
|
||||
//| int aStartDay - day of the week of the session start, |
|
||||
//| int aStartHour - session start hour, |
|
||||
//| int aStartMinute - session start minutes, |
|
||||
//| int aStopDay - day of the week of the session end, |
|
||||
//| int aStopHour - session end hour, |
|
||||
//| int aStopMinute - session end minutes, |
|
||||
//| aTimeCur - time that we check for being or not being |
|
||||
//| within the session |
|
||||
//+------------------------------------------------------------------+
|
||||
bool WeekSession(int aStartDay,int aStartHour,int aStartMinute,int aStopDay,int aStopHour,int aStopMinute,datetime aTimeCur)
|
||||
{
|
||||
//--- session start time since the week start
|
||||
int StartTime=aStartDay*86400+3600*aStartHour+60*aStartMinute;
|
||||
//--- session end time since the week start
|
||||
int StopTime=aStopDay*86400+3600*aStopHour+60*aStopMinute;
|
||||
//--- current time in seconds since the week start
|
||||
long TimeCur=SecondsFromWeekStart(aTimeCur,false);
|
||||
if(StopTime<StartTime)
|
||||
{
|
||||
//--- passing the turn of the week
|
||||
if(TimeCur>=StartTime || TimeCur<StopTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- within one week
|
||||
if(TimeCur>=StartTime && TimeCur<StopTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the leap year by date |
|
||||
//| aTime - date-time |
|
||||
//+------------------------------------------------------------------+
|
||||
bool LeapYear(datetime aTime)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
TimeToStruct(aTime,stm);
|
||||
//--- a multiple of 4
|
||||
if(stm.year%4==0)
|
||||
{
|
||||
//--- a multiple of 100
|
||||
if(stm.year%100==0)
|
||||
{
|
||||
//--- a multiple of 400
|
||||
if(stm.year%400==0)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
//--- not a multiple of 100
|
||||
else
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function for determining the number of days in a month by date |
|
||||
//| aTime - date-time |
|
||||
//+------------------------------------------------------------------+
|
||||
int DaysInMonth(datetime aTime)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
TimeToStruct(aTime,stm);
|
||||
if(stm.mon==2)
|
||||
{
|
||||
//--- February
|
||||
if(LeapYear(aTime))
|
||||
{
|
||||
//--- February in a leap year
|
||||
return(29);
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- February in a non-leap year
|
||||
return(28);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//--- other months
|
||||
return(31-((stm.mon-1)%7)%2);
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,100 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| TimePoint.mq5 |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
//--- plot TimePoint
|
||||
#property indicator_label1 "TimePoint"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- input parameters
|
||||
input int Hour=14;
|
||||
input int Minute=0;
|
||||
//--- indicator buffers
|
||||
double TimePointBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,TimePointBuffer,INDICATOR_DATA);
|
||||
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,169);
|
||||
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,10);
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
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[])
|
||||
{
|
||||
int start=1;
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
start=prev_calculated-1;
|
||||
}
|
||||
for(int i=start;i<rates_total;i++)
|
||||
{
|
||||
if(TimeCross(Hour,Minute,time[i],time[i-1]))
|
||||
{
|
||||
TimePointBuffer[i]=low[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
TimePointBuffer[i]=EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool TimeCross(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
|
||||
{
|
||||
//--- specified time since the day start
|
||||
datetime PointTime=aHour*3600+aMinute*60;
|
||||
//--- current time since the day start
|
||||
aTimeCur=aTimeCur%86400;
|
||||
//--- previous time since the day start
|
||||
aTimePre=aTimePre%86400;
|
||||
if(aTimeCur<aTimePre)
|
||||
{
|
||||
//--- going past midnight
|
||||
if(aTimeCur>=PointTime || aTimePre<PointTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(aTimeCur>=PointTime && aTimePre<PointTime)
|
||||
{
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,105 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| TradeWeekDays.mq5 |
|
||||
//| Copyright 2011, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_separate_window
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 2
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
//--- plot Session
|
||||
#property indicator_label1 "TradeWeekDays"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- input parameters
|
||||
input bool Sunday = false; // Sunday
|
||||
input bool Monday = false; // Monday
|
||||
input bool Tuesday = true; // Tuesday
|
||||
input bool Wednesday = true; // Wednesday
|
||||
input bool Thursday = true; // Thursday
|
||||
input bool Friday = false; // Friday
|
||||
input bool Saturday = false; // Saturday
|
||||
|
||||
bool WeekDays[7];
|
||||
//--- indicator buffers
|
||||
double SessionBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
WeekDays_Init();
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,SessionBuffer,INDICATOR_DATA);
|
||||
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,159);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
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[])
|
||||
{
|
||||
int start=0;
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
start=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
start=prev_calculated-1;
|
||||
}
|
||||
for(int i=start;i<rates_total;i++)
|
||||
{
|
||||
if(WeekDays_Check(time[i]))
|
||||
{
|
||||
SessionBuffer[i]=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SessionBuffer[i]=EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
void WeekDays_Init()
|
||||
{
|
||||
WeekDays[0]=Sunday;
|
||||
WeekDays[1]=Monday;
|
||||
WeekDays[2]=Tuesday;
|
||||
WeekDays[3]=Wednesday;
|
||||
WeekDays[4]=Thursday;
|
||||
WeekDays[5]=Friday;
|
||||
WeekDays[6]=Saturday;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
bool WeekDays_Check(datetime aTime)
|
||||
{
|
||||
MqlDateTime stm;
|
||||
TimeToStruct(aTime,stm);
|
||||
return(WeekDays[stm.day_of_week]);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user