Expert Advisor only opening 1 trade on GBP pairs

 
Hi there,

I have been writing a few expert advisors for the past weeks and mostly they work well but for some reason I often find that on GBP currency pairs some of them only open 1 trade and no more. I have looked at the code in the debugger and I get the error "no money" when I execute OrderCheck. It seems the margin is 10,000 and so there is no free margin with which to open a new position. I have checked the code at this point and there are no open orders or positions and so how does it think that there is no free margin? I am sorry if I am being a noob but I am stuck with this.

Thankyou,

Michael.
 
indigo79:
Hi there,

I have been writing a few expert advisors for the past weeks and mostly they work well but for some reason I often find that on GBP currency pairs some of them only open 1 trade and no more. I have looked at the code in the debugger and I get the error "no money" when I execute OrderCheck. It seems the margin is 10,000 and so there is no free margin with which to open a new position. I have checked the code at this point and there are no open orders or positions and so how does it think that there is no free margin? I am sorry if I am being a noob but I am stuck with this.

Thankyou,

Michael.

You broker's server is sending you that message. They think you don't have enough money to enter that trade so more than likely you are over-levered or y

 
I'm sorry I should have mentioned I am running the strategy tester on history data on my meta quotes demo account. Thankyou.
 
Margin issues usually means you are way over-leveraged. For MT4:
  1. In code: Risk depends on your initial stop loss, lot size, and the value of the pair.
    1. You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    2. Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers.
    4. You must normalize lots properly and check against min and max.
    5. You must also check FreeMargin to avoid stop out
    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5=0.1 Lots maximum.
  2. Use a GUI EA like mine (for MT4): Indicators: 'Money Manager Graphic Tool' indicator by 'takycard' Forum - Page 6
 

I am using MT5. I don't see why my code in the strategy tester is treating GBP pairs differently. I don't have anything in my code that differentiates anything based on the symbol. Also I am using 1:1 leverage.

This is my buy function in my framework that I have created:

static bool Buy( double lotsize, double ask, double sl, double tp, ulong expertMagicID)
   {
      bool orderOk = false;
      
      MqlTradeRequest request={0};
      MqlTradeResult  result={0};
      
      MqlTradeCheckResult checkResult={0};
                  
      request.action   = TRADE_ACTION_DEAL;                     // type of trade operation
      request.symbol   = Symbol();                              // symbol
      request.volume   = lotsize;                                   // volume of 0.2 lot
      request.type     = ORDER_TYPE_BUY;                       // order type
      request.price    = ask; // price for opening
      request.deviation = 30;   
      request.sl = sl;  
      request.tp = tp;                        // allowed deviation from the price
      request.magic    = expertMagicID;   
      
      bool orderCheckOk = OrderCheck( request, checkResult );  
      
      if ( orderCheckOk == true )
      {
         
         orderOk = OrderSend( request, result );
         
         if ( orderOk == false )
         {
            Comment( result.comment );
         }
      }
      else
      {
         Comment( checkResult.comment );
      }

      return orderOk;
   }
Reason: