141 lines
12 KiB
MQL5
141 lines
12 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| ACM_Snipper.mq5 |
|
|
//| Anderson C Mourão |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Anderson C Mourão"
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
|
|
#property strict
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
|
|
#include <Trade/Trade.mqh>
|
|
#include <Trade/PositionInfo.mqh>
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
|
|
CTrade trade;
|
|
bool order_sent;
|
|
datetime tm = TimeCurrent();
|
|
MqlDateTime stm, date_struct = {};
|
|
|
|
datetime vTradingStartTime = 0;
|
|
datetime vTradingEndTime = 0;
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit() {
|
|
TimeToStruct(tm, stm);
|
|
//--- escrevemos os valores de entrada nos campos correspondentes da estrutura
|
|
date_struct.year = stm.year;
|
|
date_struct.mon = stm.mon;
|
|
date_struct.day = stm.day;
|
|
//--- convertemos a data e a hora da estrutura em uma variável com o tipo datetime e
|
|
datetime dia_hoje = StructToTime(date_struct);
|
|
Print("Inicializando EA..");
|
|
vTradingStartTime = dia_hoje + 9 * 3600;
|
|
vTradingEndTime = dia_hoje + 17 * 3600;
|
|
Print("Hora local = ", tm, " Hora abertura = ", vTradingStartTime, " Hora fechamento = ", vTradingEndTime);
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason) {
|
|
Print("Finalizando..");
|
|
//--- "clear" comment
|
|
Comment("");
|
|
PrintAccountInfo();
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick() {
|
|
// Check if trading is allowed based on the defined start and end times
|
|
if(IsTradingBlocked()) {
|
|
// If not allowed, stop processing the rest of the OnTick function
|
|
Print("Fora do horário de mercado!");
|
|
CloseAllOpenOrders();
|
|
ExpertRemove();
|
|
}
|
|
BotLettus123();
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
void CloseAllOpenOrders() {
|
|
Print("Fechando todas as ordens abertas!");
|
|
int total_orders = OrdersTotal();
|
|
for(int i = total_orders - 1; i >= 0; i--) { //decrescente mesmo, vai ate 0
|
|
ulong ticket = OrderGetTicket(i);
|
|
trade.OrderDelete(ticket);
|
|
}
|
|
trade.PositionClose(_Symbol);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| PrintAccountInfo() |
|
|
//+------------------------------------------------------------------+
|
|
void PrintAccountInfo() {
|
|
//--- trade server name
|
|
string server = AccountInfoString(ACCOUNT_SERVER);
|
|
//--- account number
|
|
int login = (int)AccountInfoInteger(ACCOUNT_LOGIN);
|
|
//--- long value output
|
|
long leverage = AccountInfoInteger(ACCOUNT_LEVERAGE);
|
|
printf("%s %d: leverage = 1:%I64d",
|
|
server, login, leverage);
|
|
//--- account currency
|
|
string currency = AccountInfoString(ACCOUNT_CURRENCY);
|
|
//--- double value output with 2 digits after the decimal point
|
|
double equity = AccountInfoDouble(ACCOUNT_EQUITY);
|
|
printf("%s %d: account equity = %.2f %s",
|
|
server, login, equity, currency);
|
|
//--- double value output with mandatory output of the +/- sign
|
|
double profit = AccountInfoDouble(ACCOUNT_PROFIT);
|
|
printf("%s %d: current result for open positions = %+.2f %s",
|
|
server, login, profit, currency);
|
|
//--- double value output with variable number of digits after the decimal point
|
|
double point_value = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
|
|
string format_string = StringFormat("%%s: point value = %%.%df", _Digits);
|
|
printf(format_string, _Symbol, point_value);
|
|
//--- int value output
|
|
int spread = (int)SymbolInfoInteger(_Symbol, SYMBOL_SPREAD);
|
|
printf("%s: current spread in points = %d ",
|
|
_Symbol, spread);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Helper function to check if trading is allowed. |
|
|
//+------------------------------------------------------------------+
|
|
bool IsTradingBlocked() {
|
|
datetime now = TimeCurrent();
|
|
// Check if it's within the defined start and end times
|
|
return (now < vTradingStartTime || now > vTradingEndTime);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Robo Lettus123! |
|
|
//+------------------------------------------------------------------+
|
|
void BotLettus123() {
|
|
Print("Iniciando o Robo Lettus123!");
|
|
//--- Perform trading actions
|
|
double _bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
|
double _ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
|
printf("BID = %.2f ASK = %.2f", _bid, _ask);
|
|
ExpertRemove();
|
|
}
|
|
//+------------------------------------------------------------------+
|