MT5 - problems when running multiple EAs on same pair, same timeframe and different chart window

 

Hi, I faced some problems about running multiple EAs on same pair, same timeframe and different chart window.


1. Example: ea1 and ea2 open each own a 'buy' position with different (or same) price, sl, tp, lotSize, time opening and store position ticket number. But both ea1, ea2 store the same ticket number, therefor ea that didn't open this ticket number can modify this position.

FYI, each EA have unique magic number, use PositionGetTicket(0) to get ticket number and store it in global variable, each ea check that can not open more than 1 position, open position using cTrade.PositionOpen(currentSymbol, orderType, lotSize, price, sl, tp, "comment").

When modify position, I select it by PositionSelectByTicket(ticketNumber).


2. Another problem is that sometimes ea can not open position using PositionOpen function, MT5 notify for me like: request requote ... (deviation: 10)


3. I have function to modify position using PositionClosePartial function, but sometimes it doesn't work (deviation value = 1). Is this better to use deviation default value = ULONG_MAX or set it > 1 like 10 or 15?

 

For this you can define a magic number in the request:

magic

Expert Advisor ID. It allows organizing analytical processing of trade orders. Each Expert Advisor can set its own unique ID when sending a trade request.

(from https://www.mql5.com/en/docs/constants/structures/mqltraderequest

And with PositionGetInteger() (or OrderGetInteger() ...)  you can get and check it so each EA is able to know whether a position is its or not.

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Trade Request Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Carl Schreiber #:

For this you can define a magic number in the request:

magic

Expert Advisor ID. It allows organizing analytical processing of trade orders. Each Expert Advisor can set its own unique ID when sending a trade request.

(from https://www.mql5.com/en/docs/constants/structures/mqltraderequest

And with PositionGetInteger() (or OrderGetInteger() ...)  you can get and check it so each EA is able to know whether a position is its or not.

Thanks, I'll try that. Any idea for my others problem?
 

add 2) requote: https://www.mql5.com/en/search#!keyword=requote&module=mql5_module_articles

add 3) depends on the symbol (specifications), broker, market, ...

 
Carl Schreiber #:

add 2) requote: https://www.mql5.com/en/search#!keyword=requote&module=mql5_module_articles

add 3) depends on the symbol (specifications), broker, market, ...

great, thanks