2

在 MetaTrader4 终端中,我编写了一个简单的警报 EA

我想在所有 FOREX Majors 和 FOREX Minors 上运行我的 EA,我已经完成了我的代码,但我希望它自动在我的 [ Market Watch ] 面板中的所有符号上运行。

这是我的代码,非常简单,有人可以帮我看看如何让它在我的市场观察中的所有符号或符号上自动运行吗?

   double RSI            = iRSI(        NULL,15, 7,PRICE_CLOSE,0 );
   double Stoc           = iStochastic( NULL,15, 5,3,3,MODE_SMA,STO_LOWHIGH,0,0);
   double BoliUpper      = iBands(      NULL,15,20,2,0,PRICE_MEDIAN,1,1 );
   double BoliLower      = iBands(      NULL,15,20,2,0,PRICE_MEDIAN,2,1 );
   double CandlePrevHigh = iOpen(       NULL,15, 1 );
   double CandlePrevLow  = iClose(      NULL,15, 1 );

   if ((RSI > 75) && (Stoc > 80)&& (BoliUpper < CandlePrevHigh) )
   {
       Alert(Symbol()+" is over bought");
   }
   else if ((RSI < 25) && (Stoc < 20)&&(BoliLower>CandlePrevLow))
   {
       Alert(Symbol()+" is over sold");
   }
4

2 回答 2

1

只需像这样遍历符号:

string syms[] = {"EURUSD","USDJPY"}; // Currency pair symbol array

for(int i=0; i < ArraySize(syms); i++) {
 double RSI = iRSI( syms[i], 15, 7,PRICE_CLOSE,0 );
 // ...
}

因此,只需将所有 'NULL' 替换为syms[i].

要获得市场观察符号,您需要添加一些代码,但在这里这里您可以找到一些免费代码/库来帮助您做到这一点。

于 2018-06-29T08:43:57.413 回答
-1

我怎样才能让它在所有符号上自动运行?

两件事情:

1)不是将代码设计为 EA,而是设计为脚本(以便让您的代码执行不受本地图事件流的影响

2)将逻辑“包装”成一个for循环,最好的智能快捷方式,以便扫描您选择的所有交易工具:

...
   for ( int anInstrumentNAME_INDEX =  0;
             anInstrumentNAME_INDEX < ArraySize( anInstrumentNAME_ARRAY );
             anInstrumentNAME_INDEX++
             )
   {  string anInstrumentNAME = anInstrumentNAME_ARRAY[anInstrumentNAME_INDEX] );

      double aFetchedLastPRICE =  iClose( anInstrumentNAME, PERIOD_CURRENT, 0 );
      if (   aFetchedLastPRICE == 0 )
      {   // 0: signals that the requested piece of data is not in Terminal's local datastore
          // get Error# + analyse + remedy
             continue;
      }
      if (   anInstrumentPRICE[anInstrument_NAME_INDEX] == aFetchedLastPRICE ) continue; // .WAS the same, loop
      else   anInstrumentPRICE[anInstrument_NAME_INDEX] =  aFetchedLastPRICE;            // .STO

      runAsync_MonitorOnThisOne( anInstrumentNAME );

   }

void runAsync_MonitorOnThisOne( string aSymbolNAME )
{    double RSI         =        iRSI( aSymbolNAME, 15,  7, PRICE_CLOSE, 0 );
     double Stoc        = iStochastic( aSymbolNAME, 15,  5, 3, 3, MODE_SMA, STO_LOWHIGH, 0, 0 );
     double BoliUpper        = iBands( aSymbolNAME, 15, 20, 2, 0, PRICE_MEDIAN, 1, 1 );
     double BoliLower        = iBands( aSymbolNAME, 15, 20, 2, 0, PRICE_MEDIAN, 2, 1 );   
     double CandlePrevHigh   = iOpen(  aSymbolNAME, 15,  1 );
     double CandlePrevLow    = iClose( aSymbolNAME, 15,  1 );

     if (  ( RSI       >  75 )
        && ( Stoc      >  80 )
        && ( BoliUpper <  CandlePrevHigh )
           )
    {
           Alert( aSymbolNAME + " is over bought [BEWARE, THIS BLOCKS...] " );
    }
    else if (  ( RSI       <  25 )
            && ( Stoc      <  20 )
            && ( BoliLower >  CandlePrevLow )
               )
         {
               Alert( aSymbolNAME + " is over sold [BEWARE, THIS BLOCKS... ]" );
         }
}
于 2018-05-11T18:35:50.170 回答