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

 
Artyom Trishkin:
This is a simple software restriction, not related to the default settings of the EA settings window - these settings belong to the EA settings, and they are controlled in the EA itself.

Thank you) Now I understand how it is implemented

 
Alexandr Sokolov:
How to get profit and loss values when TP or SL is reached in the code?

For example, there is the function AccountFreeMarginCheck(), with which you can get the margin. And there are no functions to determine the point value at least for the specified symbol, volume and order type

MQL4

https://www.mql5.com/ru/forum/131859/page3

You can find a lot of functions here. Maybe you can fix something for yourself and you'll be fine.

Только "Полезные функции от KimIV".
Только "Полезные функции от KimIV".
  • 2011.02.18
  • www.mql5.com
Все функции взяты из этой ветки - http://forum.mql4...
 

and how do I set the recalculation function when I estimate the TF graph?

 
Lomonosov1991:

and how do I set the recalculation function when I estimate the TF graph?

There is documentation. It is possible to look through it sometimes. There is a function: UninitializeReason(), it returns code of deinitialization reason. And there are even examples.

Документация по MQL5: Константы, перечисления и структуры / Именованные константы / Причины деинициализации
Документация по MQL5: Константы, перечисления и структуры / Именованные константы / Причины деинициализации
  • www.mql5.com
//| get text description                                             | //| Expert deinitialization function                                 |
 

Good evening. At the request of a friend I have made a modified version of the standard MT5Stochastic indicator Stoch_HISTOGRAM_MQL5_3

This version displays the indicator as a bar chart. My friend asked for the bars above 50 to be green and those below 50 to be red.

I've managed to handle bargraphs but I don't know how to change the colour, it just blew my mind. Help advice plz.

I'll paste the code below and attach the file.

//+------------------------------------------------------------------+
//|                                       Stoch_HISTOGRAM_MQL5_3.mq5 |
//|                   Copyright 2009-2017, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots   3
#property indicator_type1   DRAW_LINE
#property indicator_type2   DRAW_LINE
#property indicator_type3   DRAW_HISTOGRAM2
#property indicator_type4   DRAW_HISTOGRAM2
#property indicator_color1  LightSeaGreen
#property indicator_color2  Blue
#property indicator_color3  Green
#property indicator_style2  STYLE_DOT
#property indicator_style3  STYLE_SOLID
//--- input parameters
input int InpKPeriod=5;  // K period
input int InpDPeriod=3;  // D period
input int InpSlowing=3;  // Slowing
//--- indicator buffers
double    ExtMainBuffer[];
double    ExtSignalBuffer[];
double    HISTOGRAM2_1[];
double    HISTOGRAM2_2[];
double    ExtHighesBuffer[];
double    ExtLowesBuffer[];
color     colors[]={clrRed,clrGreen};
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMainBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,HISTOGRAM2_1,INDICATOR_DATA);
   SetIndexBuffer(3,HISTOGRAM2_2,INDICATOR_DATA);
   SetIndexBuffer(4,ExtHighesBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,ExtLowesBuffer,INDICATOR_CALCULATIONS);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- set levels
   IndicatorSetInteger(INDICATOR_LEVELS,3);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,20);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,50);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,2,80);
////--- установим пустое значение для HISTOGRAM2
//   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);   
//--- set maximum and minimum for subwindow 
   IndicatorSetDouble(INDICATOR_MINIMUM,0);
   IndicatorSetDouble(INDICATOR_MAXIMUM,100);
//--- name for DataWindow and indicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"Stoch_HISTOGRAM("+(string)InpKPeriod+","+(string)InpDPeriod+","+(string)InpSlowing+")");
   PlotIndexSetString(0,PLOT_LABEL,"Main");
   PlotIndexSetString(1,PLOT_LABEL,"Signal");
   PlotIndexSetString(2,PLOT_LABEL,"UP");
   PlotIndexSetString(3,PLOT_LABEL,"LOW");
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKPeriod+InpDPeriod);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Stochastic Oscillator                                            |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i,k,start;
//--- check for bars count
   if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing)
      return(0);
//---
   start=InpKPeriod-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++)
        {
         ExtLowesBuffer[i]=0.0;
         ExtHighesBuffer[i]=0.0;
        }
     }
//--- calculate HighesBuffer[] and ExtHighesBuffer[]
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double dmin=1000000.0;
      double dmax=-1000000.0;
      for(k=i-InpKPeriod+1;k<=i;k++)
        {
         if(dmin>low[k])  dmin=low[k];
         if(dmax<high[k]) dmax=high[k];
        }
      ExtLowesBuffer[i]=dmin;
      ExtHighesBuffer[i]=dmax;
     }
//--- %K
   start=InpKPeriod-1+InpSlowing-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++) ExtMainBuffer[i]=0.0;
     }
//--- main cycle
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double sumlow=0.0;
      double sumhigh=0.0;
      for(k=(i-InpSlowing+1);k<=i;k++)
        {
         sumlow +=(close[k]-ExtLowesBuffer[k]);
         sumhigh+=(ExtHighesBuffer[k]-ExtLowesBuffer[k]);
        }
      if(sumhigh==0.0) ExtMainBuffer[i]=100.0;
         else          ExtMainBuffer[i]=sumlow/sumhigh*100;
      if(ExtMainBuffer[i]>50){
         HISTOGRAM2_1[i]=50; 
         HISTOGRAM2_2[i]=ExtMainBuffer[i]; 
         //colors[i]=clrGreen;
         //PlotIndexSetInteger(2,PLOT_LINE_COLOR,clrGreen);
         } 
      if(ExtMainBuffer[i]<50){
         HISTOGRAM2_1[i]=ExtMainBuffer[i]; 
         HISTOGRAM2_2[i]=50; 
         //colors[i]=clrRed;
         //PlotIndexSetInteger(2,PLOT_LINE_COLOR,clrRed);
         } 
      //PlotIndexSetInteger(2,PLOT_LINE_COLOR,colors[i]);
     }
//--- signal
   start=InpDPeriod-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++) ExtSignalBuffer[i]=0.0;
     }
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double sum=0.0;
      for(k=0;k<InpDPeriod;k++) sum+=ExtMainBuffer[i-k];
      ExtSignalBuffer[i]=sum/InpDPeriod;
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Sergey Voytsekhovsky:

Good evening. At the request of a friend I have made a modified version of the standard MT5Stochastic indicator Stoch_HISTOGRAM_MQL5_3

This version displays the indicator as a bar chart. My friend asked for the bars above 50 to be green and those below 50 to be red.

I've managed to handle bargraphs but I don't know how to change the colour, it just blew my mind. Help advice plz.

I'll paste the code below, I'll attach the file.

It's just amazing. How can one read the documentation and see DRAW_HISTOGRAM2 and not see DRAW_COLOR_HISTOGRAM2

Oh, and there are extra buffers declared.
 
Alexey Viktorov:

It's just amazing. How can one read the documentation and see DRAW_HISTOGRAM2 and not see DRAW_COLOR_HISTOGRAM2

Oh, and the buffers are redundant.

Thank you for your comment. Oooh, you have no idea how much you can NOT notice, reading documentation, when you are looking for ways and solutions by feel, as in a fog, when there is no teacher, mentor, more experienced comrade, etc. Thanks a lot, I already found DRAW_COLOR_HISTOGRAM2, I understand the meaning of it, I will remake it now.

Could you tell me more about extra buffers? You can't have too much experience, but you can have too many buffers. :-0

 
Sergey Voytsekhovsky:

Thank you for your comment. Oooh, you have no idea how much you can NOT notice, reading documentation, when you are looking for ways and solutions by feel, as in a fog, when there is no teacher, mentor, more experienced comrade, etc. Thanks a lot, I already found DRAW_COLOR_HISTOGRAM2, I understand the meaning of it, I will remake it now.

Could you tell me more about extra buffers? You can't have too much experience, but you can have too many buffers. :-0

Well... If the stochastic has 2 buffers, if I don't have all the memory chips burnt out. To be exact, 2 of them are. Accordingly, only they should be saved, replacing them with a histogram display. Actually, for two plots DRAW_COLOR_HISTOGRAM2 will need 6 buffers. But although I said number, I meant these lines

#property indicator_type1   DRAW_LINE
#property indicator_type2   DRAW_LINE
#property indicator_type3   DRAW_HISTOGRAM2
#property indicator_type4   DRAW_HISTOGRAM2

In my opinion, it should be like this

#property indicator_buffers 5
#property indicator_plots   2
#property indicator_type1   DRAW_COLOR_HISTOGRAM2 // основная 
#property indicator_type2   DRAW_LINE             // сигнальная
#property indicator_color1  clrGreen,clrRed       // цвет гистограмм
#property indicator_color2  clrBlue               // цвет линии
 

Greetings All!
A hint, if you know.

You see, the green one (Vigor=0.1154) did not even cross the red one (Signal=0.1133) nearby, but it sold. And it is not an isolated case.

Here's another one.

Here they are "merged", but still Vigor=0.0543 and Signal=0.0525.

Everything is "pronormalized" everywhere.

Code of this condition: && RVI_S_S >0 && RVI_S_M < RVI_S_S && RVI_S_M1 > RVI_S_S1

RVI_S_S (Signal-red), respectively RVI_S_M (Vigor-green).

If anyone has anything worthwhile to say, I'd be very grateful.

 
KrasAleks:

Greetings All!
A hint, if you know.

You see, the green one (Vigor=0.1154) did not even cross the red one (Signal=0.1133) nearby, but it sold. And it is not an isolated case.

Here's another one.

Here they are "merged", but still Vigor=0.0543 and Signal=0.0525.

Everything is "pronormalized" everywhere.

Code of this condition: && RVI_S_S >0 && RVI_S_M < RVI_S_S && RVI_S_M1 > RVI_S_S1

RVI_S_S (Signal-red), respectively RVI_S_M (Vigor-green).

If anyone has anything worthwhile to say, I'd be very grateful.

There was probably a crossover, but it was redrawn.
Check the signal after the candle closes.

Reason: