ent-testing/ent-testing.mq5
super.admin 1a8f6f22b7 convert
2025-05-30 14:53:02 +02:00

128 lines
4.2 KiB
MQL5

//+------------------------------------------------------------------+
//| ent-testing.mq5 |
//| Entr04y |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
//Include Functions
#include <Trade\Trade.mqh>
CTrade *Trade;
#include "ProcessTrades.mqh"
#include "indicator_includes/MacdSignal.mqh"
//Setup Variables
input int InpMagicNumber = 4200001;
input string InpTradeComment = __FILE__;
input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE;
//Global Variables
int TicksReceivedCount = 0;
int TicksProcessedCount = 0;
static datetime TimeLastTickProcessed;
string indicatorMetrics = ""; // reset metrics variable for each onTick
//+------------------------------------------------------------------+
//| Set up Indicators |
//+------------------------------------------------------------------+
// Define types for indicator function pointers, this allows us to use a variable name to call the function
typedef string (*C1_Func)(int);
typedef int (*C1_Handle)();
typedef string (*C2_Func)(int);
typedef int (*C2_Handle)();
// Set the specific function names from the include file to the generic variable name
// C1 Variables
C1_Func C1GetOpenSignal = GetMacdOpenSignal;
C1_Handle C1IndicatorHandle = MacdIndicatorHandler;
// Create a variable to hold the handler for the C1 indicator
int HandleC1;
// C2 variables
//C2_Func C1GetOpenSignal = GetRSIOpenSignal;
//C2_Handle C1IndicatorHandle = RSIIndicatorHandler;
// Create a variable to hold the handle for the C1 indicator
//int HandleC2;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
// Declare Magic Number for all trades
Trade = new CTrade();
Trade.SetExpertMagicNumber(InpMagicNumber);
// set up handle for macd indicator
HandleC1 = C1IndicatorHandle();
Print("Handle for C1 /", Symbol(), " / ", EnumToString(Period()), " sucessfully created");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
IndicatorRelease(HandleC1);
Print("Handle Released");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
TicksReceivedCount++;
bool IsNewCandle = false;
if(TimeLastTickProcessed != iTime(Symbol(),Period(), 0))
{
IsNewCandle = true;
TimeLastTickProcessed = iTime(Symbol(),Period(), 0);
}
if(IsNewCandle == true)
{
//---Strategy Trigger MACD---///
TicksProcessedCount++;
indicatorMetrics = "";
string OpenSignalC1 = C1GetOpenSignal(HandleC1);
StringConcatenate(indicatorMetrics, Symbol(), " | Last Processed: ", TimeLastTickProcessed, " | MACD Bias: ", OpenSignalC1);
//---Enter Trades---//
if(OpenSignalC1 == "Long")
{
ProcessTradeOpen(ORDER_TYPE_BUY);
}
else
if(OpenSignalC1 == "Short")
{
ProcessTradeOpen(ORDER_TYPE_SELL);
}
}
Comment("\n\rExpert: ", InpMagicNumber, "\n\r",
"MT5 Server Time: ", TimeCurrent(), "\n\r\n\r",
"Ticks Received: ", TicksReceivedCount, "\n\r",
"Ticks Processed: ", TicksProcessedCount, "\n\r\n\r",
"Symbols Traded: \n\r",
Symbol(), indicatorMetrics);
}
//+------------------------------------------------------------------+