File Explorer

Expert Advisors
Indicators
Scripts
Include Files

Tools

ExpertAdvisor.mq5
//+------------------------------------------------------------------+
//| Expert Advisor Template                                          |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>

input int FastMA_Period = 10;
input int SlowMA_Period = 20;
input double LotSize = 0.1;
input int StopLoss = 50;
input int TakeProfit = 100;

CTrade trade;

int OnInit()
{
   // Initialization code
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
   // Cleanup code
}

void OnTick()
{
   // Trading logic here
   double fastMA = iMA(NULL, 0, FastMA_Period, 0, MODE_SMA, PRICE_CLOSE, 0);
   double slowMA = iMA(NULL, 0, SlowMA_Period, 0, MODE_SMA, PRICE_CLOSE, 0);
   
   if(fastMA > slowMA)
   {
      trade.Buy(LotSize, NULL, 0, 0, StopLoss, TakeProfit, "Buy Order");
   }
   else if(fastMA < slowMA)
   {
      trade.Sell(LotSize, NULL, 0, 0, StopLoss, TakeProfit, "Sell Order");
   }
}

Output Console

> Initializing Expert Advisor...
> Indicators loaded successfully
> Waiting for new tick...
> New tick received at 2023.05.15 14:30:45
> Buy order executed at 1.2345