Questions from Beginners MQL5 MT5 MetaTrader 5 - page 63

 

Gumko:

Gumko : And how long is it going to take for this task to show up first...?

It's been standing for two days now.

I waited 8-10 days, then I gave up and turned it off.
 
I'm wondering how much CPU load the Tester software has in the background?
 

Hello all.

Modification and problems.

External function:

bool ModifyPosition(const string symbol,double StopLoss,double Takeprofit){
//---- binding structure and trade results
MqlTradeRequest request;
MqlTradeResult result;
//---- structure initialization of trade search MqlTradeRequest for position modification
request.action = TRADE_ACTION_SLTP;
request.symbol = symbol;
request.sl = StopLoss;
request.tp = Takeprofit;
string word = "";
StringConcatenate(word,
"<< ============ Modifyposition(): Modify position ",
symbol," ============ >>>");
Print(word);
//---- modify position and check the results of trade search
if(!OrderSend(request,result)|| result.deal==0)
{
Print("Modify error =", GetLastError();
return(false);
}
return(true);
}

But it doesn't work like this.

How to do?

Thank you :)

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций - Документация по MQL5
 
mario065: But it doesn't work like that. How do I do it? Thank you :)

Try it this way:

MqlTradeRequest request={0};
MqlTradeResult  result ={0};
 
Yedelkin:

Try it this way:

Yedelkin,

Thank you, it didn't work.

I checked if it counts correctly for the start of the function call.

Here's how I did it:

double Bid = NormalizeDouble(SymbolInfoDouble(Currency,SYMBOL_BID),_Digits);
double Ask = NormalizeDouble(SymbolInfoDouble(Currency,SYMBOL_ASK),_Digits);
double Open = NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN),_Digits);
double SL = NormalizeDouble(PositionGetDouble(POSITION_SL),_Digits);
if(Open > 0){
start_buy = Ask - Open; Print("start_buy=",start_buy);
start_sel = Open - Bid;Print("start_sel=",start_sel);
}

Surprise in the log:

MR 0 Core 1 10:21:49 2012.10.01 10:12:42 deal #2 sell 0.10 EURUSD at 1.28146 done (based on order #2)
GH 0 Core 1 10:21:49 2012.10.01 01 01:12:42 deal performed [#2 sell 0.10 EURUSD at 1.28146]
NI 0 Core 1 10:21:49 2012.10.01 01 01:12:42 order performed sell 0.10 at 1.28146 [#2 sell 0.10 EURUSD at 1.28146 (0.00000)
OF 0 Core 1 10:21:49 2012.10.01 01 01:12:43 start_buy=0.0001299999999999635
DR 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=5.000000000010552e-005
LE 0 Core 1 10:21:49 2012.10.01 01:12:43 start_buy=0.0001099999999998325
EN 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=7.00000000000145e-005

Of course I was wondering just sela, where did the numbers come from?

I think I wrote the function correctly as shown:

SL & TP Modification

Trade order for modification of StopLoss and/or TakeProfit levels. Requires 4 fields:

  • action
  • symbol
  • sl
  • tp
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства позиций
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства позиций
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства позиций - Документация по MQL5
 
mario065: Thank you, it did not work.

So what exactly "failed"?

mario065 : I checked if it counts correctly to start the function call, here's how I did it:

Insert the code correctly (Ctrl+Alt+M):

  double Bid  = NormalizeDouble(SymbolInfoDouble(Currency,SYMBOL_BID),_Digits);
  double Ask  = NormalizeDouble(SymbolInfoDouble(Currency,SYMBOL_ASK),_Digits);
  double Open = NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN),_Digits);
  double SL   = NormalizeDouble(PositionGetDouble(POSITION_SL),_Digits);
  if(Open > 0)
    {
     start_buy = Ask - Open;Print("start_buy=",start_buy);
     start_sel = Open - Bid;Print("start_sel=",start_sel);
    }

Here the normalisation has to be used in a different sequence.

1. as values of SymbolInfoDouble(Currency,SYMBOL_BID) type come from the server, they are already considered normalized. And there is no need to normalize them a second time. I.e. they can simply be written:

double Bid  = SymbolInfoDouble(Currency,SYMBOL_BID);

2. But after any arithmetic operation the normalization is gone, so if you need to get a normalized number, you should write it like this:

start_buy = NormalizeDouble(Ask - Open,_Digits);

I'm still thinking about the rest.

 
mario065: Surprise in the log:

DR 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=5.000000000010552e-005
EN 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=7.0000000145e-005

Of course, only interested in the sel - where did such numbers come from?

7.00000000000145e-005 is just one way of writing the value of a real number. I think it's called "scientific". For more details see."MQL5 Reference Guide / Language Basics / Data Types / Real Types (double, float)".
 
Yedelkin:
7.00000000000145e-005 is just one of the ways of writing the value of a real number. I think it's called "scientific". For more details see."MQL5 Reference Guide / Language Basics / Data Types / Real Types (double, float)".

Yedelkin,

Thank you for tackling the problem.

Here is the code. The functions for opening the position were written by Nikolay Kositsin.

Files:
MTB_E.mq5  9 kb
 
Please advise how and where to specify in the EA the MA belonging to the No.2 window.
For example, I added MA to MFI and I want to register this MA in my EA. I do not know where and how to do it.

Thank you for your reply)
 
mario065: Here is the code. Functions to open the position were written by Nikolay Kositsin. Nikolay Kositsin.

1. I would say this: use someone else's code with great care. Because someone else's code means someone else's mistakes too.

2. Here(https://www.mql5.com/ru/forum/6343/page64#comment_357008) I suggested that you try to correctly zero variables before using them. But your code hasn't implemented this suggestion yet. Moreover, your code contains constructs of the following type:

//+------------------------------------------------------------------+
//| Modify position.                                                 |
//+------------------------------------------------------------------+
bool ModifyPosition(const string symbol,double StopLoss,double Takeprofit)
  {
//---- обявяване на структурата и резултата на търговското искане
   MqlTradeRequest request;
   MqlTradeResult result;
//---- структурна инициализация на  търговското искане MqlTradeRequest за модифициране на  позиция
   request.action       = ...
   request.symbol       = ...
   request.sl           = ...
   request.tp           = ...
   ...
//---- модифицираме позицията и  проверяваме резултата от търговското искане
   if(!OrderSend(request,result) || result.deal==0)
     {
      ...
     }
   ZeroMemory(request);
   ZeroMemory(result);
   return(true);
  }

You see, in this construct the request and result variables are zeroed not before they are used but after they are used. Moreover, when these local variables are zeroed, the function stops operating, i.e. such zeroing itself is meaningless. In other words, such a construction is a good example of how MqlTradeRequest and MqlTradeResult variables should not be zeroed. So, if you are eager, please, try to clear the variables correctly. If something goes wrong, please, describe in details what is "not working".

3. The Standard Library has a trade class"MQL5 Reference / Standard Library / Trade Classes / CTrade". Try to figure out how to apply it in practice. At the initial stage of immersion into the language, this class may be quite sufficient. For example, this class has the following method:"MQL5 Reference / Standard Library / Trade Classes / 2CTrade/ PositionModify". It is implemented as follows:

//+------------------------------------------------------------------+
//| Modify specified opened position                                 |
//+------------------------------------------------------------------+
bool CTrade::PositionModify(const string symbol,const double sl,const double tp)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__)) return(false);
//--- clean
   ClearStructures();
//--- setting request
   m_request.action=TRADE_ACTION_SLTP;
   m_request.symbol=symbol;
   m_request.magic =m_magic;
   m_request.sl    =sl;
   m_request.tp    =tp;
//--- action and return the result
   return(OrderSend(m_request,m_result));
  }

The 'ClearStructures();' line in it clears the m_request variable before using it.