为什么当第二个箭头指示器出现时,EA 不执行任何操作?

Why is it that when the second arrow indicator shows up the EA doesn't execute anything?

我已经在 Expert Advisor 上编写了一些代码以在斐济趋势指标上进行交易。 EA 识别第一个箭头指标并相应地执行交易,但是,当第二个箭头应该出现在回溯测试中时,其余代码不执行任何操作。

我看到当 EA 执行第一笔交易时,图表上买入价后面的指标中的自定义价格框停止向上或向下移动,也许这就是问题所在?

double CloseAllTradesThisPair()
{
 for (int i=OrdersTotal();i>=0;i--)
  {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if (OrderSymbol()==Symbol())
    {
     OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),10,Red);
    }
  }
}
extern bool bought = false;
extern bool sold = false;

double Lotsize = AccountBalance()/5000;
double Lots = NormalizeDouble(Lotsize,2);

void OnTick()
 {
  for(int i=0;i<OrdersTotal();i++)
   {
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    return(0);
   }
  double uparrow = iCustom(Symbol(),PERIOD_CURRENT,"fiji-trend-indicator",2,0);
  double dnarrow = iCustom(Symbol(),PERIOD_CURRENT,"fiji-trend-indicator",3,0);
  
  if(uparrow < 1000 && i==0)
   {
    double buyticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,10,0,0,NULL,0,0,Green);
    bought = true;
   }
   if(dnarrow < 1000 && i==0)
    {
     double sellticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,10,0,0,NULL,0,0,Red);
     sold = true;
    }
   if(bought != true && dnarrow < 1000 )
    {
     CloseAllTradesThisPair();
     double sticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,10,0,0,NULL,0,0,Red);
    }
     
   if(sold != true && uparrow < 1000)
    {
     CloseAllTradesThisPair();
     double bticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,10,0,0,NULL,0,0,Green);
    }

}

Q : "when the EA executes the first trade, maybe that's where thing go wrong?"

哦,当然是。

根据代码,EA 完全按照 void OnTick(){...} 代码中的指示执行:

...
for ( int i = 0; i < OrdersTotal(); i++ )
{
    OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
    return( 0 ); // _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _THE_TERMINATOR_ >>> FINITO...
    }
...

这个片段什么都不做,直到下了第一个订单(然后 i 停止以满足条件 < OrdersTotal()

其余的很明显:return( 0 ); ...除了 return 的缺陷 void... 通过 OnTick() 代码在所有下一个 code-passes 无一例外地终止,因此有效地避免了任何交易: