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
- In code:
Risk depends on your initial stop loss, lot size, and the value of the pair.
- 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.
- 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.)
-
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. - You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
- 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; }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.