#property copyright "www.forex-station.com" #property link "www.forex-station.com" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 clrDodgerBlue #property indicator_color2 clrDeepPink #property indicator_color3 clrDeepPink #property indicator_width1 3 #property indicator_width2 3 #property indicator_width3 3 #property indicator_level1 -100 #property indicator_level2 100 #property indicator_level3 0 #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_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_habclose, // Heiken ashi (better formula) close pr_habopen , // Heiken ashi (better formula) open pr_habhigh, // Heiken ashi (better formula) high pr_hablow, // Heiken ashi (better formula) low pr_habmedian, // Heiken ashi (better formula) median pr_habtypical, // Heiken ashi (better formula) typical pr_habweighted,// Heiken ashi (better formula) weighted pr_habaverage, // Heiken ashi (better formula) average pr_habmedianb, // Heiken ashi (better formula) median body pr_habtbiased, // Heiken ashi (better formula) trend biased price pr_habtbiased2 // Heiken ashi (better formula) trend biased (extreme) price }; input int inpCciPeriod = 200; // CCI period input int inpSmoothPeriod = 4; // Smoothing period input double inpSmoothPhase = 0.0; // Smoothing phase input enPrices inpPrice = pr_close; // Jma cci Price input bool arrowsVisible = true; // Show arrows on/off input string arrowsIdentifier = "jmacci Arrows1"; // Arrows unique ID input double arrowsUpperGap = 0.5; // Arrows upper gap input double arrowsLowerGap = 0.5; // Arrows lower gap input color arrowsUpColor = clrLime; // Up arrow color input color arrowsDnColor = clrMagenta; // Down arrow color input int arrowsUpCode = 233; // Up arrow code input int arrowsDnCode = 234; // Down arrow code input int arrowsUpSize = 3; // Up arrow size input int arrowsDnSize = 3; // Down arrow size input bool alertsOn = true; // Alerts on true/false? input bool alertsOnCurrent = false; // Alerts on current bar true/false? input bool alertsMessage = true; // Alerts pop-up message true/false? input bool alertsSound = false; // Alerts sound true/false? input bool alertsNotify = false; // Alerts push notification true/false? input bool alertsEmail = false; // Alerts email true/false? input string soundFile = "alert2.wav"; // Alerts sound file double val[],valDa[],valDb[],bandu1[],bandu2[],bandd2[],bandd1[],ma[],valc[]; //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int init() { IndicatorBuffers(4); SetIndexBuffer(0,val, INDICATOR_DATA); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1,valDa, INDICATOR_DATA); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(2,valDb, INDICATOR_DATA); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(3,valc, INDICATOR_CALCULATIONS); IndicatorShortName("Cci of jma ("+(string)inpCciPeriod+","+(string)inpSmoothPeriod+")"); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { string lookFor = arrowsIdentifier+":"; int lookForLength = StringLen(lookFor); for (int i=ObjectsTotal()-1; i>=0; i--) { string objectName = ObjectName(i); if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName); } } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // 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,counted_bars=prev_calculated; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit = fmin(rates_total-counted_bars,rates_total-1); // // // // // if (valc[limit]==-1) CleanPoint(limit,valDa,valDb); for(i=limit; i>=0; i--) { double _price = iSmooth(getPrice(inpPrice,open,close,high,low,i,rates_total),inpSmoothPeriod,inpSmoothPhase,i,rates_total,0); double avg = iSmooth(_price,inpCciPeriod,inpSmoothPhase,i,rates_total,1); double dev = fmax(iEmaDeviation(_price,inpCciPeriod,i,rates_total),DBL_MIN); val[i] = (_price-avg)/(0.015*dev); valDa[i] = EMPTY_VALUE; valDb[i] = EMPTY_VALUE; valc[i] = (ival[i+1]) ? 1 : (val[i]=0; i--) if (tf==iTfTable[i]) return(sTfTable[i]); return(""); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // #define _smoothInstances 2 #define _smoothInstancesSize 10 double _smthWork[][_smoothInstances*_smoothInstancesSize]; #define bsmax 5 #define bsmin 6 #define volty 7 #define vsum 8 #define avolty 9 // // // // // double iSmooth(double price, double length, double phase, int r, int bars, int instanceNo=0) { if (ArrayRange(_smthWork,0)!=bars) ArrayResize(_smthWork,bars); instanceNo*=_smoothInstancesSize; r = bars-r-1; if (price==EMPTY_VALUE) price=0; if (r==0 || length<=1){ int k=0; for(; k absDel2) ? absDel1 : (absDel1 < absDel2) ? absDel2 : 0; _smthWork[r][instanceNo+vsum] = _smthWork[r-1][instanceNo+vsum] + (_smthWork[r][instanceNo+volty]-_smthWork[r-forBar][instanceNo+volty])*0.1; _smthWork[r][instanceNo+avolty] = _smthWork[r-1][instanceNo+avolty]+(2.0/(fmax(4.0*length,30)+1.0))*(_smthWork[r][instanceNo+vsum]-_smthWork[r-1][instanceNo+avolty]); // // // // // double dVolty = (_smthWork[r][instanceNo+avolty]>0) ? _smthWork[r][instanceNo+volty]/_smthWork[r][instanceNo+avolty] : 0; double dVoltyTmp = pow(len1,1.0/pow1); if (dVolty > dVoltyTmp) dVolty = dVoltyTmp; if (dVolty < 1.0) dVolty = 1.0; // // // // // double pow2 = pow(dVolty, pow1); double len2 = sqrt(0.5*(length-1))*len1; double Kv = pow(len2/(len2+1),sqrt(pow2)); _smthWork[r][instanceNo+bsmax] = (del1>0) ? price : price - Kv*del1; _smthWork[r][instanceNo+bsmin] = (del2<0) ? price : price - Kv*del2; // // // // // double corr = fmax(fmin(phase,100),-100)/100.0 + 1.5; double beta = 0.45*(length-1)/(0.45*(length-1)+2); double alpha = pow(beta,pow2); _smthWork[r][instanceNo+0] = price + alpha*(_smthWork[r-1][instanceNo+0]-price); _smthWork[r][instanceNo+1] = (price - _smthWork[r][instanceNo+0])*(1-beta) + beta*_smthWork[r-1][instanceNo+1]; _smthWork[r][instanceNo+2] = (_smthWork[r][instanceNo+0] + corr*_smthWork[r][instanceNo+1]); _smthWork[r][instanceNo+3] = (_smthWork[r][instanceNo+2] - _smthWork[r-1][instanceNo+4])*((1-alpha)*(1-alpha)) + (alpha*alpha)*_smthWork[r-1][instanceNo+3]; _smthWork[r][instanceNo+4] = (_smthWork[r-1][instanceNo+4] + _smthWork[r][instanceNo+3]); return(_smthWork[r][instanceNo+4]); } // // // // // #define _edevInstances 1 #define _edevInstancesSize 2 double workEmaDeviation[][_edevInstances*_edevInstancesSize]; #define _ema0 0 #define _ema1 1 // // // // // double iEmaDeviation(double price,double period, int i, int bars, int instanceNo=0) { if (ArrayRange(workEmaDeviation,0)!=bars) ArrayResize(workEmaDeviation,bars); i = bars-i-1; instanceNo*=_edevInstancesSize; workEmaDeviation[i][instanceNo+_ema0] = price; workEmaDeviation[i][instanceNo+_ema1] = price; if (i>0 && period>1) { double alpha = 2.0/(1.0+period); workEmaDeviation[i][instanceNo+_ema0] = workEmaDeviation[i-1][instanceNo+_ema0]+alpha*(price -workEmaDeviation[i-1][instanceNo+_ema0]); workEmaDeviation[i][instanceNo+_ema1] = workEmaDeviation[i-1][instanceNo+_ema1]+alpha*(price*price-workEmaDeviation[i-1][instanceNo+_ema1]); } return(sqrt(period*(workEmaDeviation[i][instanceNo+_ema1]-workEmaDeviation[i][instanceNo+_ema0]*workEmaDeviation[i][instanceNo+_ema0])/fmax(period-1,1))); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // #define _prHABF(_prtype) (_prtype>=pr_habclose && _prtype<=pr_habtbiased2) #define _priceInstances 1 #define _priceInstancesSize 4 double workHa[][_priceInstances*_priceInstancesSize]; 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*=_priceInstancesSize; int r = bars-i-1; // // // // // double haOpen = (r>0) ? (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0 : (open[i]+close[i])/2;; double haClose = (open[i]+high[i]+low[i]+close[i]) / 4.0; if (_prHABF(tprice)) if (high[i]!=low[i]) haClose = (open[i]+close[i])/2.0+(((close[i]-open[i])/(high[i]-low[i]))*fabs((close[i]-open[i])/2.0)); else haClose = (open[i]+close[i])/2.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: case pr_habtbiased2: 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]=Bars-3) return; if ((second[i] != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE)) second[i+1] = EMPTY_VALUE; else if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE)) first[i+1] = EMPTY_VALUE; } void PlotPoint(int i,double& first[],double& second[],double& from[]) { if (i>=Bars-2) return; if (first[i+1] == EMPTY_VALUE) if (first[i+2] == EMPTY_VALUE) { first[i] = from[i]; first[i+1] = from[i+1]; second[i] = EMPTY_VALUE; } else { second[i] = from[i]; second[i+1] = from[i+1]; first[i] = EMPTY_VALUE; } else { first[i] = from[i]; second[i] = EMPTY_VALUE; } } //------------------------------------------------------------------- // //------------------------------------------------------------------- // // // // // void drawArrow(int i,color theColor,int theCode, int theWidth, bool up) { string name = arrowsIdentifier+":"+(string)Time[i]; double gap = iATR(NULL,0,20,i); // // // // // //datetime time = Time[i]; if (arrowsOnNewest) time += _Period*60-1; ObjectCreate(name,OBJ_ARROW,0,Time[i],0); ObjectSet(name,OBJPROP_ARROWCODE,theCode); ObjectSet(name,OBJPROP_WIDTH,theWidth); ObjectSet(name,OBJPROP_COLOR,theColor); if (up) ObjectSet(name,OBJPROP_PRICE1,High[i] + arrowsUpperGap * gap); else ObjectSet(name,OBJPROP_PRICE1,Low[i] - arrowsLowerGap * gap); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[0]) { previousAlert = doWhat; previousTime = Time[0]; // // // // // message = StringConcatenate(Symbol()," ",timeFrameToString(_Period)," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," CCI of JMA ",doWhat); if (alertsMessage) Alert(message); if (alertsNotify) SendNotification(message); if (alertsEmail) SendMail(StringConcatenate(Symbol()," CCI of JMA "),message); if (alertsSound) PlaySound(soundFile); } } //+------------------------------------------------------------------+