Download MetaTrader 5
To add comments, please log in or register
Any questions regarding MQL5 Cloud Network? FAQ will help you!
app-trader
9
app-trader 2015.03.02 20:38 

Hi,

 I coded my first indicator. I am trying to show the 2 values of the indicator in one seperate values with 2 separate lines. but only the first line is drawn. The 2nd Buffer contains the correct values and one can see the values in the data window. just the line is not drawn.

I guess there is a very easy solution, but since it is my first own code I can't find the problem 

 Please help me out. thanks! 

 

//+------------------------------------------------------------------+
//|                                                       RevBar.mq4 |
//|                                       Copyright 2015, App-Trader |
//|                                         http://www.app-trader.de |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, App-Trader"
#property link      "http://www.app-trader.de"
#property version   "1.00"
#property strict

//Indicator Settings
#property indicator_separate_window
#property indicator_minimum    -10
#property indicator_maximum    10
#property indicator_buffers    2
#property indicator_color1     LightSeaGreen
#property indicator_color2     Red


//---- User Inputs
//How many pips shall the revbar low be below the low before and vice versa
input int PipsDelta = 10;


//Buffers
double         ExtRevBarBuffer[];
double         ExtBarsBeforeOpp[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  
//--- indicator lines
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0, ExtRevBarBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1, ExtBarsBeforeOpp);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("RevBar");
   SetIndexLabel(0,"RevBar");
   SetIndexLabel(1,"Signal");
//---
   SetIndexDrawBegin(0,200);
   SetIndexDrawBegin(1,200);
//--- initialization done
   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[])
  {
//---
   int    i,ii,limit=rates_total-prev_calculated;
   
   for(i=0; i < limit-1; i++)
   {
      if(close[i+1] < open[i+1]) //bar1 down?
      {
         //RevBar Up check
         if(low[i] < low[i+1]-PipsDelta*Point && close[i] > open[i])
         {
            //RevBar Up
            ExtRevBarBuffer[i]=1;
            ExtBarsBeforeOpp[i]=1;
            
            
            for(ii=2; ii < limit-2; ii++)
            {
               if(close[i+ii] < open[i+ii])
               {
                  ExtBarsBeforeOpp[i]=ii;
               }
               else
               {
                  ii = limit-2;
               }
            }
            
         }
         else
         {
            ExtRevBarBuffer[i]=0;
         }
         
         
      }
      else
      {
         //revbar down check
         if(high[i] > high[i+1]+PipsDelta*Point && close[i] < open[i])
         {
            //RevBar Down
            ExtRevBarBuffer[i]=-1;
         }
         else
         {
            ExtRevBarBuffer[i]=0;
         }
      }
   }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Snelle Moda
602
Snelle Moda 2015.03.03 10:41  
app-trader:

Hi,

 I coded my first indicator. I am trying to show the 2 values of the indicator in one seperate values with 2 separate lines. but only the first line is drawn. The 2nd Buffer contains the correct values and one can see the values in the data window. just the line is not drawn.

I guess there is a very easy solution, but since it is my first own code I can't find the problem 

 Please help me out. thanks! 

 

Hi


You also need to define the number of indicator plots and line types, see this example.

I think this will solve your problem.

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2

#property indicator_type1   DRAW_LINE
#property indicator_color1  clrAqua
#property indicator_style1  STYLE_DASHDOTDOT
#property indicator_width1  1
#property indicator_label1  "USD"

#property indicator_type2   DRAW_LINE
#property indicator_color2  clrYellow
#property indicator_style2  STYLE_DASHDOTDOT
#property indicator_width2  1
#property indicator_label2  "EUR"
/
To add comments, please log in or register