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

 

Quote from the handbook:

//+------------------------------------------------------------------+

//| Expert initializationfunction|
//+------------------------------------------------------------------+
intOnInit()
{
//--- get the value of the custom indicator
doublevalue=iCustom(_Symbol,_Period,"::Indicators\\\SampleIndicator.ex4",0,0);

Reference to indicator variables in the initialisationfunction , not in the start function?Reference to indicator variables in the initialisationfunction only opens one position.

 
It's getting late. Artem, will you be able to reply tomorrow? Thank you in advance.
 
Oleg Kolesov:

Quote from handbook:

//+------------------------------------------------------------------+

//| Expert initializationfunction|
//+------------------------------------------------------------------+
intOnInit()
{
//--- get the value of the custom indicator
doublevalue=iCustom(_Symbol,_Period,"::Indicators\\\SampleIndicator.ex4",0,0);

Reference to indicator variables in the initialisationfunction , not in the start function?Reference to indicator variables in the initialisationfunction only opens one position.

Instead of start it is high time to use OnTick() and other event handlers. Forget about the functions of the old MetaTrader 4. The new MQL4 is now very close to MQL5 - the only differences are in a different organization of trading functions and indicators - they are now created in the OnInit() handler - an indicator handle is created and the data access to this handle is performed. In MQL4 it is different. But resources are located in the same way, if my memory doesn't change.

And the access to the calculated data is not much different from the access through iCustom() in a usual way - its name is only slightly different.
Документация по MQL5: Обработка событий / OnTick
Документация по MQL5: Обработка событий / OnTick
  • www.mql5.com
//|                                                   TradeByATR.mq5 | //|                        Copyright 2018, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | //| Expert initialization function                                   |...
 
Oleg Kolesov:
It's getting late. Artem, will you be able to reply tomorrow? Thank you in advance.

No promises - busy.

Late ... it's 04:51 ... that's "late".

 
Artyom Trishkin:
  1. The order setting price is not normalised.
  2. All prices should be checked for StopLevel - if the order distance in points from the price is less than the StopLevel value, there will be an error 130 - invalid stops

I think the problem is not with StopLevel since it still opens one order. But on next ticks it generates error

#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#include  <Init_Deinit.mqh> 

// Переменные
extern double lots    = 0.01;
extern int    Level   = 300;
extern double StopL   = 300;
extern double TakeP   = 1000;


// Start Programm
void OnTick() 
  { 
  //--- вычисленные значений для BuyStop
   
   double price_buystop=NormalizeDouble (Ask+Level*Point, Digits);
   StopL =NormalizeDouble(price_buystop-StopL*Point,Digits); 
   TakeP =NormalizeDouble(price_buystop+TakeP*Point,Digits); 
   
//--- Размещаем отложный ордер BuyStop
   int ticket=OrderSend(Symbol(),OP_BUYSTOP,lots,price_buystop,3,StopL,TakeP,"Rupture",1111,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("BuyStop завершилась с ошибкой #",GetLastError()); 
          } 
   else 
      Print("Функция BuyStop успешно выполнена"); 
      }
 
Doszhan:

I think the problem is not with StopLevel since it still opens one order. But on next ticks it generates error

You need to check if the price is less than the stop loss or spread, then of course there will be an error. This is the first one.

Judging by the text you do not have a check whether the order has already been opened or not.

This way it will open till infinity on every tick.

 
Oleg Kolesov:

H=iCustom(NULL,TF,"::Indicators\\\KChange.ex4",History,Period_1,Period_2,MA_method,0,1);

The compiler didn't find any errors, but the tester works much slower? Is it normal?

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

The MQL4 manual says: reference to variables in the initialization function ?

Reference to indicator variables in theinitialization function , not in the start function? Experienced people tell me please!

if slow, you need to optimize-accelerate the indicator

you need to call where you want to check the indicator values, inthe initialization only one value will be received

 
nalyk:

You are looking for a fractal on the third bar, it may not be there. Look for the first fractal in the cycle.


This does not work either. The order is placed based on the high-low of 2 candles.
 
Valerius:

You need to check if the price is less than the stop loss or spread, then of course there will be an error. This is the first one.

Judging by the text you do not have a check whether the order has already been opened or not.

Otherwise it will open indefinitely on every tick.

Exactly, it doesn't open on every tick, it only opens once.
 
Doszhan:
Exactly, it doesn't open on every tick, it only opens once.

Is there an error 130 in the logbook ?

Above explanation of where it comes from and how to do the right thing to avoid it.

You didn't.

Reason: