EA only works on 1 broker - page 2

 
ceejay1962 #:

I downloaded tradesessions.mqh from the forum a while ago. It works pretty well:

This is working great on backtests, ill leave it runing on a live chart to verify

 
Conor Mcnamara #:

different brokers use a different filling...and nobody seems to set request.type_filling to the correct filling

You should reveal the part of the code where you execute orders. I bet you're using the request structure

I'm actually using the CTrade class. I find it simpler, tho it seems the problems never end, I started getting a Volume limit reached and limit volume errors in backtest. Looking into that now


void SendBuyOrder (double entry) 
{  
   // Check if there is already a Sell Stop order at the same price level
    if (IsOrderAtPrice(entry, ORDER_TYPE_BUY_STOP))
    {
        Print("Sell Stop order already exists at price: ", entry);
        return; // Exit the function if an order already exists at this level
    }
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
 
   if(ask > entry - OrderDistPoints * _Point) return;
   double tp = entry + Tppoints * _Point ;
   double sl = entry - Slpoints * _Point;
   
   
     
   sl = entry - Slpoints * _Point;
    
   tp = entry + Tppoints * _Point;
     
   double lots = 0.01;
   if (riskPercent > 0) lots = calcLots (entry-sl);
   datetime expiration = iTime(_Symbol, timeFrame, 0) + expirationBars * PeriodSeconds (timeFrame);
   
   if(!trade.BuyStop(lots, entry, _Symbol, sl, tp, ORDER_TIME_SPECIFIED, expiration)) TesterStop();
}

void SendSellOrder (double entry) 
{
   // Check if there is already a Sell Stop order at the same price level
    if (IsOrderAtPrice(entry, ORDER_TYPE_SELL_STOP))
    {
        Print("Sell Stop order already exists at price: ", entry);
        return; // Exit the function if an order already exists at this level
    }
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   if(bid < entry + OrderDistPoints * _Point) return;
   double tp = entry - Tppoints * _Point;
   
   double sl = entry + Slpoints*_Point;
   

   tp = entry - Tppoints * _Point;
     

   sl = entry + Slpoints * _Point;
 
     
   double lots = 0.01;
   if (riskPercent > 0) lots = calcLots (sl-entry);
   datetime expiration = iTime (_Symbol, timeFrame,0) + expirationBars * PeriodSeconds(timeFrame);
   if(!trade. SellStop (lots, entry, _Symbol, sl, tp, ORDER_TIME_SPECIFIED, expiration)) TesterStop();
}
 

Ive added checks for max volume an volume limit to my lot-size calculation. Despite that im still getting "Volume limit reached" and "Limit Volume".

if I do this(subtract by 10 lots instead of o.1) It works just fine. 1 lot didnt work either. How does this work?

if (lots >= SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX)) lots = lots - 10;
   return lots;
double calcLots (double _slPoints) 
{
   double lots = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   double AccountBalance = AccountInfoDouble(ACCOUNT_BALANCE);
   double EquityBalance = AccountInfoDouble(ACCOUNT_EQUITY);
   double FreeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
      
   double risk=0;
   switch(LotType)
   {
    case 0: lots= FixedLots; return lots;
    case 1: risk = AccountBalance * riskPercent / 100; break;
    case 2: risk = EquityBalance * riskPercent / 100; break;
    case 3: risk = FreeMargin * riskPercent / 100; break;
   }
  
   
   double ticksize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
   double tickvalue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
   double lotstep = SymbolInfoDouble (_Symbol, SYMBOL_VOLUME_STEP);
   double minvolume=SymbolInfoDouble (Symbol(), SYMBOL_VOLUME_MIN);
   double maxvolume=SymbolInfoDouble (Symbol(), SYMBOL_VOLUME_MAX);
   double volumelimit = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_LIMIT);
   
   double moneyPerLotstep = _slPoints / ticksize * tickvalue * lotstep;
   lots = MathFloor (risk / moneyPerLotstep) * lotstep;
   if(volumelimit!=0) lots = MathMin (lots, volumelimit);
   if(maxvolume!=0) lots = MathMin (lots, SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX));
   if(minvolume!=0) lots = MathMax (lots, SymbolInfoDouble (_Symbol, SYMBOL_VOLUME_MIN));
   lots = NormalizeDouble (lots, 2);
   
   if (lots >= SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX)) lots = lots - 1.0;
   return lots;
}