Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+------------------------------------------------------------------+
- //| Hi-LO.mq5 |
- //| Copyright 2018, MetaQuotes Software Corp. |
- //| https://www.mql5.com |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2018, MetaQuotes Software Corp."
- #property link "https://www.mql5.com"
- #property version "1.00"
- #property indicator_chart_window
- #property indicator_buffers 3
- #property indicator_plots 3
- //--- plot Media
- #property indicator_label1 "Media"
- #property indicator_type1 DRAW_LINE
- #property indicator_color1 clrOrange
- #property indicator_style1 STYLE_SOLID
- #property indicator_width1 2
- //--- plot Venda
- #property indicator_label2 "Venda"
- #property indicator_type2 DRAW_ARROW
- #property indicator_color2 clrRed
- #property indicator_style2 STYLE_SOLID
- #property indicator_width2 1
- //--- plot Compra
- #property indicator_label3 "Compra"
- #property indicator_type3 DRAW_ARROW
- #property indicator_color3 clrBlue
- #property indicator_style3 STYLE_SOLID
- #property indicator_width3 1
- //--- input parameters
- input int Periodos=34;
- //--- indicator buffers
- double MediaBuffer[];
- double VendaBuffer[];
- double CompraBuffer[];
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //--- indicator buffers mapping
- SetIndexBuffer(0,MediaBuffer,INDICATOR_DATA);
- SetIndexBuffer(1,VendaBuffer,INDICATOR_DATA);
- SetIndexBuffer(2,CompraBuffer,INDICATOR_DATA);
- PlotIndexSetInteger(1,PLOT_ARROW,234);
- PlotIndexSetInteger(2,PLOT_ARROW,233);
- PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,0);
- PlotIndexSetInteger(2,PLOT_ARROW_SHIFT,0);
- //---
- 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,Periodos,0,MODE_EMA,PRICE_CLOSE),0,0,rates_total,MediaBuffer);
- for(int i=Periodos; i<rates_total;i++)
- {
- if(open[i]>MediaBuffer[i] && close[i]>high[i-1])
- {
- CompraBuffer[i]=high[i-1];
- }
- else if(open[i]<MediaBuffer[i] && close[i]<low[i-1])
- {
- VendaBuffer[i]=low[i-1];
- }
- else
- {
- VendaBuffer[i]=0;
- CompraBuffer[i]=0;
- }
- }
- //--- return value of prev_calculated for next call
- return(rates_total);
- }
- //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement