if(Ask > OrderOpenPrice()){ ⋮ if(!OrderClose(OrderTicket(), OrderLots(), Bid, 0, clrNONE)){
If the Ask goes one tick above the open price, the Bid (close price) is below the open price (by the spread.)
- 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 is 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.)
If the Ask goes one tick above the open price, the Bid (close price) is below the open price (by the spread.)
Are you mean the problem is the spread ? what do you suggest in this case of my function ?
Are you mean the problem is the spread ? what do you suggest in this case of my function ?
if(!OrderClose(OrderTicket(), OrderLots(), Bid, 0, clrNONE)){ //instead of using Bid in your case here try// OrderClosePrice()
In your case here Bid is used, try the other function i provided ;)
I've tried to change the function but it still closing above at OP_SELL and bellow at OP_BUY. Could you help me ?
Trying
void executeTakeProfit(int mn, double points){ double _diffPips = 0; if(OrdersTotal() > 0){ for(int x = 0; x < OrdersTotal(); x++){ if(OrderSelect(x, SELECT_BY_POS, MODE_TRADES)){ if(OrderMagicNumber() == mn && OrderSymbol() == Symbol()){ if(OrderType() == OP_BUY){ _diffPips = NormalizeDouble((OrderClosePrice() - OrderOpenPrice()) / _Point, Digits); if(_diffPips >= points){ RefreshRates(); if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, clrNONE)){ Comment("Take Profit Error - Buy", GetLastError()); } } }//buy if(OrderType() == OP_SELL){ _diffPips = NormalizeDouble((OrderClosePrice() - OrderOpenPrice()) / _Point, Digits); if(_diffPips <= points){ RefreshRates(); if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, clrNONE)){ Comment("Take Profit Error - Sell", GetLastError()); } } }//sell }//magic }//select }//for } }//execute take profit
I've tried to change the function but it still closing above at OP_SELL and bellow at OP_BUY. Could you help me ?
Trying
awkay now How On earth does an open order have a value for OrderClosePrice()
f(OrderType() == OP_BUY){ _diffPips = NormalizeDouble((OrderClosePrice() - OrderOpenPrice()) / _Point, Digits); if(_diffPips >= points){ RefreshRates(); if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, clrNONE)){ Comment("Take Profit Error - Buy", GetLastError()); } } }//buy if(OrderType() == OP_SELL){ _diffPips = NormalizeDouble((OrderClosePrice() - OrderOpenPrice()) / _Point, Digits); if(_diffPips <= points){ RefreshRates(); if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, clrNONE)){ Comment("Take Profit Error - Sell", GetLastError()); }
ok So we want a virtual Take
Profit. lets do this
Have Holder of the Pips you want for your take Profit
input int m_takeprofit = 40; //Take Profit in pips
then next we need to change that into the corrct Format
void executeTakeProfit(int mn, double points){ double _diffPips = 0; double takeprof; if(OrdersTotal() > 0){ for(int x = 0; x < OrdersTotal(); x++){ if(OrderSelect(x, SELECT_BY_POS, MODE_TRADES)){ if(OrderMagicNumber() == mn && OrderSymbol() == Symbol()){ takeprof = m_takeprofit * 10 * SymbolInfoDouble(OrderSymbol(),SYMBOL_POINT); if(OrderType() == OP_BUY){ _diffPips = NormalizeDouble((SymbolInfoDouble(OrderSymbol(),SYMBOL_BID) - OrderOpenPrice()) , SymbolInfoInteger(OrderSymbol(),SYMBOL_DIGITS)); if(_diffPips >= takeprof ){ RefreshRates(); if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, clrNONE)){ Comment("Take Profit Error - Buy", GetLastError()); } } }//buy if(OrderType() == OP_SELL){ _diffPips = NormalizeDouble((OrderOpenPrice() - SymbolInfoDouble(OrderSymbol(),SYMBOL_ASK)) , SymbolInfoInteger(OrderSymbol(),SYMBOL_DIGITS)); if(_diffPips >= takeprof ){ RefreshRates(); if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, clrNONE)){ Comment("Take Profit Error - Sell", GetLastError()); } } }//sell }//magic }//select }//for } }//execute take profit
I am not sure if there errors but u get the Idea hey
awkay now How On earth does an open order have a value for OrderClosePrice()
How does an open bar have a value for Close[0]? (rhetorical question)
It's the same sort of thing.
OrderClosePrice() is the last known value at the time that the order is selected, so for a buy, it will be the same as Bid and for a sell, the same as Ask.
OrderClosePrice() is the last known value at the time that the order is selected, so for a buy, it will be the same as Bid and for a sell, the same as Ask.
What, it doesn't make sense to me, but I understand the Close[0] example
I thought OrderclosePrice must be
accessed by
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) |
I am having a BrainShutdown trying to process that. lemme go sleep its 3 am my time

- 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'm trying to create a dynamic Take Profit programatically. To do this I am using OrderClose() to close the order when the difference of pips are ready. The problem is that it is closing above the OP_SELL and bellow OP_BUY and I don't know why it happens.
how could I fix this ?
See the image: https://imgur.com/B0LYbkC