#property copyright "copyleft mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 6 #property indicator_color1 clrLimeGreen #property indicator_color2 clrGreen #property indicator_color3 clrRed #property indicator_color4 clrMaroon #property indicator_color5 clrGold #property indicator_color6 clrGreen #property indicator_width1 2 #property indicator_width2 1 #property indicator_width3 2 #property indicator_width4 1 #property indicator_width5 2 #property indicator_width6 2 #property strict // // // enum enPrices { pr_close, // Close pr_open, // Open pr_high, // High pr_low, // Low pr_median, // Median pr_typical, // Typical pr_weighted, // Weighted pr_average, // Average (high+low+open+close)/4 pr_medianb, // Average median body (open+close)/2 pr_tbiased, // Trend biased price pr_highlow, // High/low pr_tbiased2, // Trend biased (extreme) price pr_haclose, // Heiken ashi close pr_haopen , // Heiken ashi open pr_hahigh, // Heiken ashi high pr_halow, // Heiken ashi low pr_hamedian, // Heiken ashi median pr_hatypical, // Heiken ashi typical pr_haweighted, // Heiken ashi weighted pr_haaverage, // Heiken ashi average pr_hamedianb, // Heiken ashi median body pr_hatbiased, // Heiken ashi trend biased price pr_hatbiased2, // Heiken ashi trend biased (extreme) price pr_hahighlow // Heiken ashi high/low }; input int T3FastPeriod = 20; // T3 fast period input enPrices T3FastPrice = pr_close; // T3 fast Price to use input double T3FastHot = 1.2; // T3 fast hot input bool T3FastOriginal = false; // T3 fast original input int T3SlowPeriod = 35; // T3 slow period input enPrices T3SlowPrice = pr_close; // T3 slow price to use input double T3SlowHot = 1.2; // T3 slow hot input bool T3SlowOriginal = false; // T3 slow original input bool arrowsVisible = false; // Arrows visible? input string arrowsIdentifier = "trix A1"; // Unique ID for arrows input double arrowsUpperGap = 1.0; // Upper arrow gap input double arrowsLowerGap = 1.0; // Lower arrow gap input color arrowsUpColor = clrBlue; // Up arrow color input color arrowsDnColor = clrCrimson; // Down arrow color input int arrowsUpCode = 108; // Up arrow code input int arrowsDnCode = 108; // Down arrow code input int arrowsUpSize = 2; // Up arrow size input int arrowsDnSize = 2; // Down arrow size double t3fCross[],t3sCross[],huu[],hud[],hdd[],hdu[],val[],valc[],valt[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(9); SetIndexBuffer(0, huu, INDICATOR_DATA); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(1, hud, INDICATOR_DATA); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexBuffer(2, hdd, INDICATOR_DATA); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexBuffer(3, hdu, INDICATOR_DATA); SetIndexStyle(3,DRAW_HISTOGRAM); SetIndexBuffer(4, t3fCross,INDICATOR_DATA); SetIndexStyle(4,DRAW_LINE); SetIndexBuffer(5, t3sCross,INDICATOR_DATA); SetIndexStyle(5,DRAW_LINE); SetIndexBuffer(6, val, INDICATOR_CALCULATIONS); SetIndexBuffer(7, valc,INDICATOR_CALCULATIONS); SetIndexBuffer(8, valt,INDICATOR_CALCULATIONS); IndicatorSetString(INDICATOR_SHORTNAME,"T3 Trix histo"); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectsDeleteAll(0,arrowsIdentifier+":"); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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,r,limit=fmin(rates_total-prev_calculated+1,rates_total-1); // // // struct sWork { double fast; double slow; }; static sWork wrk[]; static int wrkSize=-1; if (wrkSize=0;i--,r++) { double fprc = getPrice(T3FastPrice,open,close,high,low,i,rates_total,0); double sprc = getPrice(T3SlowPrice,open,close,high,low,i,rates_total,1); wrk[r].fast = iT3(fprc,T3FastPeriod,T3FastHot,T3FastOriginal,i,rates_total,0); wrk[r].slow = iT3(sprc,T3SlowPeriod,T3SlowHot,T3SlowOriginal,i,rates_total,1); t3fCross[i] = (r>0) ? wrk[r].fast-wrk[r-1].fast : 0; t3sCross[i] = (r>0) ? wrk[r].slow-wrk[r-1].slow : 0; val[i] = t3fCross[i]-t3sCross[i]; valc[i] = (r>0) ? (val[i]>0) ? (val[i]>val[i+1]) ? 0 : 1 : (val[i]0) ? (val[i]>0) ? 1 : (val[i]<0) ? -1 : valt[i+1] : 0; huu[i] = (valc[i] == 0) ? val[i] : EMPTY_VALUE; hud[i] = (valc[i] == 1) ? val[i] : EMPTY_VALUE; hdd[i] = (valc[i] == 2) ? val[i] : EMPTY_VALUE; hdu[i] = (valc[i] == 3) ? val[i] : EMPTY_VALUE; // // // if (arrowsVisible) { string lookFor = arrowsIdentifier+":"+(string)time[i]; ObjectDelete(lookFor); if (r>0 && valt[i] != valt[i+1]) { if (valt[i] == 1) drawArrow(i,arrowsUpColor,arrowsUpCode,arrowsUpSize,false); if (valt[i] ==-1) drawArrow(i,arrowsDnColor,arrowsDnCode,arrowsDnSize, true); } } } return(rates_total); } //------------------------------------------------------------------- // //------------------------------------------------------------------- void drawArrow(int i,color theColor,int theCode, int theSize, bool up) { string name = arrowsIdentifier+":"+(string)Time[i]; double gap = iATR(_Symbol,_Period,20,i); // // // datetime atime = Time[i]; //if (arrowsOnNewest) atime += PeriodSeconds(_Period)-1; ObjectCreate(0,name,OBJ_ARROW,0,atime,0); ObjectSetInteger(0,name,OBJPROP_ARROWCODE,theCode); ObjectSetInteger(0,name,OBJPROP_WIDTH, theSize); ObjectSetInteger(0,name,OBJPROP_COLOR, theColor); if (up) ObjectSetDouble(0,name,OBJPROP_PRICE1,0,High[i] + arrowsUpperGap * gap); else ObjectSetDouble(0,name,OBJPROP_PRICE1,0,Low[i] - arrowsLowerGap * gap); } //------------------------------------------------------------------ // //------------------------------------------------------------------ #define t3Instances 2 double workT3[][t3Instances*6]; double workT3Coeffs[][6]; #define _tperiod 0 #define _c1 1 #define _c2 2 #define _c3 3 #define _c4 4 #define _alpha 5 // // // // // double iT3(double price, double period, double hot, bool original, int i, int bars, int tinstanceNo=0) { if (ArrayRange(workT3,0) != bars) ArrayResize(workT3,bars); if (ArrayRange(workT3Coeffs,0) < (tinstanceNo+1)) ArrayResize(workT3Coeffs,tinstanceNo+1); if (workT3Coeffs[tinstanceNo][_tperiod] != period) { workT3Coeffs[tinstanceNo][_tperiod] = period; double a = hot; workT3Coeffs[tinstanceNo][_c1] = -a*a*a; workT3Coeffs[tinstanceNo][_c2] = 3*a*a+3*a*a*a; workT3Coeffs[tinstanceNo][_c3] = -6*a*a-3*a-3*a*a*a; workT3Coeffs[tinstanceNo][_c4] = 1+3*a+a*a*a+3*a*a; if (original) workT3Coeffs[tinstanceNo][_alpha] = 2.0/(1.0 + period); else workT3Coeffs[tinstanceNo][_alpha] = 2.0/(2.0 + (period-1.0)/2.0); } // // // // // int instanceNo = tinstanceNo*6; int r = bars-i-1; if (r == 0) { workT3[r][0+instanceNo] = price; workT3[r][1+instanceNo] = price; workT3[r][2+instanceNo] = price; workT3[r][3+instanceNo] = price; workT3[r][4+instanceNo] = price; workT3[r][5+instanceNo] = price; } else { workT3[r][0+instanceNo] = workT3[r-1][0+instanceNo]+workT3Coeffs[tinstanceNo][_alpha]*(price -workT3[r-1][0+instanceNo]); workT3[r][1+instanceNo] = workT3[r-1][1+instanceNo]+workT3Coeffs[tinstanceNo][_alpha]*(workT3[r][0+instanceNo]-workT3[r-1][1+instanceNo]); workT3[r][2+instanceNo] = workT3[r-1][2+instanceNo]+workT3Coeffs[tinstanceNo][_alpha]*(workT3[r][1+instanceNo]-workT3[r-1][2+instanceNo]); workT3[r][3+instanceNo] = workT3[r-1][3+instanceNo]+workT3Coeffs[tinstanceNo][_alpha]*(workT3[r][2+instanceNo]-workT3[r-1][3+instanceNo]); workT3[r][4+instanceNo] = workT3[r-1][4+instanceNo]+workT3Coeffs[tinstanceNo][_alpha]*(workT3[r][3+instanceNo]-workT3[r-1][4+instanceNo]); workT3[r][5+instanceNo] = workT3[r-1][5+instanceNo]+workT3Coeffs[tinstanceNo][_alpha]*(workT3[r][4+instanceNo]-workT3[r-1][5+instanceNo]); } // // // // // return(workT3Coeffs[tinstanceNo][_c1]*workT3[r][5+instanceNo] + workT3Coeffs[tinstanceNo][_c2]*workT3[r][4+instanceNo] + workT3Coeffs[tinstanceNo][_c3]*workT3[r][3+instanceNo] + workT3Coeffs[tinstanceNo][_c4]*workT3[r][2+instanceNo]); } //------------------------------------------------------------------ // //------------------------------------------------------------------ #define priceInstances 2 double workHa[][priceInstances*4]; double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars,int instanceNo=0) { if (tprice>=pr_haclose) { if (ArrayRange(workHa,0)!= bars) ArrayResize(workHa,bars); instanceNo*=4; int r = bars-i-1; // // // // // double haOpen; if (r>0) haOpen = (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0; else haOpen = (open[i]+close[i])/2; double haClose = (open[i] + high[i] + low[i] + close[i]) / 4.0; double haHigh = fmax(high[i],fmax(haOpen,haClose)); double haLow = fmin(low[i] ,fmin(haOpen,haClose)); if(haOpenhaOpen) return((haHigh+haClose)/2.0); else return((haLow+haClose)/2.0); case pr_hatbiased2: if (haClose>haOpen) return(haHigh); if (haCloseopen[i]) return((high[i]+close[i])/2.0); else return((low[i]+close[i])/2.0); case pr_tbiased2: if (close[i]>open[i]) return(high[i]); if (close[i]