Questions from Beginners MQL4 MT4 MetaTrader 4 - page 90

 
toni_starkthe Expert Advisor worked 1.5 years ago, now it's not on the chart.

the thesis: movement=life, rest=death. What does it say in the log? it's at the bottom right two tabs

if i had one - i would check and fix it ...

 

Forum on Trading, Automated Trading Systems and Strategy Tests

Questions from Beginners MQL4 MT4 MetaTrader 4

Ilya Prozumentov, 2017.06.11 13:53

There is a class template for working with an array.
#property strict
#include <ObjectVariables.mqh>
#include <Arrays\varQSort.mqh>
#include <Arrays\objQSort.mqh>

template<typename T1>
class ArrayList
{
   private:
      T1 array[];
      QuickSorts<T1> *qs;
      int size;
      int index;

   public:
      //прочие функции
      void QuickSort();//отсортировать массив
      //прочие функции
};
//+------------------------------------------------------------------+
//| Сортировка массива
template<typename T1>
void ArrayList::QuickSort()
{
   int idx = index;//сохранение положения индекса
   if(IsPointer(array[0])) // true - массив содержит указатели класса
      qs /*ошибка 2*/ = new ObjQSort<T1>();
   else
      qs /*ошибка 2*/ = new VarQSort<T1>();
   qs.Sort(array, 0, index);
   index = idx;
}

For this template class, we need to implement sorting, given that the array can store complex data types. For example:
ArrayList<PP*> *dde; // PP - класс

I can write different functions for simple and complex types, but compiler doesn't understand that functions are rigidly delimited by data type and keeps swearing:
'<' - illegal operation use ArrayList.mqh

So I decided to embed the interface:

#property strict
template <typename T1>
interface QuickSorts
{
   void Sort(T1 &array[], int beg, int end);
};
#property strict
#include <Arrays\QuickSorts.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
template <typename T1>
class VarQSort : public /*ошибка 1*/ QuickSorts
{
private:

public:
   void Sort(T1 &array[], int beg, int end);
   VarQSort(){}
   ~VarQSort(){}
};
template <typename T1>
void VarQSort::Sort(T1 &array[], int beg,int end)
{
   //алгоритм функции
}
#property strict
#include <Arrays\QuickSorts.mqh>
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
template <typename T1>
class ObjQSort : public /*ошибка 1*/ QuickSorts
{
private:

public:
   void Sort(T1 &array[], int beg, int end){}
   ObjQSort(){}
   ~ObjQSort(){}
};

All parts of the construct compile. But if you try to declare it:
ArrayList<PP*> *dde; // PP - класс
then, when compiling the file, these are the errors:

'QuickSorts' - template mismatch varQSort.mqh /*error 1*/
'=' - type mismatch ArrayList.mqh /*error 2*/


What should I fix in the code to eliminate this type mismatch? I don't understand why it occurred in the first place.

P.S.
'<' - illegal operation use varQSort.mqh
haunts me in this construct as well. It is this very error I wanted to get rid of. But I understand this error, and I don't understand those two.
template <typename T1>
class VarQSort : public QuickSorts<T1>
//....

template <typename T1>
class ObjQSort : public QuickSorts<T1>
//....
 
fxsaber:
Indeed) The discrepancy error has disappeared and the other one with it. Thank you.
 
Greetings fellow forum members, I need help with adding some changes to the function.
enum _EventYesNo{
      YES            = 1,           //ДА
      NO             = 2            //НЕТ
      };
enum howmuch {one = 1,              //Одна
              two = 2,              //Две
              three = 3             //Три
              };

input    _EventYesNo    monday                     = 2;                 //торгуем в ПОНЕДЕЛЬНИК?
input    howmuch        mondayHM                   = 1;                 //Сколько сделок?
input    string         monday_open1               = "00:00";           //
input    string         monday_open2               = "00:00";           //
input    string         monday_open3               = "00:00";           //

input    _EventYesNo    tuesday                    = 2;                 //торгуем во ВТОРНИК?
input    howmuch        tuesdayHM                  = 1;                 //Сколько сделок?
input    string         tuesday_open1              = "00:00";           //
input    string         tuesday_open2              = "00:00";           //
input    string         tuesday_open3              = "00:00";           //

input    _EventYesNo    wednesday                  = 2;                 //торгуем в СРЕДУ?
input    howmuch        wednesdayHM                = 1;                 //Сколько сделок?
input    string         wednesday_open1            = "00:00";           //
input    string         wednesday_open2            = "00:00";           //
input    string         wednesday_open3            = "00:00";           //

input    _EventYesNo    thursday                   = 2;                 //торгуем в ЧЕТВЕРГ?
input    howmuch        thursdayHM                 = 1;                 //Сколько сделок?
input    string         thursday_open1             = "00:00";           //
input    string         thursday_open2             = "00:00";           //
input    string         thursday_open3             = "00:00";           //

input    _EventYesNo    friday                     = 2;                 //торгуем в ПЯТНИЦУ?
input    howmuch        fridayHM                   = 1;                 //Сколько сделок?
input    string         friday_open1               = "00:00";           //
input    string         friday_open2               = "00:00";           //
input    string         friday_open3               = "00:00";           //

extern int         minutes = 5;          // Время торговли(минут) bool    HOUR = true;                     // Часы Вкл (true) / Выкл (folse) //Отправляет true если по времени разрешено торговать bool isTradeTimeString() { datetime servertime = TimeCurrent(); datetime localtime = TimeLocal(); datetime time = 0; datetime hbegin = 0; datetime hend = 0; string TimeBegin = "00:00"; if(DayOfWeek() == 1){if(monday == 1){TimeBegin = monday_open1;}else{return(false);}} if(DayOfWeek() == 2){if(tuesday == 1){TimeBegin = tuesday_open1;}else{return(false);}} if(DayOfWeek() == 3){if(wednesday == 1){TimeBegin = wednesday_open1;}else{return(false);}} if(DayOfWeek() == 4){if(thursday == 1){TimeBegin = thursday_open1;}else{return(false);}} if(DayOfWeek() == 5){if(friday == 1){TimeBegin = friday_open1;}else{return(false);}} string TimeEnd = TimeToString(StrToTime(TimeBegin)+(60*minutes),TIME_MINUTES); if(servertime > localtime) {   time = servertime - localtime;   hbegin = StrToTime(TimeBegin) + time;   hend = StrToTime(TimeEnd) + time; } if(servertime < localtime) {   time = localtime - servertime;   hbegin = StrToTime(TimeBegin) - time;   hend = StrToTime(TimeEnd) - time; } if(localtime == servertime) {   hbegin = StrToTime(TimeBegin);   hend = StrToTime(TimeEnd); } datetime dtBegin, dtEnd;        // Время начала и окончания работы int      hc, he;                // Часы текущего времени и окончания работы dtBegin=StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)+" "+TimeToStr(hbegin,TIME_MINUTES)); dtEnd=StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)+" "+TimeToStr(hend,TIME_MINUTES)); hc = TimeHour(TimeCurrent()); he = TimeHour(dtEnd); if(dtBegin>=dtEnd) {   if(hc>=he)    dtEnd+=24*60*60;   else    dtBegin-=24*60*60; } if(HOUR==true) {   if(TimeCurrent()>=dtBegin && TimeCurrent()<=dtEnd)    return(true);   else   {    if(CountTrades()==0)     return(false);   } } return(true); }

I need, for example on Monday, if I need to open 2 or 3 trades, the function compares the time and sends the pipe, but I have one time compared so far.


	          
 
The export of quotes will allow you to choose from which date to which you want to download them.

Because when you press the "download" button, 6 000 000 quotes will be downloaded. Not everyone wants to fill up the hard disk with quotes data, wait for a long time until they are downloaded, and then remove unnecessary data from the table of quotes.

 

Hello Dear ... Can you tell me why the specified trailing stop code for BUY orders works correctly ...

       if (OrderType()==OP_BUY && (Bid-8*D*Point)>OrderStopLoss()&&(Bid-8*D*Point)>OrderOpenPrice()) 
{chk=OrderModify(OrderTicket(),0,NormalizeDouble(Bid-7*Point,Digits),NormalizeDouble(OrderOpenPrice()+25*D*Point,Digits),0,0);}

... ... but the same one for SELL orders doesn't set SL...

       if (OrderType()==OP_SELL &&(Ask+8*D*Point)<OrderStopLoss()&&(Ask+8*D*Point)<OrderOpenPrice()) 
{chk=OrderModify(OrderTicket(),0,NormalizeDouble(Ask+7*Point,Digits),NormalizeDouble(OrderOpenPrice()-25*D*Point,Digits),0,0);}

... The reason is most likely in the condition(Ask+8*D*Point)<OrderStopLoss(), if we remove it, SL will be set, but Trailing Stop works incorrectly without the specified condition ...

ForBUY orders,the condition(Bid-8*D*Point)>OrderStopLoss(), ifOrderStopLoss()==0, is acceptedcorrectly (i.e. some value > 0) ...

... Butthe condition(Ask+8*D*Point)<OrderStopLoss(),OrderStopLoss()==0 is notcorrect ( i.e. somevalue is< 0

) ...

Please advise how to correctly formulate in the code the required condition(Ask+8*D*Point)<OrderStopLoss()for correct work ofTrailing Stop withSELL orders.

I thank all of you who replied in advance

.
 

Good afternoon: There is a function where the indicator reads thetick history file . But it is read only once, when the indicator is loaded or updated. How can I make it read every time when the first tick of the zero bar appears?

void ProcessOldCandles(int limit, TickStruct &lastTick)

{

      int hTicksFile = FileOpen(Symbol() + ".tks", FILE_BIN | FILE_READ | FILE_SHARE_READ | FILE_SHARE_WRITE);

   if (hTicksFile < 1)

      return;

      TickStruct tick;

   while (!IsStopped())

   {

      if (!IsReadTimeAndBidAskOfTick(hTicksFile, tick))

         return;

      if (tick.time >= Time[limit])

         break;

   }

   lastTick = tick;

   int barIndex = iBarShift(NULL, 0, tick.time);

      while (barIndex >= 0)

   {

      if (!IsReadTimeAndBidAskOfTick(hTicksFile, tick))

         return;

         if (!IsTickBelongToBar(tick, barIndex))

         barIndex = iBarShift(NULL, 0, tick.time);

         ProcessOneTick(barIndex, tick, lastTick);

   }

      FileClose(hTicksFile);

 
Yaroslav Nykula:

Hello Dear ... Can you tell me why the specified trailing stop code for BUY orders works correctly ...

... ... but the same one for SELL orders doesn't set SL...

... The reason is most likely in the condition(Ask+8*D*Point)<OrderStopLoss(), if we remove it, SL will be set, but Trailing Stop works incorrectly without the specified condition ...

ForBUY orders,the condition(Bid-8*D*Point)>OrderStopLoss(), whenOrderStopLoss()==0 is takencorrectly (i.e. some value > 0) ...

... Butthe condition(Ask+8*D*Point)<OrderStopLoss(), whenOrderStopLoss()==0 is not consideredcorrect (i.e. some value is< 0

) ...

Please advise how to correctly formulate in the code the required condition(Ask+8*D*Point)<OrderStopLoss()for correct work ofTrailing Stop withSELL orders.

I thank all of you who replied in advance

.

Hi all ... something very low activity in this forum branch ... the problem is solved this way ...

 if (OrderSymbol()==Symbol()&&OrderType()==OP_SELL&&OrderLots()<=Lot*3&&(Ask+(Tral+TP)*D*Point)<OrderOpenPrice()&&((OrderStopLoss()!=0&&(Ask+Tral*D*Point)<OrderStopLoss())||OrderStopLoss()==0))
{chk=OrderModify(OrderTicket(),0,NormalizeDouble(Ask+Tral*D*Point,Digits),NormalizeDouble(OrderOpenPrice()-Stepp*D*Point,Digits),0,0);}} 

... It's a little long, but it works... Who knows how to make it shorter, can you shorten it, I'd appreciate it... the rest of us can use it as it is.

 

enter the function

OrderCloseByTicket (542534564)

Close order by ticket with full lot.

so that you don't have to specify lots, price, slippage.

similar to clicking a cross on the order in the terminal.


enter the function

OrderCloseByPos (0)

close the order by position.


and then there will be no need to prescribe these cumbersome constructions.

  for (int i=1; i<=OrdersTotal(); i++)       //Цикл по всем ордерам,..
     {                                        //отражённым в терминале
      if(OrderSelect(i-1,SELECT_BY_POS)==true)//Если есть следующий
        {                                     
         // Здесь должен выполняться ..
         // ..анализ характеристик ордеров 
        }
     }                                        //Конец тела цикла
 

Hello! The two minus numbers q and w are compared incorrectly, when they are equal, the if operator thinks one is greater than the other.What is the error? When q = -0.0002 and w is also -0.0002, res12=false, why?

double SPREAD=MarketInfo(Symb,MODE_SPREAD);// Спред
static bool res12=true;

start()
{   


   double q=High[0]-3.0*Point-High[1];
   double w=-SPREAD*Point;
      
   if (New_Bar==true&&ticket1<=0)
     {
      if(q>w)
       {
        res12=false; 
        Alert("res12=false");
        Alert (q);
        Alert (w);
       }
     }
      if (New_Bar==true&&ticket1<=0)
     {
        if(q<=w)
        {
         res12=true;
         Alert("res12=true");
         Alert (q);
         Alert (w);
        }
      }





}
Reason: