Why am I failing to open short positions in mql5?

 

I have used this line of code to open a long positions, and it works well:

trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, 1.0, SymbolInfoDouble(_Symbol, SYMBOL_ASK), 0, 0, NULL);

However, when I try the same thing with the short positions, no sell position is opened:

trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, 1.0, SymbolInfoDouble(_Symbol, SYMBOL_BID), 0, 0, NULL);
What's the problem?
 
Read the log entries of the Journal and the Expert then you know why.
 
Your topic has been moved to the section: Expert Advisors and Automated Trading — In the future, please consider which section is most appropriate for your query.
 
mohammad sh:I have used this line of code to open a long positions, and it works well: However, when I try the same thing with the short positions, no sell position is opened:What's the problem?

Are you checking the error code and the trade result code?

They will tell you the reason for the failure. "Print" them out. It will be reported in the Journal log as well.

Show us the log output if you are not able to resolve it

 

I checked the journal and I think I found out what is the problem. There were two kinds of warnings:

1) "failed exchange sell 1 BTC.jt at 18080.67 [Only long positions are allowed]"

I think that means the broker only allows long positions. So, I used a different broker and a different market.

2) "failed instant sell 0.01 EURUSD at 1.09113 sl: 1.08914 tp: 1.09214 [Invalid stops]"

I think the stop loss (sl) and take profit (tp) values I used were calculated wrongly. I changed them and the warning was resolved.

 
Brokers can forbid trades in the more profitable direction if a trend is all too clear. Compare it to sports bookmakers giving the better quote on the victory of the worse team and vis versa.

But I am not sure if it is only in crypto. I have seen it in BTC, too.
Reason: