- Request Execution - Opening and Closing Positions - Trade - MetaTrader 5 for iPhone
- Request Execution - Opening and Closing Positions - Trade - MetaTrader 5 for Android
- Instant Execution - Opening and Closing Positions - Trade - MetaTrader 5 for iPhone
Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
- Why did you post your MT4 question in the Root / MT5 General
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. -
double lots=NormalizeDouble((((AccountFreeMargin()*AccountLeverage())/Ask)/1000000),1);
Never risk more than a small percentage of your account, certainly less than 2% per trade, 6% total to the account.Risk depends on your initial stop loss, lot size, and the value of the pair. It does not depend on margin and leverage. No SL means you have infinite risk.
- 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.
- AccountBalance * 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 - MQL4 programming forum 2017.10.10
Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19 - You must normalize lots properly and check against min and max.
- 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 or 0.1 Lots maximum.
Your code if(Bid <= open - (retrace * Point)) { allowbuy = true; } else { allowbuy = false; }
Simplified allowbuy = Bid <= open - (retrace * Point);
-
ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,Bid-sl,Ask+tp,"day break",16384,0,Green); time_candle = iTime(Symbol(),PERIOD_D1,0); GlobalVariableSet("order_open", order_open + 1); GlobalVariableSet("time_candle", time_candle); GlobalVariableSet("buylocked",0); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError());
By the time you call GetLastError, you've already callled four other functions and have lost any real error. Check immediately! - Why are you calling those other functions if the OrderSend fails?
- You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell
orders you pay the spread on close.
- Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
- Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To
trigger at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 - The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
-
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+0.00011,OrderTakeProfit(),0,Green);
If you had checked your return codes for errors, and reported them including GLE/LE, your variable values and the market, we would know that at least you are calling your code. - Code breaks on JPY pairs and metals. PIP, Point, or Tick are all
different in general.
What is a TICK? - MQL4 programming forumUnless you manually adjust your SL/TP for each separate symbol, using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
How to manage JPY pairs with parameters? - MQL4 programming forum
Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum - objemmanuel1997: Please anyone coder here who can modify this will greatly appreciateUse the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use