Questions from Beginners MQL5 MT5 MetaTrader 5 - page 757

 
User_mt5:


Generally speaking, there is a concept called the "gradient". It is an indicator that describes the "steepness" (of a graph). For this industry this indicator can be expressed in terms of point/time. It is essentially a rate. This indicator will not depend on scale, as it is not attached to the graph. Use a gradient and do not use an angle.


How do you calculate this gradient?

Is there any way you can elaborate on your idea? Please note which forum thread I wrote my question in.

 
igorbel:

How do you calculate this gradient?

Is there any way you can elaborate on your idea? Note which forum thread I wrote my question in.

I don't have an idea.

I'm talking about simple maths. The gradient is the speed. Speed itself is when time is in the denominator. In familiar usage it is the speed of a car, expressed in km/hour. But speed in general can be different. For example, the speed of writing software code is measured in number of lines per day. In the case of a price chart, speed is measured in the number of points per minute. Conventionally, we can assume that if the gradient (slope, rate of ascent) at some part of the chart is higher than, for example, 100 points/minute, then this part can be considered a trend, and if less, then a flat.

 

Hello 2017.07.07_15:55 GMT+3. I don't understand. It seems like there should be a signal, but in the strategy tester there isn't one. How then is your praised MT5 tester different from the MT4 tester? I wrote it almost like in the standard Moving Average.mq5 . But I managed to test the Expert Advisor on my demo account. It opened a trade but had to close it by itself. I fixed the closing. But I have written something else and the EA has stopped opening trades again. Zero errors and zero warnings are not an indicator of the good condition of the Expert Advisor. I got stuck here. How do I know what it says that the Expert Advisor is not working? I have to bother Karputov again. If I had received the entire list of bans, I would have done it myself. I'm posting the files, although not all of them. 16:06 GMT+3.

 

Please help!

To get indicator's value in MQL4 the following function is sufficient

double CMAf(int index)
  {
   return NormalizeDouble(iMA(Symbol(),0,period_CMA,0,0,0,index),Digits);
  }
How to get an analogue for MQL5?
 
-Aleks-:

Please help!

To get an indicator's name in MQL4, a simple function is enough

How to get an analogue for MQL5?

Have you looked at theiMA help?

Step One: In the "header", declare a variable for storing the iMA indicator handle:

Step two: create indicator handle in OnInit().

//+------------------------------------------------------------------+
//|                                                       iMAGet.mq5 |
//|                              Copyright © 2017, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
//--- input parameters
input int                  ma_period=10;                 // period of ma 
input int                  ma_shift=0;                   // shift 
input ENUM_MA_METHOD       ma_method=MODE_SMA;           // type of smoothing 
input ENUM_APPLIED_PRICE   applied_price=PRICE_CLOSE;    // type of price 
input ENUM_TIMEFRAMES      period=PERIOD_CURRENT;        // timeframe 
//---
int                        handle_iMA;                   // variable for storing the handle of the iMA indicator 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator iMA
   handle_iMA=iMA(Symbol(),period,ma_period,ma_shift,ma_method,applied_price);
//--- if the handle is not created 
   if(handle_iMA==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double ma_0=iMAGet(0);
   double ma_1=iMAGet(1);

   Comment("MA #0: ",DoubleToString(ma_0,Digits()+1),"\n",
           "MA #1: ",DoubleToString(ma_1,Digits()+1));
  }
//+------------------------------------------------------------------+
//| Get value of buffers for the iMA                                 |
//+------------------------------------------------------------------+
double iMAGet(const int index)
  {
   double MA[1];
//--- reset error code 
   ResetLastError();
//--- fill a part of the iMABuffer array with values from the indicator buffer that has 0 index 
   if(CopyBuffer(handle_iMA,0,index,1,MA)<0)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(0.0);
     }
   return(MA[0]);
  }
//+------------------------------------------------------------------+


And the result (crosshair on the screenshot is set at bar #1):

iMAGet

Files:
iMAGet.mq5  7 kb
 
Vladimir Karputov:

Have you seen theiMA help?

Step one: declare a variable in the "header" to store iMA indicator handle:

Step two: create indicator handle in OnInit().

And the result (crosshair on the screenshot is set at bar #1):

Thanks for the reply.

In MQL4 everything is declared in a function - so there is a set of functions that are activated depending on the EA settings. If I'm not mistaken, in your case the memory will be allocated for dozens of different indicators that the TS allows to use, which is not rational, or the memory will not be allocated?

 

Is it possible to call a class function without having a specific object of that class? So it would be something like this:

class test
  {
public:
                     test(void);
                    ~test(void);
  public: void PrintInfo (){Print ("Class test");}
  };
//---
void OnStart()
  {
      test.PrintInfo() ;
  }

Or is it necessary to create an object? Even if this function refers to the definition of the class itself, rather than an instance of it.

 

If the function does not need access to class variables, make it static.

class test
{
public:
   test();
   ~test();

   static void PrintInfo()
   {
      Print( "Class test" );
   }
};

void OnStart()
{
   test::PrintInfo();
}
 
Koldun Zloy:

If the function does not need access to class variables, make it static.

Thank you, that's just what's needed.
 

Getting errors - what's wrong? In MQL4 it works...


   double arrFibo[17]=
     {
      0,
      0.236,
      0.382,
      0.5,
      0.618,
      0.764,
      1,
      1.236,
      1.382,
      1.5,
      1.618,
      2.0,
      2.236,
      2.382,
      2.5,
      2.618,
      2.764,
      3        //Всего уровней 17 + 0
     };
'{' - too many initializers TZ_Sky_and_Ground_V_04.mq5 2484 6
Reason: