Conversion code TrendEnveloppes
Forums › ProRealTime forum Français › Support ProBuilder › Conversion code TrendEnveloppes
- This topic has 11 replies, 3 voices, and was last updated 4 years ago by Fr7.
Viewing 12 posts - 1 through 12 (of 12 total)
-
-
11/05/2020 at 6:39 PM #14957311/06/2020 at 8:45 AM #14963011/06/2020 at 5:56 PM #14971611/06/2020 at 5:57 PM #14971811/06/2020 at 5:58 PM #149719123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163package com.dukascopy.indicators;import com.dukascopy.api.DefaultColors;import com.dukascopy.api.indicators.DoubleRangeDescription;import com.dukascopy.api.indicators.IIndicator;import com.dukascopy.api.indicators.IIndicatorContext;import com.dukascopy.api.indicators.IndicatorInfo;import com.dukascopy.api.indicators.IndicatorResult;import com.dukascopy.api.indicators.InputParameterInfo;import com.dukascopy.api.indicators.IntegerRangeDescription;import com.dukascopy.api.indicators.OptInputParameterInfo;import com.dukascopy.api.indicators.OutputParameterInfo;public class TrendEnvelopesIndicator1 implements IIndicator {private IIndicator lwma;private int timePeriod = 14;private double deviation = 0.1;private IndicatorInfo indicatorInfo;private InputParameterInfo[] inputParameterInfos;private OutputParameterInfo[] outputParameterInfos;private OptInputParameterInfo[] optInputParameterInfos;private final double[][][] inputs = new double[1][][];private final double[][] outputs = new double[2][];public void onStart(IIndicatorContext context) {lwma = context.getIndicatorsProvider().getIndicator("LWMA");indicatorInfo = new IndicatorInfo("TrendEnvelopes", "Trend Envelope", "Overlap Studies", true, false, true, 1, 2, 2);inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)};optInputParameterInfos = new OptInputParameterInfo[] {new OptInputParameterInfo("Time Period", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(timePeriod, 2, 500, 1)),new OptInputParameterInfo("Deviation", OptInputParameterInfo.Type.OTHER, new DoubleRangeDescription(deviation, 0.01, 100, 0.01, 2))};outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("Low Band", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),new OutputParameterInfo("High Band", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)};outputParameterInfos[0].setColor(DefaultColors.ROYAL_BLUE);outputParameterInfos[0].setGapAtNaN(true);outputParameterInfos[1].setColor(DefaultColors.RED);outputParameterInfos[1].setGapAtNaN(true);}public IndicatorResult calculate(int startIndex, int endIndex) {if (startIndex - getLookback() < 0) {startIndex = getLookback();}if (startIndex > endIndex) {return new IndicatorResult(0, 0);}double[] dsma = new double[endIndex - startIndex + 1];lwma.setInputParameter(0, inputs[0][1]);lwma.setOptInputParameter(0, timePeriod);lwma.setOutputParameter(0, dsma);lwma.calculate(startIndex - 1, endIndex - 1);double[] valuesLow = new double[endIndex - startIndex + 1];double[] valuesHigh = new double[endIndex - startIndex + 1];int trend = 0;for (int i = startIndex, j = 0; i <= endIndex; i++, j++) {//Inputs: 0 open, 1 close, 2 high, 3 low, 4 volumevaluesLow[j] = (1 - deviation / 100) * dsma[j];valuesHigh[j] = (1 + deviation / 100) * dsma[j];if (inputs[0][1][i] > valuesHigh[j]) {trend = 1;} else if (inputs[0][1][i] < valuesLow[j]) {trend = -1;}if (trend > 0) {outputs[1][j] = Double.NaN;if (j > 0 && valuesLow[j] < valuesLow[j - 1]) {valuesLow[j] = valuesLow[j - 1];}outputs[0][j] = valuesLow[j];} else {outputs[0][j] = Double.NaN;if (j > 0 && valuesHigh[j] > valuesHigh[j - 1]) {valuesHigh[j] = valuesHigh[j - 1];}outputs[1][j] = valuesHigh[j];}}return new IndicatorResult(startIndex, endIndex - startIndex + 1);}public IndicatorInfo getIndicatorInfo() {return indicatorInfo;}public InputParameterInfo getInputParameterInfo(int index) {if (index < inputParameterInfos.length) {return inputParameterInfos[index];}return null;}public OptInputParameterInfo getOptInputParameterInfo(int index) {if (index < optInputParameterInfos.length) {return optInputParameterInfos[index];}return null;}public OutputParameterInfo getOutputParameterInfo(int index) {if (index < outputParameterInfos.length) {return outputParameterInfos[index];}return null;}public void setInputParameter(int index, Object array) {inputs[index] = (double[][]) array;}public void setOutputParameter(int index, Object array) {switch (index) {case 0:outputs[index] = (double[]) array;break;case 1:outputs[index] = (double[]) array;break;default:throw new ArrayIndexOutOfBoundsException(index);}}public void setOptInputParameter(int index, Object value) {switch (index) {case 0:timePeriod = (Integer) value;lwma.setOptInputParameter(0, timePeriod);break;case 1:deviation = (Double) value;break;default:throw new ArrayIndexOutOfBoundsException(index);}}public int getLookback() {return lwma.getLookback() + 1;}public int getLookforward() {return 0;}}11/09/2020 at 2:53 PM #149905
Le code ci-dessous doit être correct, merci de confirmer.
Il s’agit en fait d’un breakout des bandes Enveloppes qui permet le passage de la tendance haussière à baissière et vice-versa.
123456789101112131415161718192021222324252627282930313233343536373839404142434445timePeriod=14Deviation=0.01price=customclosedsma = WeightedAverage[timePeriod](price)valuesLow = (1 - deviation / 100) * dsmavaluesHigh = (1 + deviation / 100) * dsmainputs=priceif (inputs > valuesHigh) thentrend = 1elsif (inputs < valuesLow) thentrend = -1endifif (trend > 0) thenalpha1=0if ( valuesLow < valuesLow[1]) thenvaluesLow = valuesLow[1]endifif trend[1]>0 thenoutputs0 = valuesLowoutputs1 = valueshighalpha0 = 255elsedrawtext("●",barindex,valueslow,dialog,bold,22) coloured(65,105,225)endifelsealpha0=0if (valuesHigh > valuesHigh[1]) thenvaluesHigh = valuesHigh[1]endifif trend[1]<0 thenoutputs1 = valuesHighoutputs0 = valueslowalpha1 = 255elsedrawtext("●",barindex,valueshigh,dialog,bold,22) coloured(255,0,0)endifendifreturn outputs0 coloured(65,105,225,alpha0) style(line,4), outputs1 coloured(255,0,0,alpha1) style(line,4)11/09/2020 at 6:34 PM #14993611/10/2020 at 10:45 AM #150001Il s’agit d’un principe assez répandu de HiLo switch, si le prix tombe en dessous d’une bande alors on switch sur l’autre et vice-versa. Une autre version répandue avec les bandes de Bollinger : BBands stop
11/11/2020 at 11:11 AM #15010211/11/2020 at 11:12 AM #15010511/11/2020 at 4:00 PM #150143doble desviación privada = 0,1 ;
Nicolas il y a une petite erreur dans Déviation = 0.01
123456789101112131415161718192021222324252627282930313233343536373839404142434445<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">timePeriod = 14</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">Desviación = 0,1</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">precio = personalizadoclose</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">dsma = WeightedAverage [timePeriod] (precio)</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">valuesLow = (1 - desviación / 100) * dsma</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">valores Alto = (1 + desviación / 100) * dsma</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">insumos = precio</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">si (entradas> valores alto) entonces </span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">tendencia = 1</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">elsif (input <valuesLow) luego</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">tendencia = -1</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">terminara si</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">si (tendencia> 0) entonces </span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">alpha1 = 0</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">si (valuesLow <valuesLow [1]) entonces</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">valuesLow = valuesLow [1]</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">terminara si</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">si la tendencia [1]> 0 entonces </span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">salidas0 = valoresBajo</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">salidas1 = valores alto</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">alpha0 = 255</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">más</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">drawtext ("●", barindex, valueslow, dialog, bold, 22) coloreado (65,105,225)</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">terminara si</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">más </span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">alpha0 = 0</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">if (valuesHigh> valuesHigh [1]) entonces</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">valuesHigh = valuesHigh [1]</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">terminara si</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">si la tendencia [1] <0 entonces </span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">salidas1 = valores Alto</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">salidas0 = valores bajo</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">alpha1 = 255</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">más</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">drawtext ("●", barindex, valueshigh, dialog, bold, 22) coloreado (255,0,0)</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">terminara si </span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">terminara si</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">devuelve salidas0 color (65,105,225, alpha0) estilo (línea, 4), salidas1 color (255,0,0, alpha1) estilo (línea, 4)</span></span>11/11/2020 at 4:09 PM #150145123456789101112131415161718192021222324252627282930313233343536373839404142434445timePeriod=14Deviation=0.1price=customclosedsma = WeightedAverage[timePeriod](price)valuesLow = (1 - deviation / 100) * dsmavaluesHigh = (1 + deviation / 100) * dsmainputs=priceif (inputs > valuesHigh) thentrend = 1elsif (inputs < valuesLow) thentrend = -1endifif (trend > 0) thenalpha1=0if ( valuesLow < valuesLow[1]) thenvaluesLow = valuesLow[1]endifif trend[1]>0 thenoutputs0 = valuesLowoutputs1 = valueshighalpha0 = 255elsedrawtext("●",barindex,valueslow,dialog,bold,22) coloured(65,105,225)endifelsealpha0=0if (valuesHigh > valuesHigh[1]) thenvaluesHigh = valuesHigh[1]endifif trend[1]<0 thenoutputs1 = valuesHighoutputs0 = valueslowalpha1 = 255elsedrawtext("●",barindex,valueshigh,dialog,bold,22) coloured(255,0,0)endifendifreturn outputs0 coloured(65,105,225,alpha0) style(line,4), outputs1 coloured(255,0,0,alpha1) style(line,4) -
AuthorPosts
Viewing 12 posts - 1 through 12 (of 12 total)
Find exclusive trading pro-tools on
Similar topics: