Closed with a loss even I coded profit > 0.0 - page 3

 
All of this is absolutely normal behaviour for a symbol with Market execution type.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
 

Maybe a solution could be just adjust the stoploss to broker stop level instead of close the position:

if profit > 0 then stoploss=SYMBOL_TRADE_STOPS_LEVEL

 
figurelli:

Maybe a solution could be just adjust the stoploss to broker stop level instead of close the position:

if profit > 0 then stoploss=SYMBOL_TRADE_STOPS_LEVEL

Maybe Not.

Lets assume you have a Long_Position. OpenPrice = 1.54321. ( Remember Buy_A ____&&____Sell_B ). Buy Ask ______ Sell Bid.

To close a Buy, we're looking to Sell which also means we're looking more at Bid price movements.

This is News time and and price is jumping around ( as in up and down ) by 20_pips.

The Current Tick just jumped_Up the Bid to 1.54421 and puts your position into Profit.

Your EA checks that your position profit is greater than 0 and that is True.

Your EA checks that your ClosePrice (the Bid) is greater than OpenPrice + 2_pips. Meaning >1.54341 and thats also True.

***** Now by the time the Broker receive your command to close || modify the position Bid will jump down to 1.54221.

If your order was to close the position, the broker would close you out at -Negative 10 pips from where you open...... with a loss.

If your order was to modify the stop-loss to break-even, you'll get an Error that the stoploss of 1.54321 > current price of 1.54221.

If you did succeed in changing the stop-loss to break-even or greater, your position will still be closed at 1.54221.

- The stop-loss order is a Pending_Stop Order which translate to <= This.Price. Is 1.54221 < 1.54321 ... Yes.

- I do-not think it'll let you set stop-losses above the OpenPrice (I could be wrong) , but this is what the Take-Profit Order is for.

So in this case, you'll be Better-Off modifying the Take-Profit (which is the same as Sell_Limit Orders). Sell_Limit means >= This.Price.

If the Symbol_Stop_Level is Zero or No_Minimum_Distance then setting the Take_Profit to break-even or higher might work.

This way, the order does-not close at a Loss but rather wait for Bid to jump back up again (if that ever happens).

There's no way to close the order at a Profit right now because the Price wouldn't be available when the broker receives the request.

 
i guess the more appropriate solution is to check if the spread is > than xx pips then decide whether to close the trade
 
Ubzen:

...

***** Now by the time the Broker receive your command to close || modify the position Bid will jump down to 1.54221.

...

If your order was to modify the stop-loss to break-even, you'll get an Error that the stoploss of 1.54321 > current price of 1.54221.

...


Note that my idea is change the stoploss and just use modify and never send close orders.

And if you get an error, that's ok, you will not close the position in a bad moment and this is why we are just using the stoploss.

 
doshur:
i guess the more appropriate solution is to check if the spread is > than xx pips then decide whether to close the trade
Things are not so easy, as Ubzen stated before you don't have such control in your order if the market changes very fast after you read the profit > 0.
 
figurelli:
Things are not so easy, as Ubzen stated before you don't have such control in your order if the market changes very fast after you read the price > 0.
Hmm true...
 
I think the best solution is to tighten my slippage, instead of using a dynamic value of spread, I use a fix value.