Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1238

 
Alexey Viktorov:

And the first part of the line and the question as a whole?

Well, we're programmers. Full and empty glasses on the bedside table and all that...

However, I wrote three possible scenarios and what happens during them in the main indicator calculation cycle:

Forum on trading, automated trading systems and strategy testing

FAQ from Beginners MQL5 MT5 MetaTrader 5

Artyom Trishkin, 2020.08.06 15:17

rates_total - prev_calculates is a very efficient algorithm.

  • If it is equal to zero, it means calculation on the current bar by the tick.
  • If it is equal to 1, it means that there is a new bar and two bars will be calculated - the previous and the current one
  • If it is greater than 1, it means either the first run or change in the history data
We calculate the limit. And in the loop from limit to greater than or equal to zero, we calculate the indicator data. And calculate what the limit is when calculating the limit = rates_total - prev_calculates.

The fourth situation - below zero - is quite possible. But it simply won't be processed in the loop calculated for(int i=limit; i>=0; i--) ...

Few people just want to think about it and usually just copy and paste. Correspondingly, the first launch and history change are when limit>1, so we should write about the first launch in such a situation and not check prev_calculated for zero.

 
Сергей Таболин:

Alexei, I'm interested )))) But I don't see the error! And there's no shame in learning. And if someone is smarter or more experienced, I don't see anything wrong with that either.

I have just run the indicator with a large input parameter for the size of a candle. I want to have smaller candlesticks.

All prices for the candlesticks are calculated and initialed from indicator buffers. All is correct. But there was no rendering. I don't understand why.

I suggested you

Alexey Viktorov:

......... to start by selecting bars after an N number, or at least one last closed bar. Have you tried it? Does it render?

And once again I suggest you start by selecting at least one last closed bar. When you get a positive result, only then proceed to the calculations and conditions.

 
Alexey Viktorov:

I have suggested to you

and I suggest you start by singling out at least one last closed bar. When you get a positive result, only then move on to the calculations and conditions.

I'm afraid I don't understand you... Which bar do you propose to allocate? The one I formed? Or on the chart?

If it is on the chart, I don't need them a priori. The indicator is considered the same on any timeframe.

The previous calculation was performed on H1, and now it is on H4. The result is the same.

2020.08.08 11:06:14.580 newCandles (USDJPY,H4)  ~~~~ Предварительный расчёт индикатора.
2020.08.08 11:06:14.789 newCandles (USDJPY,H4)  2019.01.02 06:00:00 >>> Свеча 00000 >> open = 109.419 hihg = 109.462 low = 105.388 close = 105.388 > Сформирована за 122162 тика.
2020.08.08 11:06:15.230 newCandles (USDJPY,H4)  2019.01.03 00:41:15 >>> Свеча 00001 >> open = 105.388 hihg = 109.388 low = 105.268 close = 109.388 > Сформирована за 1336258 тиков.
2020.08.08 11:06:19.056 newCandles (USDJPY,H4)  2019.01.17 21:50:34 >>> Свеча 00002 >> open = 109.388 hihg = 112.398 low = 105.388 close = 105.388 > Сформирована за 11546466 тиков.
2020.08.08 11:06:20.788 newCandles (USDJPY,H4)  2019.08.09 18:57:55 >>> Свеча 00003 >> open = 105.388 hihg = 109.388 low = 104.453 close = 109.388 > Сформирована за 5400916 тиков.
2020.08.08 11:06:22.592 newCandles (USDJPY,H4)  2019.11.07 17:57:24 >>> Свеча 00004 >> open = 109.388 hihg = 112.225 low = 105.384 close = 105.384 > Сформирована за 5555641 тик.
2020.08.08 11:06:22.725 newCandles (USDJPY,H4)  2020.03.06 11:47:26 >>> Свеча 00005 >> open = 105.384 hihg = 105.732 low = 101.377 close = 101.377 > Сформирована за 272724 тика.
2020.08.08 11:06:22.822 newCandles (USDJPY,H4)  2020.03.09 15:37:48 >>> Свеча 00006 >> open = 101.377 hihg = 105.378 low = 101.187 close = 105.378 > Сформирована за 314847 тиков.
2020.08.08 11:06:23.736 newCandles (USDJPY,H4)  2020.03.10 21:05:27 >>> Свеча 00007 >> open = 105.378 hihg = 109.385 low = 103.094 close = 109.385 > Сформирована за 2045775 тиков.
2020.08.08 11:06:27.124 newCandles (USDJPY,H4)  2020.03.19 04:13:11 >>> Свеча 00008 >> open = 109.385 hihg = 111.711 low = 105.385 close = 105.385 > Сформирована за 10250092 тика.
2020.08.08 11:06:27.296 newCandles (USDJPY,H4)  ~~~~ Предварительный расчёт индикатора закончен.
 
Сергей Таболин:

I'm afraid I don't understand you... Which bar do you propose to highlight? The one that has formed on me? Or on the chart?

If it is on the chart, I don't need them a priori. The indicator is considered the same on any timeframe.

The previous calculation was performed on H1, and now it is on H4. The result is the same.

Alexey told you that first you should at least make your indicator draw candles. As they are. At least on the current bar. If you manage to do it, consider that the first step towards the understanding has passed. But it is desirable not to try and find it by trying different parameters, but with your own mind.

What does this have to do with a priori? You need it very much - if you cannot draw a candle with only four values.

 
Artyom Trishkin:

Alexey told you that you should first make your indicator at least just draw candles. As they are. At least on the current bar. If you manage to do it, consider that the first step to understanding has passed. But it is desirable not to try and find it by trying different parameters, but with your own mind.

What does this have to do with "a priori"? You really need it since you cannot draw a candle with only four values.

Got it. Will do. ...

 
Hello forum users. Can you please tell me how to make a sequential receipt of signals. For example, I get the first one from 4h timeframe, then the hour timeframe, 15 minutes and enter the trade only on the minimum? I borrowed the code from CodeBase
//+------------------------------------------------------------------+
//| Search trading signals                                           |
//+------------------------------------------------------------------+
bool  SearchTradingSignals(void)
  {
   if(m_prev_bars==m_last_deal_in) // on one bar - only one deal
      return(true);
//---
   double  ma[];
   MqlRates  rates_1[],rates_2[],rates_3[],rates_4[];
   ArraySetAsSeries(ma,true);
   ArraySetAsSeries(rates_1,true);
   ArraySetAsSeries(rates_2,true);
   ArraySetAsSeries(rates_3,true);
   ArraySetAsSeries(rates_4,true);
   int  start_pos=0,count=3;
   if(!iGetArray(handle_iMA,0,start_pos,count,ma) ||
      CopyRates(m_symbol.Name(),Inp_Timeframe_1,start_pos,count,rates_1)!=count ||
      CopyRates(m_symbol.Name(),Inp_Timeframe_2,start_pos,count,rates_2)!=count ||
      CopyRates(m_symbol.Name(),Inp_Timeframe_3,start_pos,count,rates_3)!=count ||
      CopyRates(m_symbol.Name(),Inp_Timeframe_4,start_pos,count,rates_4)!=count)
     {
      return(false);
     }
   int  size_need_position=ArraySize(SPosition);
   if(size_need_position>0)
      return(true);

   if((rates_1[0].open<rates_1[0].close) && (rates_2[0].open<rates_2[0].close) &&
      (rates_3[0].open<rates_3[0].close) && (rates_4[0].open<rates_4[0].close) && ma[2]<ma[1] && ma[1]<ma[0])
     {
      if(!InpReverse)
        {
         if(InpTradeMode!=sell)
           {
            ArrayResize(SPosition,size_need_position+1);
            SPosition[size_need_position].pos_type=POSITION_TYPE_BUY;
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY");
            return(true);
           }
        }
      else
        {
         if(InpTradeMode!=buy)
           {
            ArrayResize(SPosition,size_need_position+1);
            SPosition[size_need_position].pos_type=POSITION_TYPE_SELL;
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL");
            return(true);
           }
        }
     }
   if((rates_1[0].open>rates_1[0].close) && (rates_2[0].open>rates_2[0].close) &&
      (rates_3[0].open>rates_3[0].close) && (rates_4[0].open>rates_4[0].close) && ma[2]>ma[1] && ma[1]>ma[0])
     {
      if(!InpReverse)
        {
         if(InpTradeMode!=buy)
           {
            ArrayResize(SPosition,size_need_position+1);
            SPosition[size_need_position].pos_type=POSITION_TYPE_SELL;
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL");
            return(true);
           }
        }
      else
        {
         if(InpTradeMode!=sell)
           {
            ArrayResize(SPosition,size_need_position+1);
            SPosition[size_need_position].pos_type=POSITION_TYPE_BUY;
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY");
            return(true);
           }
        }
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+

Four Timeframes 2
Four Timeframes 2
  • www.mql5.com
На одном из таймфреймов (задается через параметр 'MA Trend ') создаётся трендовый индикатор iMA (Moving Average, MA). Именно этот индикатор будет работать в качестве трендового фильтра. Тренд определяется так: MA на трёх барах (#2, #1 и #0) имеет одно направление. Советник проверяет направление бара #0 (это самый правый бар, который Вы видите...
 
Hello. I have decided to try to master both the mql5 language and the mt5 platform. I have a question about the tester. My question is about the quotes. I have put the audcad pair on the platform from Weltrade. I have a small informational panel in my Expert Advisor. I see in visualization mode that spreads are not correct (very small, similar to eurusd spread). I contacted the technical support of the company (Veltrade) and asked if there are different spreads for mt4 and mt5. They answered they are the same. What should I do if there is no correspondence in the tester? I tried to optimize it using the genetic code. My CPU load was 100%, and after a few minutes of work my computer crashed (processor was a phenom II x4 955 (4 cores, 3.2 GHz), cooler was on spare). After two times I decided not to risk any more. How should I understand such a situation? Then, when testing without visualization there is no deal information at all, only a chart. Is it true or am I doing something wrong? The informativeness is rather poor in visualization mode. In fact, I'm most worried about the inconsistency of spreads. In short, my first impression is of complete disappointment. But I discount it to the fact that I haven't figured it out yet.
 
Youri Lazurenko:
Hello. I have decided to try to master both the mql5 language and the mt5 platform. I have a question about the tester. I have a question about quotes. I have put the audcad pair on the platform from Weltrade. I have a small informational panel in my Expert Advisor. I see in visualization mode that spreads are not correct (very small, similar to eurusd spread). I contacted the technical support of the company (Veltrade) and asked if there are different spreads for mt4 and mt5. They answered they are the same. What should I do if there is no correspondence in the tester? I tried to optimize it using the genetic code. My CPU load was 100%, and after a few minutes of work my computer crashed (processor was a phenom II x4 955 (4 cores, 3.2 GHz), cooler was on spare). After two times I decided not to risk any more. How should I understand such a situation? Then, when testing without visualization there is no deal information at all, only a chart. Is it true or am I doing something wrong? The informativeness is rather poor in visualization mode. In fact, I'm most worried about the inconsistency of spreads. In short, my first impression is of complete disappointment. But I discount it to the fact that I haven't figured it out yet.

Set testing based on real ticks. Then all doubts about the validity of the spread will disappear.


 
Alexey Viktorov:

Set testing based on real ticks. Then all doubts about the validity of the spread will disappear.


Thank you, I will try it now. What is your advice on the optimization. I am more interested in the speed. I may correct the quality later, when testing.

P.S. I have done as you advised, spreads are the same. I have purposefully checked the account type. It is specified to spread on audcad 4.1 (floating). On the same account (demo chart) it is 4.7 (floating). In the tester, mt5, maximum 2.8 (floating to a smaller side).

 
Youri Lazurenko:

Thank you, I'll give it a try. What's your advice on optimisation? I'm more interested in speed. Quality can be adjusted later, when testing.

I can't give you any advice. I don't use optimisation. I think it is just a quack.

Reason: