Skip to content

Instantly share code, notes, and snippets.

@sidneylimafilho
Created September 2, 2019 16:22
Show Gist options
  • Save sidneylimafilho/e27815aab25ab5bef97b6fce3ad23ee7 to your computer and use it in GitHub Desktop.
Save sidneylimafilho/e27815aab25ab5bef97b6fce3ad23ee7 to your computer and use it in GitHub Desktop.
//+------------------------------------------------------------------+
//| cand_color.mq5 |
//| ProF |
//| http:// |
//+------------------------------------------------------------------+
#property copyright "Bere" //Author
#property indicator_chart_window //Indicator in separate window
//Specify the number of buffers of the indicator
//4 buffer for candles + 1 color buffer + 1 buffer to serve the RSI data
#property indicator_buffers 6
//Specify the names in the Data Window
//#property indicator_label1 "Open;High;Low;Close"
#property indicator_plots 1 //Number of graphic plots
#property indicator_type1 DRAW_COLOR_CANDLES //Drawing style - color candles
#property indicator_width1 3 //Width of the graphic plot (optional)
#property indicator_color1 Crimson,SeaGreen,DarkRed,YellowGreen,Coral,Orange,Black
//Declaration of buffers
double buffer_open[],buffer_high[],buffer_low[],buffer_close[]; //Buffers for data
double buffer_color_line[]; //Buffer for color indexes
double buffer_tmp[1]; //Temporary buffer for RSI data copying
int chart_id=1;
int gain=0,stop=0,draw=0,entrada=0;
double tops[],floors[];
string direction="";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
/**
* The order of the buffers assign is VERY IMPORTANT!
* The data buffers are first
* The color buffers are next
* And finally, the buffers for the internal calculations.
*/
//Assign the arrays with the indicator's buffers
SetIndexBuffer(0,buffer_open,INDICATOR_DATA);
SetIndexBuffer(1,buffer_high,INDICATOR_DATA);
SetIndexBuffer(2,buffer_low,INDICATOR_DATA);
SetIndexBuffer(3,buffer_close,INDICATOR_DATA);
//Assign the array with color indexes with the indicator's color indexes buffer
SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX);
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
Comment("Metodo SIDNEY");
//In the loop we fill the data buffers and color indexes buffers for each bar
for(int i=prev_calculated;i<=rates_total-1;i++)
if(i>0)
{
//Set data for plotting
buffer_open[i]=open[i]; //Open price
buffer_high[i]=high[i]; //High price
buffer_low[i]=low[i]; //Low price
buffer_close[i]=close[i];//Close price
// set default colors
buffer_color_line[i]=open[i]<close[i]?1:0;
string label="";
// INSIDE BAR
if(high[i]<high[i-1] && low[i]>low[i-1] && buffer_color_line[i]!=buffer_color_line[i-1])
{
buffer_color_line[i]=5;
}
}
return(rates_total-1); //Return the number of calculated bars,
//Subtract 1 for the last bar recalculation
}
return(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment