Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 836

 
Alexey Viktorov:

Is it all right that it says

nothing, the thread is for MT4, so you don't pay attention to it

OK, get busy, it's boring here

 

Greetings all. Good luck in life and profit in work.

I am asking for help (unexpectedly, huh? :) ).

In Mql I am a zerobom, 2 days "in the subject". If real EA forces me to use automatic trading, I'm trying to write (collect it in real time from different parts) owl for my flat EA and of course I'm getting tired of it :). I've been trying to work out another problem for about 10 hours and I still haven't got to it. If anyone's advice or an example will be extremely grateful (verbally and in writing, and most importantly in the shower).

In general... There's TC, successfully used by me for a long time. On trade conditions on the same instrument can multidirectional market orders (no pending). To the lowered position may be filled at a trading signal, provided that the position has fallen by at least X pips, sometimes happens and make an addition to the fill (under the same conditions (trading signal + drawdown size)). The (current) problem is in opening additional positions, namely... how to check and return the value of loss on a long position. Following the exampleof https://www.mql5.com/ru/forum/117061, I tweaked the code to assign each position its own Magik, but that's about it. How to select exactly a position that has sat and return its loss value.... :(.

"my" code for opening trades.

//-----------------

if (NumberOfPositions(Symbol(),OP_BUY, Magic)<1)

{

if (my entry conditions)

{

if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP = 0;

if (stoploss!=0) SL = NormalizeDouble(Bid - stoploss*Point,Digits); else SL = 0;

ticket=OrderSend(Symbol(),OP_BUY,LOT,NormalizeDouble(Ask,Digits),5,SL,TP, "BUY",Magic,0,Blue);

if(ticket < 0) { Print("Error while opening BUY order #", GetLastError());}

}}

if(NumberOfPositions(Symbol(),OP_SELL, Magic)<1)

{

if (my entry conditions)

{

if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP = 0;

if (stoploss!=0) SL = NormalizeDouble(Ask + stoploss*Point,Digits); else SL = 0;

ticket=OrderSend(Symbol(),OP_SELL,LOT,NormalizeDouble(Bid,Digits),5,SL,TP, "SELL",Magic,0,Red);

if(ticket < 0) { Print("Error opening SELL order #", GetLastError());}

}}

//---------------

Additional orders are planned to open using the following code

//---------------

if (NumberOfPositions(Symbol(),OP_BUY, Magic)==1 && NumberOfPositions(Symbol(),OP_BUY, Magic_2)<1)

{

if (my entry conditions && GetProfitOpenPosInPoint(Symbol(),OP_BUY,Magic)>= LEVEL_1)

{

ticket=OrderSend(Symbol(),OP_BUY,LOT,NormalizeDouble(Ask,Digits),5,SL,TP, "Extra Buy",Magic_2,0,Blue);

if(ticket < 0) { Print("Error opening BUY order #", GetLastError()); }

} }

//---------------

And that's where I got stuck :). What to use instead of GetProfitOpenPosInPoint(Symbol(),OP_BUY,Magic). I think I need to use Drawdown_level(Symbol(),OP_BUY,Magic) but how to get it...

Help PLEASE, be friends.
Z.U. If you advise, please keep in mind that I'm still nubyara that not too lazy to send me a little more detail, you know, like if: FOREST THERE, do not forget to point out the direction <------ || ------>.

Thank you for your attention :).

код----доливаем по тренду
код----доливаем по тренду
  • 2009.05.07
  • www.mql5.com
Я пытался написать советник с открытием дополнительных лотов по тренду. Суть заключается вот в чем...
 
Igor Makanu:

Nothing, the thread is for MT4, so you don't pay attention to it.

Ok, get busy, it's boring here

Tell me where a similar branch for MT5 is, I'll ask there...

 
Alexander Layzerevich:

Tell me where a similar thread for MT5 is, I'll ask there...

Ask here. Here for both languages.
 
Alexey Viktorov:

Is it OK to specify

The highlighted function is no different from the function declaration. It turns out that the function is declared in the input parameters of the function.

In MT4 the function call from Indicator goes without errors and works as needed(int handle=iEnvelopes(Symbol(), tf, period, method, shift, price, Deviation(kanal), buff);) I thought it may be the same in MT5.

Please advise how to do it correctly ?

 
Alexander Layzerevich:

In MT4 the function call from Indicator goes without errors and works as needed(int handle=iEnvelopes(Symbol(), tf, period, method, shift, price, Deviation(kanal), buff);) I thought it may be the same in MT5.

Can you tell me how to do it correctly ?

It's impossible to get Envelopes data in mql4
 
Artyom Trishkin:
So it is impossible to get Envelopes data in mql4

Here's the code from MT4

//-------------------------------------------------------------------
extern string Parametrs_Indicator       = "Настройки Индикатора";// Настройки Индикатора

extern ENUM_TIME_FRAMES   TimeFrames     = 5;                     // Временной период
//-------------------------------------------------------------------
       int                Ma_Period     = 120;                   // Период
       ENUM_MA_METHOD     Ma_Method     = 2;                     // Mетод усреднения
       int                Ma_Shift      = 0;                     // Cдвиг средней
       ENUM_APPLIED_PRICE Applied_Price = 0;                     // Tип цены
//************************************************************************************************/

int OnInit()
{
double Signal_Buy = iEnvelopes(Symbol(), TimeFrames, Ma_Period, Ma_Method, Ma_Shift, Applied_Price, Deviation(TimeFrames, Kanal), 2, 0); // Сигнал на Покупку
}
//+------------------------------------------------------------------+
double Deviation(int Time_Frames, int _Kanal)
{

int Simbol = SymbolMagic();
//-------------------------
if (Time_Frames == 0) Time_Frames = Period();

if (Time_Frames == 1)
   {
   if (_Kanal == 1)
      {
      switch (Simbol)
         {
         ...
         }
      }
   }
}
//+------------------------------------------------------------------+

Everything works perfectly. I would like the same in MT5

 
Alexander Layzerevich:

Here's the code from MT4

Everything works perfectly. I would like the same in MT5

Well, that's because it's a different code and it will work.
 
Artyom Trishkin:
Well that's because it's a different code and it will work.

Fixed the MT5 code to send data to the Indicator:

//-------------------------------------------------------------------
extern string Parametrs_Indicator       = "Настройки Индикатора";// Настройки Индикатора

extern ENUM_TIMEFRAMES    TimeFrames    = PERIOD_M5;             // Временной период
//-------------------------------------------------------------------
       int                Ma_Period     = 120;                   // Период
       ENUM_MA_METHOD     Ma_Method     = MODE_SMMA;             // Mетод усреднения
       int                Ma_Shift      = 0;                     // Cдвиг средней
       ENUM_APPLIED_PRICE Applied_Price = PRICE_CLOSE;           // Tип цены
//************************************************************************************************/
void OnTick()
{
double Signal_Buy = (int)Envelopes(Symbol(), TimeFrames, Ma_Period, Ma_Shift, Ma_Method, Applied_Price, 2,  Deviation(1)); // Сигнал на Покупку
}
//************************************************************************************************/
double Envelopes(string symb, ENUM_TIMEFRAMES tf, int period, int shift, int method, int price, int buff, double Deviation(int kanal))
{
  double buf[1];
  int handle=iEnvelopes(Symbol(), tf, period, shift, method, price, Deviation(kanal));
   if(handle<0)
   {
    Print("Failed to create handle ATR, Error: ",GetLastError());
    return(WRONG_VALUE);
   } else
   {
    if(CopyBuffer(handle,buff,0,1,buf)<0)
    {
     Print("Failed to copy data from the indicator ATR, Error: ",GetLastError());
     return(WRONG_VALUE);
    }
   }
   return(buf[0]);
}
//************************************************************************************************/

But the error is the same.

 
Alexander Layzerevich:

Here's the code from MT4

//-------------------------------------------------------------------
extern string Parametrs_Indicator       = "Настройки Индикатора";// Настройки Индикатора

extern ENUM_TIME_FRAMES   TimeFrames     = 5;                     // Временной период
//-------------------------------------------------------------------
       int                Ma_Period     = 120;                   // Период
       ENUM_MA_METHOD     Ma_Method     = 2;                     // Mетод усреднения
       int                Ma_Shift      = 0;                     // Cдвиг средней
       ENUM_APPLIED_PRICE Applied_Price = 0;                     // Tип цены
//************************************************************************************************/

int OnInit()
{
double Signal_Buy = iEnvelopes(Symbol(), TimeFrames, Ma_Period, Ma_Method, Ma_Shift, Applied_Price, Deviation(TimeFrames, Kanal), 2, 0); // Сигнал на Покупку
}
//+------------------------------------------------------------------+
double Deviation(int Time_Frames, int _Kanal)
{

int Simbol = SymbolMagic();
//-------------------------
if (Time_Frames == 0) Time_Frames = Period();

if (Time_Frames == 1)
   {
   if (_Kanal == 1)
      {
      switch (Simbol)
         {
         ...
         }
      }
   }
}
//+------------------------------------------------------------------+

Everything works perfectly. I would like the same in MT5

Watch your hands:

In my previous post this is highlighted in your code

double Deviation(int Time_Frames, int _Kanal)

and in the code of this, the quoted message is a function declaration. Also highlighted.

And this

Deviation(TimeFrames, Kanal)

Calling a user function that exists. Although this programming method is unacceptable to me, it is still understandable. But how to describe the error in that code, I'm at a loss.

Reason: