//+------------------------------------------------------------------+ //| AI Owner Groups Setup.mq5 | //| Copyright 2026, Allan Munene Mutiiria. | //| https://t.me/Forex_Algo_Trader | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, Allan Munene Mutiiria." #property link "https://t.me/Forex_Algo_Trader" #property version "1.00" #property script_show_inputs #include //+------------------------------------------------------------------+ //| Inputs | //+------------------------------------------------------------------+ input int InpEaMagic = 12345; // Magic Number Of The AI Program (Match Its Input) input int InpOtherMagic = 777; // Magic Number Standing In For Another Robot input double InpLots = 0.01; // Lot Size Of Each Position input int InpPerGroup = 1; // Positions To Open In Each Owner Group //+------------------------------------------------------------------+ //| Global Variables | //+------------------------------------------------------------------+ CTrade trade; // Send the market orders //+------------------------------------------------------------------+ //| Open one owner group of positions under a magic number | //+------------------------------------------------------------------+ int OpenGroup(const long magic, const string label) { //--- Stamp this group's magic number on every order trade.SetExpertMagicNumber(magic); //--- Count the positions that actually open int opened = 0; for(int i = 0; i < InpPerGroup; i++) { //--- Alternate buys and sells so each group carries both directions const bool ok = (i % 2 == 0) ? trade.Buy(InpLots, _Symbol, 0.0, 0.0, 0.0, label) : trade.Sell(InpLots, _Symbol, 0.0, 0.0, 0.0, label); //--- Report a refused order and carry on with the rest if(!ok) Print(label, " order refused: ", trade.ResultRetcodeDescription()); else opened++; } //--- Hand back how many positions this group holds return opened; } //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- Refuse to run anywhere but a demo account if(AccountInfoInteger(ACCOUNT_TRADE_MODE) != ACCOUNT_TRADE_MODE_DEMO) { Print("This script opens test positions, so it only runs on a demo account"); return; } //--- Refuse a netting account, which would merge the groups into one position if(AccountInfoInteger(ACCOUNT_MARGIN_MODE) != ACCOUNT_MARGIN_MODE_RETAIL_HEDGING) { Print("This script needs a hedging account so each owner group keeps its own positions"); return; } //--- Open the group the AI program owns const int ea = OpenGroup(InpEaMagic, "AI program group"); //--- Open the group with magic zero, which the program reads as hand-placed const int manual = OpenGroup(0, "Manual group"); //--- Open the group standing in for another robot const int other = OpenGroup(InpOtherMagic, "Other robot group"); //--- Report what is now open on the chart symbol PrintFormat("Opened %d AI program, %d manual and %d other robot positions on %s", ea, manual, other, _Symbol); } //+------------------------------------------------------------------+