//------------------------------------------------------------------ #property copyright "© mladen, 2019" #property link "mladenfx@gmail.com" #property description "Perfect trend line" //------------------------------------------------------------------ #property indicator_chart_window #property indicator_buffers 9 #property indicator_plots 4 #property indicator_label1 "PTL trend candles" #property indicator_type1 DRAW_COLOR_CANDLES #property indicator_color1 clrDodgerBlue,clrCrimson #property indicator_label2 "PTL slow line" #property indicator_type2 DRAW_LINE #property indicator_style2 STYLE_DOT #property indicator_color2 clrDodgerBlue #property indicator_label3 "PTL fast line" #property indicator_type3 DRAW_LINE #property indicator_color3 clrCrimson #property indicator_style3 STYLE_DOT #property indicator_label4 "PTL trend start" #property indicator_type4 DRAW_COLOR_ARROW #property indicator_color4 clrDodgerBlue,clrCrimson #property indicator_width4 2 // // // input int inpFastLength = 3; // Fast length input int inpSlowLength = 7; // Slow length // // // double slowlu[],slowln[],fastln[],arrowar[],arrowcl[],candleo[],candleh[],candlel[],candlec[],candleC[]; int _fastPeriod,_slowPeriod; //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // int OnInit() { SetIndexBuffer( 0,candleo,INDICATOR_DATA); SetIndexBuffer( 1,candleh,INDICATOR_DATA); SetIndexBuffer( 2,candlel,INDICATOR_DATA); SetIndexBuffer( 3,candlec,INDICATOR_DATA); SetIndexBuffer( 4,candleC,INDICATOR_COLOR_INDEX); SetIndexBuffer( 5,slowln ,INDICATOR_DATA); SetIndexBuffer( 6,fastln ,INDICATOR_DATA); SetIndexBuffer( 7,arrowar,INDICATOR_DATA); SetIndexBuffer( 8,arrowcl,INDICATOR_COLOR_INDEX); _fastPeriod = MathMax(MathMin(inpFastLength,inpSlowLength),1); _slowPeriod = MathMax(MathMax(inpFastLength,inpSlowLength),1); // //--- // PlotIndexSetInteger(3,PLOT_ARROW,159); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { return; } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // 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[]) { struct sPtlStruct { datetime time; double fastHigh; double fastLow; double slowHigh; double slowLow; int trend; int trena; }; static sPtlStruct m_array[]; static int m_arraySize=-1; if (m_arraySizem_array[i].slowLow) ? m_array[i].slowLow : low[i]; double thighf = (high[i]m_array[i].fastLow) ? m_array[i].fastLow : low[i]; // // // m_array[i].trend = -1; if (i>0) { m_array[i].trena = m_array[i-1].trena; slowln[i] = (close[i]>slowln[i-1]) ? tlows : thighs; fastln[i] = (close[i]>fastln[i-1]) ? tlowf : thighf; if (close[i]slowln[i] && close[i]>fastln[i]) m_array[i].trend = 0; if (slowln[i]>fastln[i] || m_array[i].trend == 1) m_array[i].trena = 1; if (slowln[i]