Download MetaTrader 5

Code Not working: Line connecting 2 different close prices

To add comments, please log in or register
therustytrader
457
therustytrader  

I am trying to have a line connect the close value every quarter hour on a 1 minute chart. The line shows on 15 minute charts and above but not on the 1 minute chart.

Below is the code I use.  I believe the problem may be in the section labeled //Block for calculating indicator values.

I have also tried this and it just gives me a crazy line going everywhere:

//--- Block for calculating indicator values
   int k=0;
   for(int i=0;i<rates_total;i++)

     {
       if(TimeMinute(Time[i])==00 || TimeMinute(Time[i])==15 || TimeMinute(Time[i])==30 || TimeMinute(Time[i])==45)
         {
           LineBuffer[k]=close[i];
           k++;
         }
     }


#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- Line properties are set using the compiler directives
#property indicator_label1  "Line"      // Name of a plot for the Data Window
#property indicator_type1   DRAW_LINE   // Type of plotting is line
#property indicator_color1  clrRed      // Line color
#property indicator_style1  STYLE_SOLID // Line style
#property indicator_width1  1           // Line Width

//--- An indicator buffer for the plot
double         LineBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Binding an array and an indicator buffer
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
//---
   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[])
  {

//--- Block for calculating indicator values
   for(int i=0;i<rates_total;i++)
     {
       if(TimeMinute(Time[i])==00 || TimeMinute(Time[i])==15 || TimeMinute(Time[i])==30 || TimeMinute(Time[i])==45)
         {     
            LineBuffer[i]=close[i];
         }
     }
 
//--- Return the prev_calculated value for the next call of the function
   return(rates_total);
  }
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
Language Basics / Functions / Event Handling Functions - Reference on algorithmic/automated trading language for MetaTrader 5
therustytrader
457
therustytrader  
Code is fixed,  I just needed to use DRAW_SECTION instead of DRAW_LINE
To add comments, please log in or register