多币种交易架构设计参考代码

 
//+------------------------------------------------------------------+
//|                                                 MultiSymbols.mq4 |
//|                              BillAbiao,QQ:327151901,WX:billabiao |
//|                               https://one.exness.link/a/sduus6ff |
//+------------------------------------------------------------------+
#property copyright "BillAbiao,QQ:327151901,WX:billabiao"
#property link      "https://one.exness.link/a/sduus6ff"
#property version   "1.00"
#property strict

string userSymbols2[]={"EURUSD","GBPUSD","GBPCHF"};

string systemSymbols[];
string debugMsg;
double minEquity,maxEquity;
bool stopFlagRun=false;

//----------
struct CONTROL_DATA{
   int index;
   string strSymbol;
   ENUM_TIMEFRAMES timeFrame;//=PERIOD_H2;
   int    ExtHandle;
  // CTrade ExtTrade;
   int magicma;
   int switchDo;
   int orders_buy,orders_sell;
   int orders_pending_buy,orders_pending_sell;
   double minOpenPrice_buy,minOpenPrice_sell;
   ulong maxOpenPrice_buy_ticket;
   ulong minOpenPrice_buy_ticket;
   double maxOpenPrice_buy,maxOpenPrice_sell;
  
   double maxPendingOpenPrice_buy,maxPendingOpenPrice_sell;
   ulong maxPendingOpenPrice_buy_ticket,maxPendingOpenPrice_sell_ticket;
  
   double minPendingOpenPrice_buy,minPendingOpenPrice_sell;
   ulong minPendingOpenPrice_buy_ticket,minPendingOpenPrice_sell_ticket;
  
   double profit_buy,profit_sell;
   double volume_buy,volume_sell;
  
   ENUM_ORDER_TYPE signal;
  
   double agvLen;
  
   double minOpenPrice_profitBuy;
   double maxOpenPrice_profitBuy;
   double maxOpenPrice_volume;
   double minOpenPrice_buyVolume;
  
   double maxProfitBuy,minProfitBuy;
   datetime lastOpenDateTime;
   double maxPendingOpenPrice_volume;
   double magicN;
   double skip;
   ulong stopLevel;//=SymbolInfoInteger(d[index].strSymbol,SYMBOL_SPREAD);
   double point;
   ulong spread;
   double lastAsk;
   double ask,bid;
   int digits;
};

CONTROL_DATA d[];

#define MAGICMA 03082100
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   initSymbols();
   int n=ArraySize(systemSymbols);
   ArrayResize(d,n);
   for(int i=0;i<n;i++)
   {
      OnInit_INDEX(i);
   }
//---
   EventSetTimer(6);
   minEquity=0;
   maxEquity=0;
   return(INIT_SUCCEEDED);
  }
  void OnInit_INDEX(int index)
  {
      int k=index;
      d[k].index=index;
      d[k].strSymbol=systemSymbols[index];
      d[k].timeFrame=PERIOD_H1;
      d[k].magicma=MAGICMA+index;
      d[k].switchDo=1;
      d[k].maxProfitBuy=0;
      d[k].minProfitBuy=0;
      d[k].magicN=5;
      d[k].lastAsk=SymbolInfoDouble(d[k].strSymbol,SYMBOL_ASK);
      
  }
  
void initSymbols()
{
   int n=ArraySize(userSymbols2);
   ArrayResize(systemSymbols,n);
   int i;
   for(i=0;i<n;i++)
   {
     // systemSymbols[i]=userSymbols2[i];
      systemSymbols[i]=getSystemSymbol(userSymbols2[i]);
   }
   return ;
}
  
  string getSystemSymbol(string strSymbol)
{
   string ret="";
   int  n=SymbolsTotal(false);
   int i;
   string strTemp=strSymbol;
   StringToLower(strTemp);
   for(i=0;i<n;i++)
   {
      string name=SymbolName(i,false);
      StringToLower( name);
      if( strTemp==StringSubstr(name,0,6))
      {
         ret=SymbolName(i,false);
         break;
      }
      
   }
   return ret;
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   EventKillTimer();
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
      MainRUN( "Tick " );
      return ;

  }
  void OnTimer()
  {
      MainRUN( "Timer" );
      return ;
  }
  
  bool runFlag=false;
  void MainRUN( string strWho)
  {
      if( runFlag) return ;
      runFlag=true;
      debugMsg=strWho+": ";
      mainRun();
      runFlag=false;
      Comment(debugMsg);
      return ;
      
  }
  
//+------------------------------------------------------------------+



void mainRun()
{
   getMainData();
   if( stopFlagRun) return ;
   int i,n=ArraySize(d);
   for( i=0;i<n;i++)
   {
      subControlSymbol(i);
   }
  
   return ;
}


void  getMainData()
{
   debugMsg+="mainData,";
   debugMsg+=StringFormat("date=%s\n", TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS));
   double equity=AccountEquity();
   if( minEquity==0 || equity<minEquity) minEquity=equity;
   if( maxEquity==0 || equity>maxEquity) maxEquity=equity;
   debugMsg+=StringFormat("minEquity=%.2f,maxEquity=%.2f,Equity=%.2f\n",minEquity,maxEquity,equity);
   if( equity<10)
   {
      stopFlagRun=true;
   }
  
   return ;
  
}

void subControlSymbol(int index)
{
   debugMsg+=StringFormat("%d--> %s\n",index+1, d[index].strSymbol);
   control_getdata(index);
   switch (d[index].switchDo)
   {
      case 1:
         d[index].switchDo=2;
         control_open(index);
         break;
      case 2:
         d[index].switchDo=3;
         control_close(index);
         break;
      case 3:
         d[index].switchDo=1;
         control_modify(index);
         break;
   }
   //------
   debugMsg+="\n";
   return ;
}


void control_open(int index)
{
   debugMsg+="open\n";

   return ;
}




void control_close(int index)
{
   debugMsg+="close\n";
    
  
   return ;
  
}


void control_modify(int index)
{
   debugMsg+="modify\n";
  
}

void control_getdata(int index)
{

   return ;
}
  
 
能說明下用途嗎
 
学习下
原因: