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

 
RomanRott:

I mean to prescribe some code in my indicator/advisor, which would immediately connect some other indicators when switching on
What kind of code?

Something tells me it's for the tester. This is solved in half a click without programming. When you create a template with all indicators you need and give it the name "Tester" or the name of advisor. Then, when you run the advisor in the tester, a chart will be opened with indicators already set.

 
RomanRott:

I mean to write some code in my indicator/advisor, which would immediately connect some other indicators when switching on
What and how do I add?

I have many variants. For example 1) ChartApplyTemplate - applies to the chart the specified template (the template shows indicator). 2) Add the code of the indicator to be included in the indicator. 3) In the Expert Advisor, display the indicator by graphic objects. 4) ...
 

Hi, Can you please advise me, I need to integrate Vinini_HMA indicator into an EA, I have managed to connect it and get data via resource and iCustom, but the testing has become very slow. Please advise how to make the indicator values are calculated in the EA itself, I need only one parameter for the last 3 candles.

Here is the code of the indicator:

#property indicator_chart_window 
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green 
#property indicator_color3 Red 
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

//---- input parameters 
extern int period=15; 
extern int method=3; // MODE_SMA 
extern int price=0; // PRICE_CLOSE 
extern int sdvig=0;
//---- buffers 

double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];

double vect[]; 

//+------------------------------------------------------------------+ 
//| Custom indicator initialization function | 
//+------------------------------------------------------------------+ 
int init() { 
   IndicatorBuffers(4); 
   SetIndexBuffer(0, ExtMapBuffer); 
   SetIndexBuffer(1, Uptrend); 
   SetIndexBuffer(2, Dntrend); 
   SetIndexBuffer(3, vect); 
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);

   SetIndexDrawBegin(0,1*period);
   SetIndexDrawBegin(1,2*period);
   SetIndexDrawBegin(2,3*period);

   IndicatorShortName("Signal Line("+period+")"); 
   SetIndexLabel(1,"UP");
   SetIndexLabel(2,"DN");
   return(0); 
} 

//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function | 
//+------------------------------------------------------------------+ 
int deinit() { return(0); } 

//+------------------------------------------------------------------+ 
//| ?????????? ??????? | 
//+------------------------------------------------------------------+ 
double WMA(int x, int p) { return(iMA(NULL, 0, p, 0, method, price, x+sdvig)); } 

//+------------------------------------------------------------------+ 
//| Custom indicator iteration function | 
//+------------------------------------------------------------------+ 
int start() { 
   int counted_bars = IndicatorCounted(); 

   if (counted_bars < 0) return(-1); 
   if (counted_bars > 0) counted_bars--;
   
   int p = MathSqrt(period); 

   int i, limit0,limit1,limit2;
   
   limit2=Bars - counted_bars;
   limit1=limit2;
   limit0=limit1;

   if (counted_bars==0){
      limit1-=(period);
      limit2-=(2*period);
   }

   for(i = limit0; i >= 0; i--)    vect[i]          = 2*WMA(i, period/2) - WMA(i, period); 
   for(i = limit1; i >= 0; i--)    ExtMapBuffer[i]  = iMAOnArray(vect, 0, p, 0, method, i); 
   for(i = limit2; i >= 0; i--) { 
      Uptrend[i] = EMPTY_VALUE; if (ExtMapBuffer[i]> ExtMapBuffer[i+1]) Uptrend[i] = ExtMapBuffer[i]; `  AZ4
      Dntrend[i] = EMPTY_VALUE; if (ExtMapBuffer[i]< ExtMapBuffer[i+1]) Dntrend[i] = ExtMapBuffer[i]; 
   }
   return(0); 
} 

I need to calculate the last 3 values that are in the bufferExtMapBuffer[i]. I am a beginner, do not judge severely. I tried to insert these code fragments into the Expert Advisor, but the values are calculated incorrectly

extern int period1=14;
extern int method1=3;
extern int price1=0;
extern int sdvig1=0;

-----------------------------------------------------
.
int p = MathSqrt(period1);      
        
        int z = 3;
        double vect[];
        ArrayResize(vect,z);
        
for(int i = 2; i >= 0; i--) vect[i] = 2*WMA(i, period1/2) - WMA(i, period1);
                
        int y = 3;;
        double HMA[];
        ArrayResize(HMA,y);
        
for(i = 2; i >= 0; i--) HMA[i]  = iMAOnArray(vect, 0, p, 0, method, i);

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

double WMA(int x, int p) { return(iMA(NULL, 0, p, 0, method1, price1, x+sdvig1)); }

I really need it! Thank you! Thanks in advance! And sorry for the long message.

Files:
123.png  22 kb
 

I end up with 3 values vect[0], vect[1], vect[2]. But I need HMA values. HMA[0] is calculated but not correct. HMA[1] and HMA[2] are zero.

 
ilfat85:

I end up with 3 values vect[0], vect[1], vect[2]. But I need HMA values. HMA[0] is calculated but not correct. HMA[1] and HMA[2] are zero.

I think it was already discussed on this page... Have you tried contacting the author?
 
ilfat85:

Hi, Can you please advise me, I need to integrate Vinini_HMA indicator into an EA, I have managed to connect it and get data via resource and iCustom, but the testing has become very slow. Please advise how to make the indicator values are calculated in the EA itself, I need only one parameter for the last 3 candles.

Here is the code of the indicator:

I need to calculate the last 3 values that are in the bufferExtMapBuffer[i]. I am a beginner, do not judge severely. I tried to insert these code fragments into the Expert Advisor, but the values are calculated incorrectly

I really need them! Thank you! Thanks in advance! And sorry for the long message.

For the tester, do not connect a resource - it is slow (does not apply to this particular indicator, but to all - all resources are slow in the tester).

Connect simply through iCustom() from file location in its folder (not from resource)

 
STARIJ:
I think this has already been discussed on this page... Have you tried contacting the author?

Vitya very rarely appears here.

 
STARIJ:
I think it was already discussed on this page... Have you tried contacting the author?

There's a slightly different issue there, they get the values from the indicator, and I wanted the values to be calculated directly in the EA. The formulas seem to be simple, but I made a mistake somewhere. I have not contacted the author, I have not. Thanks for the tip, I will try to write to him.

 
Artyom Trishkin:

For the tester, don't connect a resource - it slows down (does not apply to this particular indicator, but to all - of the resources slow down in the tester).

Connect simply via iCustom() from file location in its folder (not from resource)


Thank you! Didn't know about this, I'll try it this way.

 

Hi. I'm making a bar chart based on the size of the candles. Help me know that the size of the first candle is the biggest of the last ten candles. The bar of the histogram should be marked somehow, by width or colour. Maybe you should also add a buffer.

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,limit = Bars-1;
//--- counting from 0 to rates_total
   

//--- the main loop of calculations
   for(i = limit; i >= 0; i--)
     {
      if (hl) ExtATRBuffer[i] = (iHigh(Symbol(),Period(),i) - iLow(Symbol(),Period(),i)); 
                        
      else    ExtATRBuffer[i] = MathAbs(iOpen(Symbol(),Period(),i) - iClose(Symbol(),Period(),i));
      
      if (ExtATRBuffer[i] < x) ExtATRBuffer[i] = 0;
    
    //
      
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
п
Reason: