mql5/Experts/ACM/ACM_Snipper.mq5

142 lines
12 KiB
MQL5
Raw Permalink Normal View History

2025-08-23 23:53:14 -03:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| ACM_Snipper.mq5 |
//| Anderson C Mour<EFBFBD>o |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Anderson C Mour<00>o"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
2025-08-24 21:26:54 -03:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2025-08-23 23:53:14 -03:00
2025-09-06 01:04:06 -03:00
#include <Trade/Trade.mqh>
#include <Trade/PositionInfo.mqh>
2025-08-24 20:41:30 -03:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2025-08-23 23:53:14 -03:00
2025-08-24 13:57:04 -03:00
CTrade trade;
bool order_sent;
2025-09-05 16:01:01 -03:00
datetime tm = TimeCurrent();
MqlDateTime stm, date_struct = {};
datetime vTradingStartTime = 0;
datetime vTradingEndTime = 0;
2025-08-23 23:53:14 -03:00
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
2025-09-05 16:01:01 -03:00
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<EFBFBD>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);
2025-08-23 23:53:14 -03:00
return(INIT_SUCCEEDED);
2025-09-05 16:01:01 -03:00
}
2025-08-24 21:26:54 -03:00
2025-08-23 23:53:14 -03:00
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
2025-09-05 16:01:01 -03:00
void OnDeinit(const int reason) {
2025-08-24 13:57:04 -03:00
Print("Finalizando..");
2025-08-25 02:00:12 -03:00
//--- "clear" comment
Comment("");
2025-09-05 16:01:01 -03:00
PrintAccountInfo();
}
2025-08-24 21:26:54 -03:00
2025-08-23 23:53:14 -03:00
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
2025-09-05 16:01:01 -03:00
void OnTick() {
2025-08-25 02:00:12 -03:00
// Check if trading is allowed based on the defined start and end times
2025-09-05 16:01:01 -03:00
if(IsTradingBlocked()) {
2025-08-25 02:00:12 -03:00
// If not allowed, stop processing the rest of the OnTick function
Print("Fora do hor<00>rio de mercado!");
CloseAllOpenOrders();
ExpertRemove();
2025-09-05 16:01:01 -03:00
}
BotLettus123();
}
2025-08-24 13:57:04 -03:00
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2025-09-05 16:01:01 -03:00
void CloseAllOpenOrders() {
Print("Fechando todas as ordens abertas!");
2025-08-24 13:57:04 -03:00
int total_orders = OrdersTotal();
2025-09-05 16:01:01 -03:00
for(int i = total_orders - 1; i >= 0; i--) { //decrescente mesmo, vai ate 0
2025-08-24 13:57:04 -03:00
ulong ticket = OrderGetTicket(i);
trade.OrderDelete(ticket);
2025-09-05 16:01:01 -03:00
}
trade.PositionClose(_Symbol);
}
2025-08-24 20:41:30 -03:00
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| PrintAccountInfo() |
//+------------------------------------------------------------------+
2025-09-05 16:01:01 -03:00
void PrintAccountInfo() {
2025-08-24 20:41:30 -03:00
//--- 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);
2025-09-05 16:01:01 -03:00
}
2025-08-24 13:57:04 -03:00
//+------------------------------------------------------------------+
2025-08-25 02:00:12 -03:00
//+------------------------------------------------------------------+
//| Helper function to check if trading is allowed. |
//+------------------------------------------------------------------+
2025-09-05 16:01:01 -03:00
bool IsTradingBlocked() {
2025-08-25 02:00:12 -03:00
datetime now = TimeCurrent();
// Check if it's within the defined start and end times
return (now < vTradingStartTime || now > vTradingEndTime);
2025-09-05 16:01:01 -03:00
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Robo Lettus123! |
//+------------------------------------------------------------------+
void BotLettus123() {
Print("Iniciando o Robo Lettus123!");
//--- Perform trading actions
2025-09-05 22:29:08 -03:00
double _bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double _ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
printf("BID = %.2f ASK = %.2f", _bid, _ask);
2025-09-05 16:01:01 -03:00
ExpertRemove();
}
2025-08-25 02:00:12 -03:00
//+------------------------------------------------------------------+
2025-08-23 23:53:14 -03:00