//+------------------------------------------------------------------+ //| tangoline.mq4 | //| Copyright 2015, fxborg | //| http://blog.livedoor.jp/fxborg/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, fxborg" #property link "http://blog.livedoor.jp/fxborg/" #property version "1.02" #property strict #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 1 //--- plot Label1 #property indicator_label1 "TangoLine" #property indicator_width1 2 //--- input parameters input int InpPeriod=20; // Period input double MinSpread = 5; // Min Spread input color LineColor=DeepPink; // Line Color input color BandColor=DarkViolet; // Band Color //--- indicator buffers double LineBuffer[]; //---- for calc double HighesBuffer[]; double LowesBuffer[]; double HighBuffer[]; double LowBuffer[]; //--- int CalcBarCount=2; // Calc Bar Count //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { string short_name; //--- indicator buffers mapping IndicatorBuffers(5); SetIndexBuffer(0,LineBuffer); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,EMPTY,LineColor); //--- SetIndexBuffer(1,HighBuffer); SetIndexStyle(1,DRAW_LINE,STYLE_DOT,EMPTY,BandColor); //--- SetIndexBuffer(2,LowBuffer); SetIndexStyle(2,DRAW_LINE,STYLE_DOT,EMPTY,BandColor); //--- SetIndexBuffer(3,HighesBuffer); SetIndexBuffer(4,LowesBuffer); if(InpPeriod<2) { Alert("InpPeriod is too small."); return(INIT_FAILED); } //--- short_name="Tango Line("+IntegerToString(InpPeriod)+")"; IndicatorShortName(short_name); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| De-initialization | //+------------------------------------------------------------------+ int deinit() { string short_name="Tango Line("+IntegerToString(InpPeriod)+")"; IndicatorShortName(short_name); 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[]) { //--- int i,k,pos; //--- check for bars count if(rates_total<=InpPeriod) return(0); //--- counting from 0 to rates_total ArraySetAsSeries(HighesBuffer,false); ArraySetAsSeries(LowesBuffer,false); ArraySetAsSeries(HighBuffer,false); ArraySetAsSeries(LowBuffer,false); ArraySetAsSeries(LineBuffer,false); //--- ArraySetAsSeries(low,false); ArraySetAsSeries(high,false); //--- pos=InpPeriod-1; if(pos+1low[k]) dmin=low[k]; if(dmaxLowesBuffer[i-1] && LowesBuffer[i-1]==dmin) { top_bar=i-1; btm_bar=i-1; } if((HighesBuffer[i-2]+MinSpread*Point)i-InpPeriod+1) { //--- calculate range spread dmin=1000000.0; dmax=-1000000.0; //--- for(k=i-InpPeriod+1; k<=i; k++) { //--- if(k>=btm_bar) if(dmin>low[k]) dmin=low[k]; if(k>=top_bar) if(dmax