Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
- //| JRSX.mq4 |
- //| JRSX: Copyright © 2005, Weld, Jurik Research |
- //| http://weld.torguem.net |
- //| MQL4: Copyright © 2005, Nikolay Kositsin |
- //| Khabarovsk, [email protected] |
- //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
- #property copyright "Weld"
- #property link "http://weld.torguem.net"
- #property indicator_separate_window
- #property indicator_buffers 2
- #property indicator_color1 Magenta
- #property indicator_color2 Green
- #property indicator_level1 80
- #property indicator_level2 20
- #property indicator_level3 50
- #property indicator_maximum 100
- #property indicator_minimum 0
- //---- input parameters
- extern int RSX_Length = 14;
- extern double JMA_Length = 14;
- extern int JMA_Phase = 0;
- //---- buffers
- double JRSX_Bufer[];
- double JMAValueBuffer[];
- //----
- int shift,r,w,k,Tnew,counted_bars,T0,T1;
- //----
- double v4,v8,v10,v14,v18,v20,v0C,v1C,v8A;
- double F28,F30,F38,F40,F48,F50,F58,F60,F68,F70,F78,F80;
- double f0,f28,f30,f38,f40,f48,f50,f58,f60,f68,f70,f78,f80,Kg,Hg;
- double fC0Buffer[];
- double fA8Buffer[];
- double fC8Buffer[];
- double list[128], ring1[128], ring2[11], buffer[62];
- bool initFlag;
- int limitValue, startValue, loopParam, loopCriteria;
- int cycleLimit, highLimit, counterA, counterB;
- double cycleDelta, lowDValue, highDValue, absValue, paramA, paramB;
- double phaseParam, logParam, JMAValue, series, sValue, sqrtParam, lengthDivider;
- int s58, s60, s40, s38, s68;
- //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
- //| Custom indicator initialization function |
- //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
- int init()
- {
- //---- indicators
- IndicatorBuffers(5);
- SetIndexStyle(0,DRAW_LINE);
- SetIndexBuffer(0,JRSX_Bufer);
- IndicatorShortName("JMAofRSX("+RSX_Length+","+JMA_Length+","+JMA_Phase+")");
- SetIndexEmptyValue(0,50.0);
- double lengthParam;
- SetIndexBuffer (1, JMAValueBuffer);
- SetIndexBuffer (2, fC0Buffer);
- SetIndexBuffer (3, fA8Buffer);
- SetIndexBuffer (4, fC8Buffer);
- ArrayInitialize (ring2, 0);
- ArrayInitialize (ring1, 0);
- ArrayInitialize (buffer, 0);
- limitValue = 63;
- startValue = 64;
- //----
- for (int i = 0; i <= limitValue; i++) list [i] = -1000000;
- for (i = startValue; i <= 127; i++) list [i] = 1000000;
- //----
- initFlag = true;
- if (JMA_Length < 1.0000000002) lengthParam = 0.0000000001;
- else lengthParam = (JMA_Length - 1) / 2.0;
- //----
- if (JMA_Phase < -100) phaseParam = 0.5;
- else if (JMA_Phase > 100) phaseParam = 2.5;
- else phaseParam = JMA_Phase / 100.0 + 1.5;
- //----
- logParam = MathLog (MathSqrt (lengthParam)) / MathLog (2.0);
- //----
- if (logParam + 2.0 < 0) logParam = 0;
- else logParam = logParam + 2.0;
- //----
- sqrtParam = MathSqrt(lengthParam) * logParam;
- lengthParam = lengthParam * 0.9;
- lengthDivider = lengthParam / (lengthParam + 2.0);
- //----
- return(0);
- }
- //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
- //| Custor indicator deinitialization function |
- //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+
- int start()
- {
- counted_bars=IndicatorCounted()-1;
- if(counted_bars < 0) counted_bars = 0;
- if (counted_bars>RSX_Length) shift=Bars-counted_bars;
- else shift=Bars-RSX_Length-1;
- Tnew=Time[shift+1];
- //+--- âînnnríîâëlícl dldlelííuo +=====================+
- if((Tnew!=T0)&&(shift<Bars-RSX_Length-1))
- {
- if (Tnew==T1)
- {
- f28=F28; f30=F30; f38=F38; f40=F40; f48=F48; f50=F50;
- f58=F58; f60=F60; f68=F68; f70=F70; f78=F78; f80=F80;
- }
- else return(-1);
- }
- //+--- +===============================================+
- if (RSX_Length-1>=5)w=RSX_Length-1;else w=5; Kg=3/(RSX_Length+2.0); Hg=1.0-Kg;
- while (shift >= 0)
- {//+-------------------+
- if (r==0)
- {//...
- r = 1; k = 0;
- }//...
- else
- {//++++++++++++++++++++
- if (r>=w) r=w+1; else r=r+1;
- v8 = (High[shift]+Low[shift])-(High[shift+1]+Low[shift+1]); v8A=MathAbs(v8);
- //---- âu÷cnëlícl V14 ------
- f28 = Hg * f28 + Kg * v8;
- f30 = Kg * f28 + Hg * f30;
- v0C = 1.5 * f28 - 0.5 * f30;
- f38 = Hg * f38 + Kg * v0C;
- f40 = Kg * f38 + Hg * f40;
- v10 = 1.5 * f38 - 0.5 * f40;
- f48 = Hg * f48 + Kg * v10;
- f50 = Kg * f48 + Hg * f50;
- v14 = 1.5 * f48 - 0.5 * f50;
- //---- âu÷cnëlícl V20 ------
- f58 = Hg * f58 + Kg * v8A;
- f60 = Kg * f58 + Hg * f60;
- v18 = 1.5 * f58 - 0.5 * f60;
- f68 = Hg * f68 + Kg * v18;
- f70 = Kg * f68 + Hg * f70;
- v1C = 1.5 * f68 - 0.5 * f70;
- f78 = Hg * f78 + Kg * v1C;
- f80 = Kg * f78 + Hg * f80;
- v20 = 1.5 * f78 - 0.5 * f80;
- if ((r <= w) && (v8!= 0)) k = 1;
- if ((r == w) && (k == 0)) r = 0;
- }//++++++++++++++++++++
- if ((r > w) &&(v20 > 0.0000000001 )) ///0.0000000001=={1.0e-10};
- {//...
- v4 = (v14/v20+1.0)*50.0; if(v4>100.0)v4=100.0; if(v4<0.0)v4=0.0;
- }//...
- else v4 = 50.0;
- JRSX_Bufer[shift]=v4;
- //+--- Nîodrílícl dldlelííuo +========================+
- if (shift==1)
- {
- T1=Time[1];T0=Time[0];
- F28=f28; F30=f30; F38=f38; F40=f40; F48=f48; F50=f50;
- F58=f58; F60=f60; F68=f68; F70=f70; F78=f78; F80=f80;
- }
- //+---+===============================================+
- shift--;
- }
- if (counted_bars>JMA_Length+RSX_Length) shift=Bars-counted_bars;
- else shift=Bars-JMA_Length-RSX_Length-1;
- while (shift >= 0) {
- series = JRSX_Bufer [shift];
- if (loopParam < 61) {
- loopParam++;
- buffer [loopParam] = series;
- }
- if (loopParam > 30) {
- if (initFlag) {
- initFlag = false;
- int diffFlag = 0;
- for (int i = 1; i <= 29; i++) {
- if (buffer [i + 1] != buffer [i]) diffFlag = 1;
- }
- highLimit = diffFlag * 30;
- if (highLimit == 0) paramB = series;
- else paramB = buffer[1];
- paramA = paramB;
- if (highLimit > 29) highLimit = 29;
- } else
- highLimit = 0;
- //---- big cycle
- for (i = highLimit; i >= 0; i--) {
- if (i == 0) sValue = series; else sValue = buffer [31 - i];
- if (MathAbs (sValue - paramA) > MathAbs (sValue - paramB)) absValue = MathAbs(sValue - paramA); else absValue = MathAbs(sValue - paramB);
- double dValue = absValue + 0.0000000001; //1.0e-10;
- if (counterA <= 1) counterA = 127; else counterA--;
- if (counterB <= 1) counterB = 10; else counterB--;
- if (cycleLimit < 128) cycleLimit++;
- cycleDelta += (dValue - ring2 [counterB]);
- ring2 [counterB] = dValue;
- if (cycleLimit > 10) highDValue = cycleDelta / 10.0; else highDValue = cycleDelta / cycleLimit;
- if (cycleLimit > 127) {
- dValue = ring1 [counterA];
- ring1 [counterA] = highDValue;
- s68 = 64; s58 = s68;
- while (s68 > 1) {
- if (list [s58] < dValue) {
- s68 = s68 / 2.0;
- s58 += s68;
- } else
- if (list [s58] <= dValue) {
- s68 = 1;
- } else {
- s68 = s68 / 2.0;
- s58 -= s68;
- }
- }
- } else {
- ring1 [counterA] = highDValue;
- if ((limitValue + startValue) > 127) {
- startValue--;
- s58 = startValue;
- } else {
- limitValue++;
- s58 = limitValue;
- }
- if (limitValue > 96) s38 = 96; else s38 = limitValue;
- if (startValue < 32) s40 = 32; else s40 = startValue;
- }
- //----
- s68 = 64;
- s60 = s68;
- while (s68 > 1) {
- if (list [s60] >= highDValue) {
- if (list [s60 - 1] <= highDValue) {
- s68 = 1;
- }
- else {
- s68 = s68 / 2.0;
- s60 -= s68;
- }
- }
- else {
- s68 = s68 / 2.0;
- s60 += s68;
- }
- if ((s60 == 127) && (highDValue > list[127])) s60 = 128;
- }
- if (cycleLimit > 127) {
- if (s58 >= s60) {
- if (((s38 + 1) > s60) && ((s40 - 1) < s60))
- lowDValue += highDValue;
- else if ((s40 > s60) && ((s40 - 1) < s58))
- lowDValue += list [s40 - 1];
- }
- else if (s40 >= s60) {
- if (((s38 + 1) < s60) && ((s38 + 1) > s58))
- lowDValue += list[s38 + 1];
- }
- else if ((s38 + 2) > s60)
- lowDValue += highDValue;
- else if (((s38 + 1) < s60) && ((s38 + 1) > s58))
- lowDValue += list[s38 + 1];
- if (s58 > s60) {
- if (((s40 - 1) < s58) && ((s38 + 1) > s58))
- lowDValue -= list [s58];
- else if ((s38 < s58) && ((s38 + 1) > s60))
- lowDValue -= list [s38];
- }
- else {
- if (((s38 + 1) > s58) && ((s40 - 1) < s58))
- lowDValue -= list [s58];
- else if ((s40 > s58) && (s40 < s60))
- lowDValue -= list [s40];
- }
- }
- if (s58 <= s60) {
- if (s58 >= s60) list[s60] = highDValue; else {
- for (int j = s58 + 1; j <= (s60 - 1); j++) {
- list [j - 1] = list[j];
- }
- list [s60 - 1] = highDValue;
- }
- } else {
- for (j = s58 - 1; j >= s60; j--) {
- list [j + 1] = list [j];
- }
- list [s60] = highDValue;
- }
- if (cycleLimit <= 127) {
- lowDValue = 0;
- for (j = s40; j <= s38; j++) {
- lowDValue += list[j];
- }
- }
- //----
- if ((loopCriteria + 1) > 31) loopCriteria = 31; else loopCriteria++;
- double JMATempValue, sqrtDivider = sqrtParam / (sqrtParam + 1.0);
- if (loopCriteria <= 30) {
- if (sValue - paramA > 0) paramA = sValue; else paramA = sValue - (sValue - paramA) * sqrtDivider;
- if (sValue - paramB < 0) paramB = sValue; else paramB = sValue - (sValue - paramB) * sqrtDivider;
- JMATempValue = series;
- if (loopCriteria == 30) {
- fC0Buffer [shift] = series;
- int intPart;
- if (MathCeil(sqrtParam) >= 1) intPart = MathCeil(sqrtParam); else intPart = 1;
- int leftInt = IntPortion (intPart);
- if (MathFloor(sqrtParam) >= 1) intPart = MathFloor(sqrtParam); else intPart = 1;
- int rightPart = IntPortion (intPart);
- if (leftInt == rightPart) dValue = 1.0;
- else
- dValue = (sqrtParam - rightPart) / (leftInt - rightPart);
- if (rightPart <= 29) int upShift = rightPart; else upShift = 29;
- if (leftInt <= 29) int dnShift = leftInt; else dnShift = 29;
- fA8Buffer [shift] = (series - buffer [loopParam - upShift]) * (1 - dValue) / rightPart + (series - buffer[loopParam - dnShift]) * dValue / leftInt;
- }
- } else {
- double powerValue, squareValue;
- dValue = lowDValue / (s38 - s40 + 1);
- if (0.5 <= logParam - 2.0) powerValue = logParam - 2.0;
- else powerValue = 0.5;
- if (logParam >= MathPow(absValue/dValue, powerValue)) dValue = MathPow (absValue/dValue, powerValue); else dValue = logParam;
- if (dValue < 1) dValue = 1;
- powerValue = MathPow (sqrtDivider, MathSqrt (dValue));
- if (sValue - paramA > 0) paramA = sValue; else paramA = sValue - (sValue - paramA) * powerValue;
- if (sValue - paramB < 0) paramB = sValue; else paramB = sValue - (sValue - paramB) * powerValue;
- }
- }
- // ---- end of big cycle
- if (loopCriteria > 30) {
- JMATempValue = JMAValueBuffer [shift + 1];
- powerValue = MathPow (lengthDivider, dValue);
- squareValue = MathPow (powerValue, 2);
- fC0Buffer [shift] = (1 - powerValue) * series + powerValue * fC0Buffer [shift + 1];
- fC8Buffer [shift] = (series - fC0Buffer [shift]) * (1 - lengthDivider) + lengthDivider * fC8Buffer [shift + 1];
- fA8Buffer [shift] = (phaseParam * fC8Buffer [shift] + fC0Buffer [shift] - JMATempValue) *
- (powerValue * (-2.0) + squareValue + 1) + squareValue * fA8Buffer [shift + 1];
- JMATempValue += fA8Buffer [shift];
- }
- JMAValue = JMATempValue;
- }
- if (loopParam <= 30) JMAValue = 0;
- JMAValueBuffer [shift] = JMAValue;
- //---- End of main cycle
- shift--;
- }
- //+-------------------+
- return(0);
- }
- //+------------------------------------------------------------------+
- int IntPortion (double param) {
- if (param > 0) return (MathFloor (param));
- if (param < 0) return (MathCeil (param));
- return (0.0);
- }
- //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement