Close trade at the close of current bar.
thank you for the help Keith
You don't.
- You can only close at the current market price.
- It is impossible to know the current candle close price, because it is impossible to know when a candle will close. A candle is closed when a tick arrives after the last possible second and a new candle is opened..
You don't.
- You can only close at the current market price.
- It is impossible to know the current candle close price, because it is impossible to know when a candle will close. A candle is closed when a tick arrives after the last possible second and a new candle is opened..
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 2014.04.04
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum 2011.05.06
Hello I am looking to close a trade that i am in for the duration of 1 bar based on the prev 2 bars. if the parameters fit i enter a trade, but when i set my takeprofit to the close of the current bar it will look to execute a close order immediately as it takes the current close price and not the actual close price. How do i get around this?
void OnTick() { //--- if(!CheckIfOpenOrdersByMagicNumber(MN)) { if (High[1] > High[2] && Close[1] < Close[2]) { Alert("Going short. Reversal Bar."); double stopLossPrice = High[1]; double takeProfitPrice = Close[0]; int OrderID = OrderSend(NULL,OP_SELL,OptimalLotSize(maxRiskPerTrade,MathAbs(Bid - stopLossPrice)/GetPipValue()),Bid,20,stopLossPrice,takeProfitPrice,NULL,MN); if (OrderID < 0) Alert("order rejected. Order error: " + GetLastError()); } else if (Low[1] < Low[2] && Close[1] > Close[2]) { Alert("Going long. Reversal Bar."); double stopLossPrice = Low[1]; double takeProfitPrice = Close[0]; int OrderID = OrderSend(NULL,OP_BUY,OptimalLotSize(maxRiskPerTrade,MathAbs(Ask - stopLossPrice)/GetPipValue()),Ask,20,stopLossPrice,takeProfitPrice,NULL,MN); if (OrderID < 0) Alert("order rejected. Order error: " + GetLastError()); } } }