//+------------------------------------------------------------------+
//| MyExpert.mq4 |
//| Copyright 2024, Your Name |
//| https://www.example.com |
//+------------------------------------------------------------------+
#property strict
// Input parameters
input double initialLotSize = 0.01;
input double maxLotSize = 0.64;
input double takeProfitPips = 300;
input double stopLossPips = 300;
input int magicNumber = 123456;
// Global variables
double currentLotSize;
datetime londonOpenTime;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
currentLotSize = initialLotSize;
return INIT_SUCCEEDED;
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
// Check for London open (8:00 AM GMT)
if (TimeCurrent() >= londonOpenTime && TimeCurrent() < londonOpenTime + 60 * 60)
// Open initial trade
OpenTrade(ORDER_BUY);
OpenTrade(ORDER_SELL);
londonOpenTime = 0; // Reset to prevent multiple openings
// Manage open trades
ManageTrades();
//+------------------------------------------------------------------+
//| Open a trade |
//+------------------------------------------------------------------+
void OpenTrade(int orderType)
double price = (orderType == ORDER_BUY) ? Ask : Bid;
double takeProfit = price + (orderType == ORDER_BUY ? takeProfitPips * Point : -takeProfitPips *
Point);
double stopLoss = price - (orderType == ORDER_BUY ? stopLossPips * Point : stopLossPips * Point);
int ticket = OrderSend(Symbol(), orderType, currentLotSize, price, 3, stopLoss, takeProfit, "",
magicNumber, 0, clrNONE);
if (ticket < 0)
Print("Error opening order: ", GetLastError());
//+------------------------------------------------------------------+
//| Manage trades |
//+------------------------------------------------------------------+
void ManageTrades()
double lotSize = initialLotSize;
for (int i = OrdersTotal() - 1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS))
if (OrderMagicNumber() == magicNumber)
// Check for Take Profit
if (OrderProfit() >= takeProfitPips * Point || OrderProfit() <= -stopLossPips * Point)
double orderLotSize = OrderLots();
OrderClose(OrderTicket(), OrderLots(), MarketInfo(Symbol(), MODE_BID), 3, clrNONE);
// If it hit stop loss, double the lot size
if (OrderProfit() < 0)
currentLotSize = MathMin(currentLotSize * 2, maxLotSize);
OpenTrade(OrderType() == ORDER_BUY ? ORDER_SELL : ORDER_BUY); // Open
opposite trade
//+------------------------------------------------------------------+