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

 
artem artem #:

SanAlex, yes, looked at the tester for this year's current one, all ok) The results are good, in the near future I will try to run it on a real account

What is the name of the Expert Advisor? Did you download it from kodobase? I need to see how the author has implemented it in the function

//+------------------------------------------------------------------+
// Permission to trade in this day                                   |
//+------------------------------------------------------------------+
bool TradingDay(int hmin, int hmax) // Определение времени и дня разрешения торговли
  {
   bool dtrade = false;
   switch(DayOfWeek())
     {
      case 1: // Monday
         if(Monday == 1)
            dtrade = true;
         break;
      case 2: // Tuesday
         if(Tuesday == 1)
            dtrade = true;
         break;
      case 3: // Wednesday
         if(Wednesday == 1)
            dtrade = true;
         break;
      case 4: // Thursday
         if(Thursday == 1)
            dtrade = true;
         break;
      case 5: // Friday
         if(Friday == 1)
            dtrade = true;
         break;
      default: //
         dtrade = false;
         break;
     }
   if(dtrade && !(Hour() >= hmin && Hour() <= hmax))
      dtrade = true;
   return dtrade;
  }
//+------------------------------------------------------------------+

We are missing something - to add the condition to the ontik

 
SanAlex #:

What is the name of the Expert? Did you download it from kodobase? I need to see how the author has implemented it in the function

There is something missing - to add a condition to the ontik

Sasha, the timing work has not been included. Just added some features to plug in during development)
 
MakarFX #:
Sasha, the timing work has not been included. Just added some features to plug in during development)

I'm going to redo it in my own way.

 
artem artem #:

SanAlex, yes, looked at the tester for this year's current one, all ok) The results are good, in the near future I will try to run it on a real account

This one and time will work - I changed the function

//---
input string   s0 = "Баланс";                  // 1
input string   Template       = "ADX";         // Имя шаблона(without '.tpl')
input double   TargetProfit   = 1000000;       // Баланс + Прибыль(прибавить к балансу)
input double   TargetLoss     = 0;             // Баланс - Убыток(отнять от баланса)
input string   s2 = "Trading options";         // 2
input double   Lots           = 0.1;           // Lots
input double   MaximumRisk    = 0.02;          // MaximumRisk
input double   DecreaseFactor = 3;             // DecreaseFactor
input double   InpSLoss       = 4000;          // стоплосс
input double   InpTProfit     = 2000;          // тейкпрофит
input string   s3 = "TP SL";                   // 3
input double   InpTakeProfit  = 2000;          // Exchange TP
input double   InpStopLoss    = 4000;          // Exchange SL
input string   s4 = "Индикатор MA";            // 4
input int      MovingPeriodLw = 13;            // MovingPeriodLw
input int      MovingPeriodS1 = 55;            // MovingPeriodS1
input int      MovingPeriodS2 = 89;            // MovingPeriodS2
input string   s5 = "Индикатор MACD";          // 5
input int      InpFastEMA     = 12;            // Fast EMA Period
input int      InpSlowEMA     = 26;            // Slow EMA Period
input int      InpSignalSMA   = 9;             // Signal SMA Period
input string   s6 = "Start Stop";              // 6
input datetime HoursFrom      = D'1970.01.02'; // 1 Время: старт
input datetime HoursTo        = D'1970.01.01'; // Время: стоп
input datetime HoursFrom2     = D'1970.01.01'; // 2 Время: старт
input string   s7 = "Time:Start Stop";         // 7
input int      HoursFrom1     = 0;             // Время: старт
input int      HoursTo1       = 24;            // Время: стоп
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- Закрыть Общий профит или профит на паре
   if(ProfitTarget())
     {
      return;
     }
//--- Закрыть профит BUY или SELL на паре
   ProfitOnTick();
//---
   if((HoursFrom<HoursTo && TimeLocal()>=HoursFrom && TimeLocal()<HoursTo) ||
      (HoursFrom>HoursTo && (TimeLocal()<HoursTo || TimeLocal()>=HoursFrom)) ||
      (HoursFrom2<HoursTo2 && TimeLocal()>=HoursFrom2 && TimeLocal()<HoursTo2) ||
      (HoursFrom2>HoursTo2 && (TimeLocal()<HoursTo2 || TimeLocal()>=HoursFrom2)))
     {
      MqlDateTime currTime;
      TimeLocal(currTime);
      int hour0 = currTime.hour;
      if((HoursFrom1 < HoursTo1 && hour0 >= HoursFrom1 && hour0 < HoursTo1) ||
         (HoursFrom1 > HoursTo1 && (hour0 < HoursTo1 || hour0 >= HoursFrom1)))
        {
         // Определение направления пересечения мувингов
         if(Init)
            InitMetod();
         // Ожидание нового бара на графике
         if(timeprev == Time[0])
            return;
         timeprev = Time[0];
         // Открытие ордера по методу Пуриа
         CheckForOpen();
        }
     }
  }
//+------------------------------------------------------------------+

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

The Time function in mt4 and in mt5 works

Files:
 
MakarFX #:
Don't you want to get rid of classes?

I just recently found out about them. I don't know, it's a mega handy thing. What do you suggest? Putting everything into functions? If that would solve the problem.

I have two global objects (bar, db_last) of one class Bar, first is initialized with parameters of each new bar (usual bar on chart), and second saves a bar corresponding to all conditions. As a matter of fact, in another local object of class Order all calculations are made from the parameters db_last to open an order. Parameters db_last and bar are used in many places, but only for reading, initialization and assignment occur in one place, in OnTick(), so unexpected changes in objects should not be.

void OnTick()
{
  last_time = iTime(NULL, 0, 0);
  BreakevenActivate();

  if(last_time > bar.time_open){
    bar.Initialize();
    TrawlOnFractals();

    if(BarRelativeMA() == "bear"){
      n_arrow_down++;
      db_last = bar;
      if(db_last.IsBearishDB() == true) OpenOrder("bear");
      ArrowCreate(OBJ_ARROW_DOWN,0,"ArrowDown"+IntegerToString(n_arrow_down,4,'0'),
                  0, iTime(NULL,0,1),AnchorPrise("bear"),ANCHOR_BOTTOM);
    }

    if(BarRelativeMA() == "bull"){
      n_arrow_up++;
      db_last = bar;
      if(db_last.IsBullishDB() == true) OpenOrder("bull");
      ArrowCreate(OBJ_ARROW_UP,0,"ArrowUp"+IntegerToString(n_arrow_down++,4,'0'),
                  0, iTime(NULL,0,1),AnchorPrise("bull"),ANCHOR_TOP);
    }

    bar.time_open = last_time;
  }
   
}
 
Nerd Trader #:

I just recently found out about them. I don't know, it's a mega handy thing. What do you suggest? Putting everything into functions? If that would solve the problem.

I have two global objects (bar, db_last) of one class Bar, first is initialized with parameters of each new bar (usual bar on chart), and second saves a bar corresponding to all conditions. As a matter of fact, in another local object of class Order all calculations are made from the parameters db_last to open an order. Parameters db_last and bar are used in many places, but only for reading, initialization and assignment happen in one place, in OnTick (), so unexpected changes in objects should not occur.

I would try it - it does not cost money).

But there are errors, moreover, errors with simple normalization

Can you send me the file in a private message? I'll have a look at it.
 
SanAlex #:

What is the name of the Expert? Did you download it from kodobase? I need to see how the author has implemented it in the function

I missed something - to add the condition to the ontik

SanAlex, I attached the downloaded version in this message - it has Puria + trailing stop + Breakeven level + watchdog trading. I would test trading by the clock, I just haven't got around to it yet)

 
MakarFX #:

The lack of history affects the indicator reading at the beginning of the test

MakarFX, I also thought of that, so it should work as it should

 
artem artem #:

SanAlex, attached the version I downloaded in this post - it's Puria + trailing stop + breakeven level + clock trading. I would test trading by the clock, I just haven't got around to it yet).

Found this in kodobase https://www.mql5.com/ru/code/12654

- I missed your target, what did you want to change in it?

Советник по методу Пуриа
Советник по методу Пуриа
  • www.mql5.com
Советник открывает позиции по алгоритму метода Пуриа.
 
SanAlex #:

Found this in kodobase https://www.mql5.com/ru/code/12654

- I missed your target, what did you want to change in it?

What additions I wanted to make:

1. To make so, that the opening of a deal and check for all indicator conditions(crossing a fast (5) two slow (75) (85) and the MACD bar opening in the same direction with a fast (5) ) was performed only at opening price of a new candle (the very first tick of each 30 minute candle);
  1. Create conditions for "zeroing" of indicators. For example, for a fast moving (5) If it is higher than slow - then it is a signal to buy. If it then goes downwards and either touches one of them, or is between the slow moving (75) and (85)- then the signal from the fast moving indicator" zeros out" as it were, and will remain in this" zero" position as long as it touches or remains between the slow ones. If after that the fast one crosses both slow ones to one side(including if it goes back to the side it came from before touching the slow ones)- then it will be a signal of this indicator. With MACD the situation is similar- Only MACD=0 will be considered as "zeroing"(if on the first candle the MACD, for example, opened with 0.0043, and on the second candle with -0.0010, it means that the MACD on the second candle has" zeroed" and has given a new signal). However, there is a time when the fast (5) and the MACD should be kind of "on equal footing" - if (5) doesn't change its position relative to the slow, and the MACD has opened on the previous candle in the wrong zone (no entry), and on the next one - in the same zone as the fast, then all conditions have converged and an entry to the order should be made. Note that all this should be only on the opening prices of the candles - only on this one tick;
  1. And the last, to make the Expert Advisor wait for 4 consecutive candle openings:

    1. 1st open price - (5) above (75) and (85) + MACD bar opened above 0- 1 out of 4 confirmations;
    2.The opening price of the 2nd candle - (5) over (75) and (85) + MACD bar opened above 0- 2 out of 4 confirmations is;
    3. The opening price of the 3rd candle - (5) over (75) and (85) + MACD bar opened above 0- 3 out of 4 confirmations is;
    4.Opening price of the 4th candle - (5) over (75) and (85) + MACD bar opened above 0- 4 out of 4 confirmations yes- Open buy trade on the same candle (4th).
The same situation with orders to sell, only in the other direction indicators should open. And there is an important point- if at, say, any stage of the 1 st candle to the 4th, the indicators change their position(for example, on the 3rd opening candle, the MACD bar opens either below 0, or = 0)- then everything resets, because the signals were not checked on the opening of 4-th candle in a row.