0% found this document useful (0 votes)
68 views4 pages

MyExpert London EA

The document is an MQL4 script for an expert advisor that trades based on the London market opening time. It allows for customizable parameters such as initial lot size, maximum lot size, take profit, and stop loss values. The script includes functions for initializing, opening trades, and managing existing trades, with a strategy to double the lot size upon hitting a stop loss.

Uploaded by

Phillip_68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views4 pages

MyExpert London EA

The document is an MQL4 script for an expert advisor that trades based on the London market opening time. It allows for customizable parameters such as initial lot size, maximum lot size, take profit, and stop loss values. The script includes functions for initializing, opening trades, and managing existing trades, with a strategy to double the lot size upon hitting a stop loss.

Uploaded by

Phillip_68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

//+------------------------------------------------------------------+

//| 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

//+------------------------------------------------------------------+

You might also like