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

 
Northwest:

1. Put everything back, don't torture the computer .

I'm sorry, but you can't do that, the indicator has to count from left to right.

I'm not bothering it, I'm using it for its intended purpose.

2.iBandsOnArray, iStdDevOnArray calculated using data stored in the array

Yes, they are calculated using data from bbMacd[] array, so what next?

3.The array is filled in one loop.

In one or in the first one?

Are you saying that in order to fill one array, you need a personal loop, in which this array is filled

array is filled and no other operations may be performed?


It is important for me to find out why the indicator slows down and how to calculate those places where it happens.

I have more questions but no answers.

Unfortunately, you haven't offered any clues.

If something is built using an array, it should be built using an already existing array. This is one cycle of array preparation and the second cycle of drawing of an indicator by this array. This is a general case. There are some more specific cases, but they should be considered separately - for example, we can create functions, that return values from only one calculated bar:

//+------------------------------------------------------------------+
//| BandsOnArray                                                     |
//+------------------------------------------------------------------+
double BandsOnArray(const int rates_total,const int index,const int period,const double deviation_bb,const double &array[],const int line,const bool as_series=true)
  {
//--- check position
   bool check_index=(as_series ? index<=rates_total-period-1 : index>=period-1);
   if(period<1 || !check_index)
      return 0;
   //--- calculate StdDev
   double dev=StdDevOnArray(rates_total,index,period,array);
   //--- base line
   double mid=0;              
   for(int i=0; i<period; i++)
      mid+=array[index+i];    
   mid/=period;               
   //--- upper line
   double top=mid+dev*deviation_bb;
   //--- lower line
   double btm=mid-dev*deviation_bb;
   return(line==UPPER_BAND ? top : line==LOWER_BAND ? btm : mid);
  }  
//+------------------------------------------------------------------+
//| StdDevOnArray                                                    |
//+------------------------------------------------------------------+
double StdDevOnArray(const int rates_total,const int index,const int period,const double &array[],const bool as_series=true)
  {
//--- check position
   bool check_index=(as_series ? index<=rates_total-period-1 : index>=period-1);
   if(period<1 || !check_index)
      return 0;
//--- calculate value
   double avg=0;              
   for(int i=0; i<period; i++)
      avg+=array[index+i];    
   avg/=period;               
   double sd=0;
   for(int i=0; i<period; i++)
      sd+=(avg-array[index+i])*(avg-array[index+i]);
   return(sqrt(sd/period));
  }  
//+------------------------------------------------------------------+

But they also require an already prepared data array as an input, because StdDevOnArray and BandsOnArray use Simple-smoothing for which the filled data equal to the value of Period smoothing are needed.

 

Forum on trading, automated trading systems & strategy testing

Any questions for newbies on MQL4, help and discussion on algorithms and codes

Artyom Trishkin, 2018.11.18 20:21

PlotIndexSetInteger(0,PLOT_ARROW,140);

But you need to create a number of buffers equal to the number of weeks. And for each buffer you have to give an arrow code from 140 to 149 - 1,2,3,4,5,6,7,8,9,10 - is ten weeks enough for a year? That's only 70 days. Or how did you want it?


Is it possible to override SetIndexArrow via case?

Or at least display the numbers on a histogram?


Forum on trading, automated trading systems and strategy testing

Any MQL4 beginners questions, help and discussion on algorithms and codes

Artyom Trishkin, 2018.11.18 20:02

The buffer is filled with the value of an hour. And if the hour is zero, the histogram won't be drawn. So, we must check if hour is equal to zero (we have set it to search for zero hour in the settings), and if it is equal to zero, we must enter 0.1 instead of hour value (zero) into the buffer - to show the histogram column. This will show a value of 0 instead of 0.1 in the data window, as the indicator Digits is set to zero.


I see it now, thank you.

 
psyman:

Can SetIndexArrow be overwritten by a case?

Or at least display the numbers on a bar graph?



I see it now, thank you.

It acts on the whole buffer at once.

You need to put an icon of a week number on the found bar, and there should be the number of weeks in a year. The number arrows are clearly missing in Wingdings.

It is possible to turn out with object-texts and mark the bars with the value of the week number, but set the icon for the buffer to 32 - an empty character. The value will be on the bar, but will not be displayed. Then the value can be the number of the week in the year, and in the object write whatever you want and the object will be displayed on the bar found.

 

Forum on trading, automated trading systems & strategy testing

Any questions for beginners on MQL4, help and discussion on algorithms and codes

Artyom Trishkin, 2018.11.19 10:50 am

It acts on the whole buffer at once.

You need to put a week number icon on the found bar, and there should be the number of weeks in a year. The number arrows are clearly missing in Wingdings.

You can get out by using object-texts, and mark the bars with the values of the number of the week, but the icon for the buffer to set 32 - an empty character. The value will be on the bar, but will not be displayed. Then the value can be the number of the week in the year, and in the object write whatever you want and the object will be displayed on the bar found.


I wrote about the day of the week - Mon, Tue, Wed, not the number. You only need 5 different marks on the chart.

 
psyman:

I wrote about the day of the week - Mon, Tues, Wed, not the number. You only need five different marks on the chart.

Well then you need five buffers, and assign a different arrow number to each - from 140 to 144.

 
Artyom Trishkin:

If something is built using an array, it should be built using an already prepared array. And this is one cycle of array preparation and the second cycle of drawing of the indicator by this array. This is a general case. There are some more specific cases, but they should be considered separately - for example, we can create functions, that return values from only one calculated bar:

But they also require an already prepared data array as an input, because StdDevOnArray and BandsOnArray use Simple-smoothing for which the filled data equal to the value of Period smoothing are needed.

Thank you for clarifying the situation.
 

hello

How do I make a pop-up window with buttons to manually confirm/cancel a transaction?

 
Andrey Sokolov:

hello

How do I make a pop-up window with buttons to manually confirm/cancel a transaction?

MessageBox()
 
Artyom Trishkin:
MessageBox()

Thanks

 

Hi all.

How do I get the percentage of maximum drawdown as in the tester?

Here is the code:

double  MaxPeak,DD, MaxDD, DD2, MaxDD2;
--------------------------------------
--------------------------------------
это вывод:

 SM("Maximal drawdown        : " + DoubleToString(MaxDrawdown_Money(), 2)+ " (" + DoubleToString(MaxDrawdown_Protsent(), 2) +" %)");

-------------------------------------
-------------------------------------

//--------------------Рассчет % относительной просадки----------
double MaxDrawdown_Protsent()
{
if (AccountEquity() > MaxPeak)
{
MaxPeak = AccountEquity();
}
if (AccountEquity() < MaxPeak)
{
DD2 = NormalizeDouble((MaxPeak - AccountEquity())/MaxPeak*100,2);
}
if (MaxDD2< DD2)
{
MaxDD2 = DD2;
}
return (MaxDD2);
}
//---------------------Рассчет суммы максимальной просадки--------
double MaxDrawdown_Money()
{
if (AccountEquity() > MaxPeak)
{
MaxPeak = AccountEquity();
}
if (AccountEquity() < MaxPeak)
{
DD = NormalizeDouble(MaxPeak - AccountEquity(),2);
}
if (MaxDD< DD)
{
MaxDD = DD;
}
return (MaxDD);
}

The amount of max drawdown is the same as in the tester, the percentage of relative drawdown is also the same as in the tester.

How do I get the percentage of max drawdown as in the tester ?