-
double stochastic = iStochastic(Symbol(), PERIOD_M5, k, d, slowing, MODE_SMA, 0, MODE_MAIN, i); double signal = iStochastic(Symbol(), PERIOD_M5, k, d, slowing, MODE_SMA, 0, MODE_SIGNAL, i);
int buy = OrderSend(Symbol(), OP_BUY, 1.0, Ask, 5, 0, 0);
Why did you post your MT4 question in the 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? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
void TakeProfit(){ ⋮ if((OrderType() == OP_BUY)
MT4: You can not use any Trade Functions until you first select an order.
-
double BidPrice = MarketInfo(OrderSymbol(), MODE_BID); double AskPrice = MarketInfo(OrderSymbol(), MODE_ASK); if( OrderType() == OP_BUY ) res = OrderClose(OrderTicket(), OrderLots(), BidPrice, Slippage); else if(OrderType() == OP_SELL) res = OrderClose(OrderTicket(), OrderLots(), AskPrice, Slippage);
MT4: You can use OrderClosePrice() instead of Bid/Ask and be direction independent — no need to check order type to get the close price.
-
for(int i = (OrdersTotal() - 1); i >= 0; i--){ if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
PositionClose is not working - MQL5 programming forum (2020)
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good Afternoon
I've just started an EA, and I coded the Stochastic Oscillator aspect of it. Upon running it and checking results, i found that metatrader has closed the trade before the close signal and the opened a new trade.
All the trades of this nature all seem to close at approximately the same value.
This is the stochastic code:
This is the trade taking code:
This is the take profit code:
And this is the code to close the trade:
Has anyone had this issue before or can see an error in the code. I just can't it.
Any help will be appreciated.
Kind Regards