// volume e media a 20 periodi sul volume //------------------------------------------------------------------ #property copyright "© mladen, 2018" #property link "mladenfx@gmail.com" #property version "1.00" //------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 2 #property indicator_label1 "Volume" #property indicator_type1 DRAW_COLOR_HISTOGRAM #property indicator_color1 clrRed,clrGreen #property indicator_width1 2 #property indicator_label2 "Average" #property indicator_type2 DRAW_LINE #property indicator_color2 clrDarkGray //--- input parameters input int inpAveragePeriod = 20; // Average period input double inpBreakoutPercent = 50; // Breakout percentage //--- buffers double val[],valc[],average[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- indicator buffers mapping SetIndexBuffer(0,val,INDICATOR_DATA); SetIndexBuffer(1,valc,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,average,INDICATOR_DATA); IndicatorSetString(INDICATOR_SHORTNAME,"Volume SMA average ("+(string)inpAveragePeriod+")"); } //+------------------------------------------------------------------+ //| 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[]) { if(Bars(_Symbol,_Period)=average[i]){ valc[i] = 1; }else{ valc[i] = 0; } //if(i>0 && close[i] > close[i-1]) valc[i] = (_volume > average[i]*(1+inpBreakoutPercent*0.01)) ? 3 : 1; //if(i>0 && close[i] < close[i-1]) valc[i] = (_volume > average[i]*(1+inpBreakoutPercent*0.01)) ? 4 : 2; } return(i); } //+------------------------------------------------------------------+ //| Custom functions | //+------------------------------------------------------------------+ #define _maInstances 1 #define _maWorkBufferx1 1*_maInstances double workSma[][_maWorkBufferx1]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double iSma(double price,int period,int r,int _bars,int instanceNo=0){ if(ArrayRange(workSma,0)!=_bars) ArrayResize(workSma,_bars); workSma[r][instanceNo]=price; double avg=price; int k=1; for(; k=0; k++) avg+=workSma[r-k][instanceNo]; return(avg/(double)k); }