Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+------------------------------------------------------------------+
- //| bbema.mq5 |
- //| Copyright 2020, MetaQuotes Software Corp. |
- //| https://www.mql5.com |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2020, MetaQuotes Software Corp."
- #property link "https://www.mql5.com"
- #property version "1.00"
- #property indicator_chart_window
- #property indicator_buffers 7
- #property indicator_plots 7
- //--- plot call
- #property indicator_label1 "call"
- #property indicator_type1 DRAW_ARROW
- #property indicator_color1 clrLightSkyBlue
- #property indicator_style1 STYLE_SOLID
- #property indicator_width1 10
- //--- plot put
- #property indicator_label2 "put"
- #property indicator_type2 DRAW_ARROW
- #property indicator_color2 clrOrchid
- #property indicator_style2 STYLE_SOLID
- #property indicator_width2 10
- //--- plot signal
- #property indicator_label3 "signal"
- #property indicator_type3 DRAW_ARROW
- #property indicator_color3 clrPurple
- #property indicator_style3 STYLE_SOLID
- #property indicator_width3 10
- //--- plot ema
- #property indicator_label4 "ema"
- #property indicator_type4 DRAW_LINE
- #property indicator_color4 clrHotPink
- #property indicator_style4 STYLE_SOLID
- #property indicator_width4 1
- //--- plot upper
- #property indicator_label5 "upper"
- #property indicator_type5 DRAW_LINE
- #property indicator_color5 clrRed
- #property indicator_style5 STYLE_SOLID
- #property indicator_width5 1
- //--- plot mid
- #property indicator_label6 "mid"
- #property indicator_type6 DRAW_LINE
- #property indicator_color6 clrWhite
- #property indicator_style6 STYLE_SOLID
- #property indicator_width6 1
- //--- plot lower
- #property indicator_label7 "lower"
- #property indicator_type7 DRAW_LINE
- #property indicator_color7 clrPaleGreen
- #property indicator_style7 STYLE_SOLID
- #property indicator_width7 1
- //--- input parameters
- input int Input1;
- input int Input2;
- //--- indicator buffers
- double callBuffer[];
- double putBuffer[];
- double signalBuffer[];
- double emaBuffer[];
- double upperBuffer[];
- double midBuffer[];
- double lowerBuffer[];
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //--- indicator buffers mapping
- SetIndexBuffer(0,callBuffer,INDICATOR_DATA);
- SetIndexBuffer(1,putBuffer,INDICATOR_DATA);
- SetIndexBuffer(2,signalBuffer,INDICATOR_DATA);
- SetIndexBuffer(3,emaBuffer,INDICATOR_DATA);
- SetIndexBuffer(4,upperBuffer,INDICATOR_DATA);
- SetIndexBuffer(5,midBuffer,INDICATOR_DATA);
- SetIndexBuffer(6,lowerBuffer,INDICATOR_DATA);
- //--- setting a code from the Wingdings charset as the property of PLOT_ARROW
- PlotIndexSetInteger(0,PLOT_ARROW,159);
- PlotIndexSetInteger(1,PLOT_ARROW,159);
- PlotIndexSetInteger(2,PLOT_ARROW,159);
- //---
- 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[])
- {
- //---
- CopyBuffer(iMA(_Symbol,_Period,100,0,MODE_EMA,PRICE_OPEN) ,0,0,rates_total, emaBuffer);
- //CopyBuffer(iBands(_Symbol,_Period,20,0,2.5,PRICE_OPEN),0,0,rates_total, midBuffer);
- CopyBuffer(iBands(_Symbol,_Period,20,0,2.5,PRICE_CLOSE),1,0,rates_total, upperBuffer);
- CopyBuffer(iBands(_Symbol,_Period,20,0,2.5,PRICE_CLOSE),2,0,rates_total, lowerBuffer);
- for(int i=1; i<rates_total; i++){
- if(emaBuffer[i]>upperBuffer[i]){
- putBuffer[i]= high[i] >= upperBuffer[i] ? high[i] : 0;
- }
- else{
- putBuffer[i]=0;
- }
- if(emaBuffer[i]<lowerBuffer[i]){
- callBuffer[i]= low[i] <= lowerBuffer[i] ? low[i] : 0;
- }
- else{
- callBuffer[i]=0;
- }
- }
- //--- return value of prev_calculated for next call
- return(rates_total);
- }
- //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement