Straight Moving average

 

Hello !!


There is some indicator that draws straight lines  every n bars ???


Thanks for your help.


Straight moving average

 
Nobody ??
 
angevoyageur: I recommend to all not answer such thing that "use google or use this and you will have found this", it's absolutely not useful. Ignore it.
Ignoring post per https://www.mql5.com/en/forum/155059/page2#1010252
 
Great forum !!!


Congratulations.

 
lol...I think you missed my point.
 
CROM:
Great forum !!!


Congratulations.


A lot of people find this form useful, but they ask sensible questions.

You may as well ask "Is there an indicator that draws wiggly lines on a chart?"

You show an example chart image that has random length lines, apparently placed randomly with no explanation.

I don't know of any such indicator. 

 
GumRai:

A lot of people find this form useful, but they ask sensible questions.

You may as well ask "Is there an indicator that draws wiggly lines on a chart?"

You show an example chart image that has random length lines, apparently placed randomly with no explanation.

I don't know of any such indicator. 


Sorry, I believe that this forum  was like another mlq4 forums ( for example .ru ) more dynamic and interactive where you can do a lot of type of "sensible" questions. Thanks for your replies... I found the answer of my question...

https://www.mql5.com/en/docs/customind/indicators_examples/draw_section

Best regards..

 

Anyone can say me why this indicator not draws correctly ??



//+------------------------------------------------------------------+
//|                                                 DRAW_SECTION.mq4 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                             https://www.mql4.com |
//+------------------------------------------------------------------+

 
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Section

#property indicator_type1   DRAW_SECTION
#property indicator_color1  clrAqua
#property indicator_style1  STYLE_SOLID
#property indicator_width1  3
//--- input parameter
input int      bars=2;           // The length of sections in bars

//--- An indicator buffer for the plot
double         SectionBuffer[];
//--- An auxiliary variable to calculate ends of sections
int            divider;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Binding an array and an indicator buffer
   SetIndexBuffer(0,SectionBuffer,INDICATOR_DATA);
//--- The 0 (empty) value will mot participate in drawing
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//--- Check the indicator parameter
   if(bars<=0)
     {
      PrintFormat("Invalid value of parameter bar=%d",bars);
      return(INIT_PARAMETERS_INCORRECT);
     }
   else divider=2*bars;
//---+
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
   static int ticks=0;
//--- Calculate ticks to change the style, color and width of the line
   ticks++;
//--- If a critical number of ticks has been accumulated
 
     {
     
      //--- Reset the counter of ticks to zero
      ticks=0;
     }
 
//--- The number of the bar from which the calculation of indicator values starts
   int start=0;
//--- If the indicator has been calculated before, then set start on the previous bar
   if(prev_calculated>0) start=prev_calculated-1;
//--- Here are all the calculations of the indicator values
   for(int i=start;i<rates_total;i++)
     {
      //--- Get a remainder of the division of the bar number by 2*bars
      int rest=i%divider;
      //--- If the bar number is divisible by 2*bars
      if(rest==0)
        {
         //--- Set the end of the section at the High price of this bar
         SectionBuffer[i]=Close[i];
        }
      //---If the remainder of the division is equal to bars, 
      else
        {
         //--- Set the end of the section at the High price of this bar
         if(rest==bars) SectionBuffer[i]= Close[i];
         //--- If nothing happened, ignore the bar - set 0
         else SectionBuffer[i]=EMPTY_VALUE;;
        }
     }
//--- Return the prev_calculated value for the next call of the function
   return(rates_total);
  }

Thanks for your attention..

 
//#property indicator_type1   DRAW_LINE
#property indicator_type1   DRAW_SECTION

I believe that you want to draw sections, not lines 

   //PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);

 I don't think that this is supported in mq4

         //else SectionBuffer[i]=0;
         else SectionBuffer[i]=EMPTY_VALUE;

 by using zero, lines will be drawn from zero, use EMPTY_VALUE

 Not tested

 

Works perfectly !!!

Really , really thanks.

 
Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it.