Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

derek2209

Members
  • Content Count

    32
  • Joined

  • Last visited

Everything posted by derek2209

  1. Hi I would like to Plot the "BB-MACD" Created by KelvinHand for a Variable Time Period Dominant Cycle as calculated by "Ehlers Autocorrelation Periodogram" code below I have only able to plot the "BB-MACD" Created by KelvinHand using the fixed time period of the last value of "Ehlers Autocorrelation Periodogram" Hoping that you can help Thanking you in advance Best regards Derek ////////////////////////////////////////////////////// //Ehlers Autocorrelation Periodogram for Amibroker (AFL) /* Autocorrelation Periodogram 2013 John F. Ehlers */ SetBarsRequired(sbrAll); LPeriod = Param("Low-pass Period", 10, 3, 20); HPeriod = Param("High-pass Period", 48, 22, 80); IsPlotHeatMap = ParamToggle("Show HeatMap?", "No|Yes", 1); IsPlotDominantCycle = ParamToggle("Show Dom. Cycle?", "No|Yes"); pi=3.1415926; function RoofingFilter(lpPeriod, hpPeriod) { alpha1 = (cos(0.707*2*pi / hpPeriod) + sin(0.707*2*pi / hpPeriod) - 1) / cos(0.707*2*pi / hpPeriod); a1 = exp(-1.414*pi / lpPeriod); b1 = 2*a1*cos(1.414*pi / lpPeriod); c2 = b1; c3 = -a1*a1; c1 = 1 - c2 - c3; HP = Close; Filt = HP; for(i = 2; i < BarCount; i++) { HP[i] = ((1 - alpha1 / 2)^2)*(Close[i] - 2*Close[i-1] + Close[i-2]) + 2*(1 - alpha1)*HP[i-1] - ((1 - alpha1)^2)*HP[i-2]; Filt[i] = c1*(HP[i] + HP[i-1]) / 2 + c2*Filt[i-1] + c3*Filt[i-2]; } return Filt; } function AGC(lowerCutoff, higherCutoff, acceptableSlope) { factor = 0; accSlope = -acceptableSlope; //acceptableSlope = 1.5 dB halfLC = lowerCutoff / 2; halfHC = higherCutoff / 2; ratio = 10^(accSlope/20); if(halfHC - halfLC > 0) factor = ratio^(1/(halfHC - halfLC)); return factor; } function AutocorrelationPeriodogram(data, isHeatMap, isDomCyc) { avgLength = 3; dominantCycle = 0; //Pearson correlation for each value of lag for(lag = 0; lag <= 48; lag++) { //Set the average length as M M = avgLength; if(avgLength == 0) M = lag; //Initialize correlation sums Sx = 0; Sy = 0; Sxx = 0; Syy = 0; Sxy = 0; //Advance samples of both data streams and sum Pearson components for(count = 0; count <= M-1; count++) { X = Ref(data, -count); Y = Ref(data, -(lag + count)); Sx += X; Sy += Y; Sxx += X^2; Syy += Y^2; Sxy += X*Y; } var1 = (M*Sxx - Sx^2)*(M*Syy - Sy^2); VarSet("corr" + lag, IIf(var1 > 0, (M*Sxy - Sx*Sy)/sqrt(var1), 0)); //Compute correlation for each value of lag //VarSet("corrScale" + lag, IIf(var1 > 0, 0.5*((M*Sxy - Sx*Sy)/sqrt(var1) + 1), 0)); //Scale each correlation to range between 0 and 1 } /*//Plot as a Heatmap (for scale each correlation to range between 0 and 1) for(period = 3; period <= 48; period++) { corr = VarGet("corrScale" + period); Red = IIf(corr > 0.5, 255*(2 - 2*corr), 255); Green = IIf(corr > 0.5, 255, 2*255*corr); PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel); }*/ /* The DFT is accomplished by correlating the autocorrelation at each value of lag with the cosine and sine of each period of interest. The sum of the squares of each of these values represents the relative power at each period. */ for(period = 10; period <= 48; period++) { cosinePart = 0; sinePart = 0; for(n = 3; n <= 48; n++) { cosinePart += VarGet("corr" + n)*cos(2*pi*n / period); sinePart += VarGet("corr" + n)*sin(2*pi*n / period); } VarSet("sqSum" + period, cosinePart^2 + sinePart^2); } //EMA is used to smooth the power measurement at each period for(period = 10; period <= 48; period++) VarSet("r" + period, AMA((VarGet("sqSum" + period))^2, 0.2)); //Find Maximum Power Level for Normalization K = AGC(10, 48, 1.5); for(period = 10; period <= 48; period++) { if(period == 10) VarSet("maxPwr", 0); VarSet("maxPwr", IIf(VarGet("r" + period) > VarGet("maxPwr"), K*VarGet("r" + period), VarGet("maxPwr"))); } //Normalization power for(period = 10; period <= 48; period++) VarSet("pwr" + period, VarGet("r" + period)/VarGet("maxPwr")); //Compute the dominant cycle using the CG of the spectrum Spx = 0; Sp = 0; for(period = 10; period <= 48; period++) { Spx += IIf(VarGet("pwr" + period) >= 0.5, period*VarGet("pwr" + period), 0); Sp += IIf(VarGet("pwr" + period) >= 0.5, VarGet("pwr" + period), 0); } dominantCycle = IIf(Sp != 0, Spx / Sp, 0); dominantCycle =(dominantCycle); if(isHeatMap) { //Plot as a Heatmap for(period = 10; period <= 48; period++) { pwr = VarGet("pwr" + period); Red = IIf(pwr > 0.5, 255, 2*255*pwr); Green = IIf(pwr > 0.5, 255*(2*pwr - 1), 0); PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel, Null, Null, 0, 0); } } if(isDomCyc) Plot(LastValue(dominantCycle,1), "Dominant Cycle", colorBlue, styleThick, Null, Null, 0, 1); pds=LastValue(dominantCycle,1); //"BB-MACD") Created by KelvinHand SetChartBkColor( ParamColor("background",colorBlack) ); A1=EMA(C,pds/2)-EMA(C,pds); BBtop=BBandTop(A1,10,1); BBbot=BBandBot(A1,10,1); Color=IIf(a1<0 AND a1>Ref(a1,-1), colorLime,IIf(a1>0 AND a1>Ref(a1,-1),colorBrightGreen,IIf(a1>0 AND a1<Ref(a1,-1),colorCustom12,colorRed))); Plot(a1,"MACD",color,styleThick+styleLine); Plot(BBtop,"BBtop",colorWhite,styleDashed); Plot(BBbot,"BBbot",colorWhite,styleDashed); Plot(0,"",colorWhite,1); AddColumn(round(dominantCycle), " DominantCycle", 2.0 , colorRed, colorLightYellow,50) ; return dominantCycle; } filtData = RoofingFilter(LPeriod, HPeriod); AutocorrelationPeriodogram(filtData, IsPlotHeatMap, IsPlotDominantCycle); ]
  2. Hi Kelvin, Many thanks for your code and the additional information you supplied Best regards, Derek
  3. Hi, Would anyone be kind enough to convert the code below into Amibroker code Hoping that you can oblige Thank you in advance Derek ............................................ // EW Oscillator Breaking Bands // Author: Unknown // http://finance.groups.yahoo.com/group/amibroker/message/105938 // version: 1.0 // Author: aaa // version: 1.1 // Date: 20091226 // added: a few tweaks Inputs: K( 1 ), K2( 0.0555 ), Len( 5 ); Vars: Price1 ( 0 ), UpperBand( 0), LowerBand( 0), AvgP( 0); Price1 =( Average((H+L)/2,5) - Average((H+L)/2,35)) ; If Price1 > 0 then begin upperband = price1; If barnumber >= 2 then UpperBand = (upperband[1] + k2*( K * Price1 - upperband[1]) ); end; If Price1 < 0 then begin LowerBand = Price1; If barnumber>=2 then LowerBand =(lowerband[1] + K2*( K*Price1 - lowerband[1])); end; AvgP = XAverage(Price1,Len); Plot1( Price1, "Osc535" ); Plot2( AvgP, "AvgP" ); Plot3( UpperBand, "upper" ); Plot4( LowerBand, "lower" ); Plot5( 0 , "ZeroLine" ); if AvgP > 0 then setplotcolor ( 2, rgb( 183 , 179 , 142 ) ); if AvgP < 0 then setplotcolor ( 2, rgb( 110 , 136 , 177 ) ); if Price1 > 0 then setplotcolor ( 1, yellow ); if Price1 < 0 then setplotcolor ( 1, blue ); �
  4. HI, Does anyone have the Jurik Formula for the Tradestation Jurik Stochastic. Hoping you can oblige, Derek
  5. Hi, I have attached an Image of the Turbo_JRSX I hope this will help Best regards, Derek
  6. Hi phim9hi3n, Many thank for your MA_WRP indicator Best regards, Derek2209
  7. Hi, Could you please help me to convert the Turbo_JRSX.mq4 code below into Tradestation Easylanguage. Thank you in advance Derek --------------------------------------------------------------------------- http://www.mql5.com/en/code/viewcode/7900/44457/Turbo_JRSX.mq4 //+------------------------------------------------------------------+ //| | //| Copyright © 1999-2007, MetaQuotes Software Corp. | //| http://www.metaquotes.ru | //+------------------------------------------------------------------+ #property copyright "strategybuilderfx.com - modified by bluto to use typical price (HLC/3)" #property link "finger" //---- #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Magenta #property indicator_level1 70 #property indicator_level2 30 #property indicator_level3 50 #property indicator_maximum 100 #property indicator_minimum 0 //---- input parameters extern int Len=14; //---- buffers double rsx[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,rsx); IndicatorShortName("Turbo_JRSX"); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { double f88, f90; double f0, v4, v8, vC, v10, v14, v18, v20; double f8, f10, f18, f20, f28, f30, f38, f48, v1C; double f50, f58, f60, f68, f70, f78, f80, f40; //int counted_bars = IndicatorCounted(),limit,shift; //if (counted_bars<0) return(-1); //if (counted_bars>0) counted_bars--; double limit=Bars-(Len)-1; //if(counted_bars>Len) limit=Bars-counted_bars-1; for(int shift=limit;shift>=0;shift--) { if (f90==0.0) { f90=1.0; f0=0.0; if (Len-1>=5) f88=Len-1.0; else f88=5.0; // f8 = 100.0*(Close[shift]); // // Modified for median price // f8=100.0*((High[shift]+Low[shift]+Close[shift])/3); f18=3.0/(Len + 2.0); f20=1.0 - f18; } else { if (f88<=f90) f90=f88 + 1; else f90=f90 + 1; f10=f8; // f8 = 100*Close[shift]; f8=100.0*((High[shift]+Low[shift]+Close[shift])/3); v8=f8 - f10; f28=f20 * f28 + f18 * v8; f30=f18 * f28 + f20 * f30; vC=f28 * 1.5 - f30 * 0.5; f38=f20 * f38 + f18 * vC; f40=f18 * f38 + f20 * f40; v10=f38 * 1.5 - f40 * 0.5; f48=f20 * f48 + f18 * v10; f50=f18 * f48 + f20 * f50; v14=f48 * 1.5 - f50 * 0.5; f58=f20 * f58 + f18 * MathAbs(v8); f60=f18 * f58 + f20 * f60; v18=f58 * 1.5 - f60 * 0.5; f68=f20 * f68 + f18 * v18; f70=f18 * f68 + f20 * f70; v1C=f68 * 1.5 - f70 * 0.5; f78=f20 * f78 + f18 * v1C; f80=f18 * f78 + f20 * f80; v20=f78 * 1.5 - f80 * 0.5; //---- if ((f88>=f90) && (f8!=f10)) f0=1.0; if ((f88==f90) && (f0==0.0)) f90=0.0; } if ((f88 < f90) && (v20 > 0.0000000001)) { 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; } rsx[shift]=v4; } //---- return(0); } //+------------------------------------------------------------------+
  8. Hi, I am new to Tradestation Easylanguage Code and I do not know when * how to use Arrays. Could you please help me hoe to convert the code below into Tradestation Easylanguage. Hoping you can oblige. Thank you in advance Derek ------------------------------------------------------------ /* Turbo_JRSX : a better RSI ? Ported from Metatrader. Original source code : http://codebase.mql4.com/source/6182 */ SetChartOptions (0, 0, chartGrid20 | chartGrid50 | chartGrid80); Len = Param ( "Periods", 12, 1, 200, 1 ); function JRSX ( Period ) { f88 = 0; f90 = 0; f0 = 0; v4 = 0; v8 = 0; vC = 0; v10 = 0; v14 = 0; v18 = 0; v20 = 0; f8 = 0; f10 = 0; f18 = 0; f20 = 0; f28 = 0; f30 = 0; f38 = 0; f48 = 0; v1C = 0; f50 = 0; f58 = 0; f60 = 0; f68 = 0; f70 = 0; f78 = 0; f80 = 0; f40 = 0; f90 = 1.0; f0 = 0.0; if ( Period-1 >= 5 ) f88 = Period-1.0; else f88 = 5.0; f8 = 100.0 * ((H[0]+L[0]+Close[0])/3); f18 = 3.0 / (Period + 2.0); f20 = 1.0 - f18; for ( i = 1; i < BarCount; i++ ) { if (f88 <= f90) f90 = f88 + 1; else f90 = f90 + 1; f10 = f8; // f8 = 100*Close[i]; f8 = 100.0*((H[i]+L[i]+C[i])/3); v8 = f8 - f10; f28 = f20 * f28 + f18 * v8; f30 = f18 * f28 + f20 * f30; vC = f28 * 1.5 - f30 * 0.5; f38 = f20 * f38 + f18 * vC; f40 = f18 * f38 + f20 * f40; v10 = f38 * 1.5 - f40 * 0.5; f48 = f20 * f48 + f18 * v10; f50 = f18 * f48 + f20 * f50; v14 = f48 * 1.5 - f50 * 0.5; f58 = f20 * f58 + f18 * abs (v8); f60 = f18 * f58 + f20 * f60; v18 = f58 * 1.5 - f60 * 0.5; f68 = f20 * f68 + f18 * v18; f70 = f18 * f68 + f20 * f70; v1C = f68 * 1.5 - f70 * 0.5; f78 = f20 * f78 + f18 * v1C; f80 = f18 * f78 + f20 * f80; v20 = f78 * 1.5 - f80 * 0.5; if ((f88 >= f90) && (f8 != f10)) f0 = 1.0; if ((f88 == f90) && (f0 == 0.0)) f90 = 0.0; if ((f88 < f90) && (v20 > 0.0000000001)) { 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; } rsx[i] = v4; } return rsx; } dynamic_color = IIf( JRSX(Len)>Ref(JRSX(Len),-1), colorBlue, colorRed ); Plot( JRSX(Len), "RSX", dynamic_color,styleThick=4 ); Plot(70,"",colorGreen,styleDashed = 32); Plot(60,"",colorGreen,styleDashed = 32); Plot(40,"",colorGreen,styleDashed = 32); Plot(30,"",colorGreen,styleDashed = 32); Plot(50,"",colorBlue,styleLine = 1); Title =EncodeColor(colorBlue)+" Turbo JRSX " + " Period = " + WriteVal( Len,1)+" JRSX ="+WriteVal(JRSX(Len));
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.