開倉條件透過Magic number計算總持倉量

 

嘿,我是程式設計新手,這是我的第一個 EA。

我使用 PositionsTotal()<=0 來計算所有位置,現在我想使用Magic number來計算。

if(PriceInfo[1].open > Buffer_belowlin_FS[1] && PriceInfo[1].open > MyEaArray[1] && MACDNumber[1] > 0)
         {signal ="buy";}      
         
          if( signal =="buy" && PositionsTotal()<=0){
         trade.Buy.....
}


寫了一段用magic number計算倉位 可是不知道怎樣套用到我原本開倉條件上

  int positions = 0;
  for(int i=0; i<PositionsTotal(); i++)
     {
   ResetLastError();

   string symbol = PositionGetSymbol(i); {
     
   long pos_magic = PositionGetInteger(POSITION_MAGIC);  
  
   if(pos_magic == MagicNumber && _Symbol==symbol)
    {
     positions++;
      }
    }
  }

      if((emaFast[2] >= emaSlow[2] && emaFast[0] < emaSlow[0]) && (maTrend[1] < 50 && maTrend[1] > 30) && high <= emaFast[1])
      {signal ="sell";}
       
        if(signal =="sell" && (positions<=0)){
  
         trade.Sell.....
}
 

FYI.

int positions = 0;
for(int i=0; i<PositionsTotal(); i++)
{
   ulong ticket = PositionGetTicket(i);
   if(ticket>0)
   {
      ulong pos_magic = PositionGetInteger(POSITION_MAGIC);
      string symbol =  PositionGetString(POSITION_SYMBOL);
      if(pos_magic == MagicNumber && symbol == _Symbol)
      {
         positions++;
      }
   }
}

bool signalBuy = false, signalSell = false;


if(positions == 0 && PriceInfo[1].open > Buffer_belowlin_FS[1] && PriceInfo[1].open > MyEaArray[1] && MACDNumber[1] > 0)
{
   signalBuy = true;
}

if( positions == 0 && emaFast[2] >= emaSlow[2] && emaFast[0] < emaSlow[0]  && (maTrend[1] < 50 && maTrend[1] > 30) && high <= emaFast[1])
{
   signalSell = true;
}


if(signalBuy)
{
   trade.Buy(...);
}


if(signalSell)
{
   trade.Sell(...);
}

//+------------------------------------------------------------------+
 
Ziheng Zhuang # :

FYI.

Thank you so much