116 linhas
Sem EOL
4,6 KiB
MQL5
116 linhas
Sem EOL
4,6 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| EAFunctions.mqh |
|
|
//| Bahram Dolati |
|
|
//| bahram.dolati2@gmail.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Bahram Dolati"
|
|
#property link "bahram.dolati2@gmail.com"
|
|
//+------------------------------------------------------------------+
|
|
//| defines |
|
|
//+------------------------------------------------------------------+
|
|
// #define MacrosHello "Hello, world!"
|
|
// #define MacrosYear 2010
|
|
//+------------------------------------------------------------------+
|
|
//| DLL imports |
|
|
//+------------------------------------------------------------------+
|
|
// #import "user32.dll"
|
|
// int SendMessageA(int hWnd,int Msg,int wParam,int lParam);
|
|
// #import "my_expert.dll"
|
|
// int ExpertRecalculate(int wParam,int lParam);
|
|
// #import
|
|
//+------------------------------------------------------------------+
|
|
//| EX5 imports |
|
|
//+------------------------------------------------------------------+
|
|
// #import "stdlib.ex5"
|
|
// string ErrorDescription(int error_code);
|
|
// #import
|
|
//+------------------------------------------------------------------+
|
|
|
|
//This function counts the number open positions in direction we want in current EA.
|
|
int NumberOfActivePositions(string symbol, string comment, int magic, ENUM_POSITION_TYPE position_type, bool ignoreType=false)
|
|
{
|
|
|
|
int NumberOfOpenPositions=0;
|
|
for(int i= PositionsTotal()-1; i >=0; i--)
|
|
{
|
|
|
|
PositionGetTicket(i);
|
|
|
|
if(PositionGetSymbol(i) != symbol) continue;
|
|
if(!ignoreType && PositionGetInteger(POSITION_TYPE) != position_type) continue;
|
|
if(PositionGetInteger(POSITION_MAGIC) != magic) continue;
|
|
// if(PositionGetString(POSITION_COMMENT) != comment) continue;
|
|
NumberOfOpenPositions++;
|
|
|
|
|
|
|
|
|
|
}
|
|
return NumberOfOpenPositions;
|
|
}
|
|
|
|
bool IsNewBar(string symbol, ENUM_TIMEFRAMES timeframe, bool first_call=false){
|
|
static bool result = false;
|
|
if(!first_call) return(result);
|
|
|
|
static datetime previous_time=0;
|
|
datetime current_time = iTime(symbol, timeframe, 0);
|
|
result = false;
|
|
if(previous_time != current_time){
|
|
previous_time = current_time;
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
}
|
|
|
|
bool IsTradeAllowed(){
|
|
return ((bool)MQLInfoInteger(MQL_TRADE_ALLOWED)
|
|
&& (bool)TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)
|
|
&& (bool)AccountInfoInteger(ACCOUNT_TRADE_ALLOWED)
|
|
&& (bool)AccountInfoInteger(ACCOUNT_TRADE_EXPERT)
|
|
);
|
|
}
|
|
|
|
|
|
bool CheckTimeInputsValidity(int StartHour, int StartMinute, int FinishHour, int FinishMinute){
|
|
if(StartHour < 0 || StartHour > 23){
|
|
Print("Start Hour Value ", StartHour, " is INVALID. It should be Positive and LESS THAN 23!");
|
|
return false;
|
|
}
|
|
else if(StartMinute < 0 || StartMinute > 59){
|
|
Print("Start Minute Value ", StartMinute ," is INVALID. It should be Positive and LESS THAN 59!");
|
|
return false;
|
|
}
|
|
else if(FinishHour < 0 || FinishHour > 23){
|
|
Print("Finish Hour Value ", FinishHour ," is INVALID. It should be Positive and LESS THAN 23!");
|
|
return false;
|
|
}
|
|
else if(FinishMinute < 0 || FinishMinute > 59){
|
|
Print("Finish Minute Value ", FinishMinute , " is INVALID. It should be Positive and LESS THAN 59!");
|
|
return false;
|
|
}
|
|
else if( FinishHour < StartHour ){
|
|
Print("Finish Hour ", FinishHour , " should be BIGGER Than or EQUAL to Start Hour ", StartHour, "!");
|
|
return false;
|
|
}
|
|
else if(FinishHour == StartHour && FinishMinute < StartMinute){
|
|
Print( "IF Finish Hour ",FinishHour," and Start Hour ",StartHour," are equal, Then Finih Minute ", FinishMinute, " should be bigger or equal to Start Minute ", StartMinute );
|
|
return false;
|
|
}
|
|
else if (FinishHour == StartHour && FinishMinute == StartMinute){
|
|
Print( "Finish Hour ",FinishHour," is Equal to Start Hour ",StartHour," and Finih Minute ", FinishMinute, " is equal to Start Minute ", StartMinute, " So There is no time limit to trading." );
|
|
return false;
|
|
|
|
}
|
|
else return true;
|
|
|
|
|
|
}
|
|
|
|
int TimeToMinute(datetime now){
|
|
MqlDateTime dt;
|
|
TimeToStruct(now, dt);
|
|
return (dt.hour*60 + dt.min);
|
|
} |