Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 25

 

Цикл от самого "старого" бара к самому "свежему": 

    for (int i = limit; i >= 0; i--);
 

Modified the indicator slightly. It counts correctly up to the decimal point. For example, on one section the indicator should be 11, but it shows 11.58.

What may be wrong?

I made vniz_1, vniz_2 be greater than zero. I have created gaps in the indicator line. How to connect the gaps and colour them differently, but not to calculate the indicator in these gaps.

//+------------------------------------------------------------------+
//|                                                         сила.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//--- input parameters
extern int       Period_MA_1=7;
extern int       Period_MA_2=7;
extern int       Period_MA_3=7;
//--- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int counted_bars=IndicatorCounted(),                      
    limit;
    double
    vniz_1,
    vniz_2,
    MA_1_t,                         
    MA_2_t,                           
    MA_3_t;
 
   if(counted_bars>0)
      counted_bars--;
   
   limit=Bars-counted_bars;
   
   
   for(int i=0;i<limit;i++)
   {
      MA_1_t=iMA(NULL,0,Period_MA_1,0,MODE_EMA,PRICE_CLOSE,i+1);  
      MA_2_t=iMA(NULL,0,Period_MA_2,0,MODE_EMA,PRICE_CLOSE,i+2);  
      MA_3_t=iMA(NULL,0,Period_MA_3,0,MODE_EMA,PRICE_CLOSE,i+3);    
      vniz_1=(MA_3_t-MA_2_t);
      vniz_2=(MA_2_t-MA_1_t);
      if (vniz_1>0&&vniz_2>0)
      {
      ExtMapBuffer1[i]=(vniz_1/vniz_2);
      }
   }
   return(0);
  }
//+------------------------------------------------------------------+
 
Forexman77:

Modified the indicator slightly. It counts correctly up to the decimal point. For example, on one section the indicator should be 11, but it shows 11.58.

What may be wrong?

I made vniz_1, vniz_2 be greater than zero. I have created gaps in the indicator line. How to connect the gaps and colour them differently, but not to calculate the indicator in these gaps.


      MA_1_t=iMA(NULL,0,Period_MA_1,0,MODE_EMA,PRICE_CLOSE,i+1);  
      MA_2_t=iMA(NULL,0,Period_MA_2,0,MODE_EMA,PRICE_CLOSE,i+2);  
      MA_3_t=iMA(NULL,0,Period_MA_3,0,MODE_EMA,PRICE_CLOSE,i+3); 
Calculate the indicator on non-existent bars ?????
 
      if (vniz_1<0 || vniz_2<0)
      {
      ExtMapBuffer2[i]=(чему равны разрывы);
      }
 
What is 2013.07.07 16:06:21 2010.02.01 01:56 EURUSD,H1: Error in opening a EURUSD sell order Array index - out of range
??????
 
Below is the code of a simple indicator which draws a Horizontal line for all bars.
How can I fix it so that the line is drawn only for the last 20 bars?




#property indicator_separate_window
#property indicator_buffers 1

#property indicator_color1 Chocolate
#property indicator_width1 6

#property indicator_minimum -0.1
#property indicator_maximum  0.1


double ExtMapBuffer[];



int init() {

   IndicatorBuffers(1);
   IndicatorDigits(   Digits+2);
   IndicatorShortName("H_LINE");

   SetIndexLabel(    0, "H_LINE");
   SetIndexDrawBegin(0, 0);
   SetIndexStyle(    0, DRAW_LINE);
   SetIndexBuffer(   0, ExtMapBuffer);

   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexShift(     0, 0);

   return(0);
}




int start()  {

   int limit;
   int counted_bars=IndicatorCounted();

   if(counted_bars>0) {
      counted_bars--;
   }

   limit=Bars-counted_bars;


   for(int i=0; i<limit; i++) {   
      ExtMapBuffer[i] = 0;
   }


   return(0);
}
 
atztek:
Below is the code of a simple indicator which draws a Horizontal line for all bars.
How can I fix it so that the line is drawn only for the last 20 bars?






What should the line be equal to?
 
Vinin:

What should the line be equal to?

The size of the line on the Y-axis in this case does not matter, this is just an example based on which I want to understand how to properly limit "drawing" by indicators to a certain number of bars.
 
atztek:

The size of the line on the Y-axis does not matter in this case, this is just an example based on which I want to understand how to limit "drawing" by indicators to a certain number of bars.

Do you want to use indicator buffers or objects?
 
Vinin:
Do you want to use indicator buffers or objects?

Indicator buffers, as in the future the solution will be used not only for straight lines, but also for moving average and other types of lines.
Reason: