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

mila.com  
Artyom Trishkin:

To completely detach the functions for getting arbitrary fractals from the indicator, we should not pass by reference arrays high[] and low[] and limit value into them.

Since our code is very close to MQL5, we will have to refuse High[], Low[], iHigh() and iLow() functions. This is how it will look in this indicator:

Although, you should also check for -1 from functions GetPriceHigh() and GetPriceLow()
Thank you.
Artyom Trishkin  
strongflex:
RSI should be 15 minutes. We need the EA to check it every 20 minutes from market opening (9-00, 9-20, 9-40 etc.) Let's say at 10-20 there was a cross below the 70 level it remembers the price and at 10-40 checks if the price is lower than at 10-20 it opens a short.

Well first you need to make the time get a given number of minutes back. Here is a test script:

//+------------------------------------------------------------------+
//|                                                sTestValueRSI.mq4 |
//|              Copyright 2016, Artem A. Trishkin, Skype artmedia70 |
//|                       https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Artem A. Trishkin, Skype artmedia70"
#property link      "https://login.mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property strict
#property script_show_inputs
//--- input parameters
input ENUM_TIMEFRAMES   TimeframeRSI   = PERIOD_M15;  // Таймфрейм RSI
input int               MinutesBefore  =20;           // Количество минут назад
int minutesBefore=(MinutesBefore<1?1:MinutesBefore);  // Количество минут назад

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   datetime time_before=TimeCurrent()-minutesBefore*PeriodSeconds(PERIOD_M1);
   int shift=Bars(Symbol(),TimeframeRSI,TimeCurrent(),time_before);
   double value=iRSI(Symbol(),TimeframeRSI,14,PRICE_CLOSE,shift);
   Comment("\nCurrent time: ",TimeToString(TimeCurrent()),
           "\nВремя ",minutesBefore," минут назад: ",TimeToString(time_before),
           "\nБар времени ",TimeToString(time_before)," = ",shift," на таймфрейме ",EnumToString(TimeframeRSI),
           "\nЗначение RSI на баре ",shift," периода ",EnumToString(TimeframeRSI),": ",DoubleToString(value,Digits()));
  }
//+------------------------------------------------------------------+

This script is counting down from current server time - just test getting RSI data a given number of minutes ago.

Artyom Trishkin  

Next, we need to know the current time, and whether its value is a multiple of the minutes of the check interval. I have made it into a test EA:

//+------------------------------------------------------------------+
//|                                               exTestValueRSI.mq4 |
//|              Copyright 2016, Artem A. Trishkin, Skype artmedia70 |
//|                       https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Artem A. Trishkin, Skype artmedia70"
#property link      "https://login.mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property strict
//--- input parameters
input ENUM_TIMEFRAMES      TimeframeRSI   = PERIOD_M15;  // Таймфрейм RSI
input int                  PeriodRSI      = 14;          // Период расчёта RSI
input ENUM_APPLIED_PRICE   PriceRSI       = PRICE_CLOSE; // Цена расчёта RSI
input int                  MinutesBefore  =20;           // Количество минут назад
//--- global variables
int      minutesBefore; // Количество минут назад
int      periodRSI;     // Период расчёта RSI
double   prevRSIValue;  // Значение RSI xxx минут назад
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   minutesBefore=(MinutesBefore<1?1:MinutesBefore);  // Количество минут назад
   periodRSI=(PeriodRSI<1?1:PeriodRSI);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   MqlDateTime server_time;
   TimeToStruct(TimeCurrent(),server_time);
   if(server_time.min%minutesBefore==0) prevRSIValue=GetLastDataRSI(Symbol(),TimeframeRSI,TimeCurrent(),minutesBefore);
   Comment("\nТекущее время: ",TimeCurrent(),"\nМинуты текущего времени: ",server_time.min,"\nЗначение RSI: ",DoubleToString(prevRSIValue,Digits()));
  }
//+------------------------------------------------------------------+
double GetLastDataRSI(string symbol_name, ENUM_TIMEFRAMES timeframe, datetime start_time, int minutes_before,
                      int period_rsi=14, ENUM_APPLIED_PRICE price_rsi=PRICE_CLOSE)
  {
   datetime time_before=start_time-minutes_before*PeriodSeconds(PERIOD_M1);
   int shift=Bars(symbol_name,timeframe,start_time,time_before);
   return(iRSI(symbol_name,timeframe,period_rsi,price_rsi,shift));
  }
//+------------------------------------------------------------------+

Next, what do we need to know?

Vladymyr Glushko  
Good afternoon. I am new to trading, so I have a lot of questions, including software questions, in my case it is MT4. Is it possible to put a spread of currency pair, for example, on a chart window in the form of numbers and in the same way an indicator of ATR? I think it would be convenient to use this way of presenting information about market situation, it is more convenient and quicker to calculate and evaluate based on averages. The second point is moving stop based on ATR. Is it possible to make it automatic? If you are sitting in a pose, then thanks to the calculator and good eyesight, you can calculate and set a stop manually - no problem. And making it automatic is a nice idea for a trader, even if it has its disadvantages, but in a good trend a trailing stop will reduce the risk of a wrong stop by a newbie. Thanks in advance.
strongflex  
Artyom Trishkin:

Next, we need to know the current time, and whether its value is a multiple of the minutes of the check interval. I have made it into a test EA:

//+------------------------------------------------------------------+
//|                                               exTestValueRSI.mq4 |
//|              Copyright 2016, Artem A. Trishkin, Skype artmedia70 |
//|                       https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Artem A. Trishkin, Skype artmedia70"
#property link      "https://login.mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property strict
//--- input parameters
input ENUM_TIMEFRAMES      TimeframeRSI   = PERIOD_M15;  // Таймфрейм RSI
input int                  PeriodRSI      = 14;          // Период расчёта RSI
input ENUM_APPLIED_PRICE   PriceRSI       = PRICE_CLOSE; // Цена расчёта RSI
input int                  MinutesBefore  =20;           // Количество минут назад
//--- global variables
int      minutesBefore; // Количество минут назад
int      periodRSI;     // Период расчёта RSI
double   prevRSIValue;  // Значение RSI xxx минут назад
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   minutesBefore=(MinutesBefore<1?1:MinutesBefore);  // Количество минут назад
   periodRSI=(PeriodRSI<1?1:PeriodRSI);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   MqlDateTime server_time;
   TimeToStruct(TimeCurrent(),server_time);
   if(server_time.min%minutesBefore==0) prevRSIValue=GetLastDataRSI(Symbol(),TimeframeRSI,TimeCurrent(),minutesBefore);
   Comment("\nТекущее время: ",TimeCurrent(),"\nМинуты текущего времени: ",server_time.min,"\nЗначение RSI: ",DoubleToString(prevRSIValue,Digits()));
  }
//+------------------------------------------------------------------+
double GetLastDataRSI(string symbol_name, ENUM_TIMEFRAMES timeframe, datetime start_time, int minutes_before,
                      int period_rsi=14, ENUM_APPLIED_PRICE price_rsi=PRICE_CLOSE)
  {
   datetime time_before=start_time-minutes_before*PeriodSeconds(PERIOD_M1);
   int shift=Bars(symbol_name,timeframe,start_time,time_before);
   return(iRSI(symbol_name,timeframe,period_rsi,price_rsi,shift));
  }
//+------------------------------------------------------------------+

Next, what do we need to know?

Next, if there is a cross of the RSI level 20 minutes ago, we check the price, i.e., for a short, the price should be lower than 20 minutes ago. Thank you very much. If it works, I owe you a promise))
Artyom Trishkin  
Vladymyr Glushko:
Good day. I am new to trading, that is why I have a lot of questions, including software, in my case it is MT4. Is it possible to display spread of currency pair in the chart window as a number, and in the same way ATR indicator? I think it would be convenient to use this way of presenting information about market situation, it is more convenient and quicker to calculate and evaluate based on averages. The second point is moving stop based on ATR. Is it possible to make it automatic? If you are sitting in a pose, then thanks to the calculator and good eyesight, you can calculate and set a stop manually - no problem. And making it automatic is a nice idea for a trader, even if it has its disadvantages, but in a good trend a trailing stop will reduce the risk of a wrong stop by a newbie. Thank you in advance.

It's simple and straightforward - display graphical objects, in particular text labels with the required data on the chart, and update them on every tick.

If you do not know what kind of trawl you are dealing with, just look for the right one ;)

Artyom Trishkin  
strongflex:
Then if the RSI level has been crossed 20 minutes ago we check the price, i.e. for a short the price should be lower than 20 minutes ago. Thank you very much. If it all works out I'll be charged with the promise))
We will only be able to check the price "now" "then" by opening/closing/high/low candle corresponding to that time - no tick history in MT4. So we need to find a crossover on the minutes for the most accurate price determination available. But what do you mean by RSI crossover ?
strongflex  

Artyom Trishkin:
Мы сможем "сейчас" проверить цену "тогда" лишь только открытия/закрытия/хай/лоу свечи, соответствующей тому времени - нету в МТ4 тиковой истории. Поэтому нужно найти пересечение на минутках для наиболее точного определения цены из имеющихся в наличии возможностей. Но что вы имеете в виду под пересечением RSI ?

RSI crossing the 70 level let's say RSI at 10-00 was below 70 at 10-20 above 70 and at 10-40 check the 10-20 should be higher than at 10-40
Vladymyr Glushko  
Artyom Trishkin:

It's easy and straightforward - you display graphical objects, in particular text labels with the required data on the chart, and update them on every tick.

And different trawls in kodobase are a dime a dozen - look for the right one ;)

Thanks a lot ...... we will look for it))

Vladymyr Glushko  
Artyom Trishkin:

Everything is easy and simple - display graphical objects, in particular - text labels with the required data on the chart, and update them on every tick.

And different trawls in kodobase are a dime a dozen - find the right one for yourself ;)

But how to do it step by step? ..... graphical objects (what is it and how to set them), put labels with the data on the chart (where to enter and with what data) ...... sorry for the silly questions.