Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1299

 
Alexey Viktorov:

You have to check in the debugger. I can't say for sure.

Got it, thanks.

 
Friends,please advise how to prescribe a code in the advisor to trade only in one direction Buy or Sell
 
Alexanerhoch:
Friends,please advise how to prescribe a code in the advisor to trade only in one direction Buy or Sell

F7 - general - shopping only

 
Iurii Tokman:

F7 - general - purchases only

no such thing in mt5

 
Alexanerhoch:
Friends,please advise how to prescribe a code in the advisor to trade only in one direction Buy or Sell

That's the way it is;

enum typ
  {
                        ty1=0,                  //Buy and Sell
                        ty2=1,                  //Only Buy
                        ty3=2                   //Only Sell
  };

input typ               TradesType=ty1;         //Type of trading operations
.
.
.
if(TradesType!=2 && ...
if(TradesType!=1 && ...
 
VVT:

That's the way it is;

Thank you

 

Good afternoon, colleagues. I can't find an error in the code. The .Magic() method of theCPositionInfo class gives the correct value, if the trade is opened directly in the code through the Trade.mqh class.

If I open a deal through Trade.mqh, but called in another class, then the.Magic() method gives 0 in the Expert Advisor code. Why is it so?

I am attaching the code.

Files:
MQL5.zip  5 kb
 
Ildar Yusupov:

Good afternoon, colleagues. I can't find an error in the code. The .Magic() method of theCPositionInfo class gives the correct value, if the trade is opened directly in the code through the Trade.mqh class.

If I open a deal through Trade.mqh, but called in another class, then the.Magic() method gives 0 in the Expert Advisor code. Why is it so?

I am attaching the code.

I do not open the code)

So, the second variant does not use Magic, look carefully at the code

 
Ildar Yusupov:

Good afternoon, colleagues. I can't find an error in the code. The .Magic() method of theCPositionInfo class gives the correct value, if the trade is opened directly in the code through the Trade.mqh class.

If I open a deal through Trade.mqh, but called in another class, then the.Magic() method gives 0 in the Expert Advisor code. Why is it so?

I am attaching the code.

I haven't even looked at the archive.

The algorithm is always the following: You create 'm_trade' - object of CTrade class. If you want it to trade by its Magic - you must do

   m_trade.SetExpertMagicNumber(InpMagic);

- That is, you must set this Magic for the object of CTrade class.

 
Vitaly Muzichenko:

there's no such thing in mt5.

I'm doing it the old-fashioned way, I can't get out of it...

Reason: