- Programming Help - Avoid opening the trade in the same price as already opened trades
- is there a pivot point indicator with adjustable time settings?
- adding to array
"I want to define a variable which is dependent of the same variable one period ago, but I have absolutely no idea how to do that. I already tried it with an array and a loop, but somehow it doesn`t work "
"It doesn't work" doesn't give much to go on.
Show your code.
Hi phy.
I tried it with the following code:
int counted_bars=IndicatorCounted(); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=0; i<limit; i++) { adEMA1[i]=alpha1*admacd_vol*Close[i]+(1-alpha1*admacd_vol)*adEMA1[(i-1)]; adEMA2[i]=alpha2*admacd_vol*Close[i]+(1-alpha1*admacd_vol)*adEMA2[(i-1)]; adjMACD[i]=adEMA1[i]-adEMA2[i]; } Print(adjMACD[i]);But I just receive the value 0, which in my opnion can't be correct, because adEMA1(i) and adEMA2(i) without the lagging adEMA(i-1) & adEMA2(i-1) results in a "normal" value.
Show more code.
"without the lagging adEMA(i-1) & adEMA2(i-1) "
Those would be adEMA(i+1) & adEMA2(i+1)
if you are talking about bars that came before the bar specified by "i"
You probably want to run the loop from limit to 0, not from 0 to limit...
"without the lagging adEMA(i-1) & adEMA2(i-1) "
Those would be adEMA(i+1) & adEMA2(i+1)
if you are talking about bars that came before the bar specified by "i"
You probably want to run the loop from limit to 0, not from 0 to limit...
Hi phy.
Thanks for your help!!
this is the whole code for this function:
int adMACD() { double adEMA1[]; double adEMA2[]; double adjMACD[]; int EMA1n=12; //Periodenanzahl für den ersten EMA int EMA2m=26; //Periodenanzahl für den zweiten EMA double alpha1=(2/(EMA1n+1)); //Alpha-Parameter 1 double alpha2=(2/(EMA2m+1)); //Alpha-Parameter 2 double admacd_stdev10=iStdDev(NULL,0,10,1,MODE_EMA,PRICE_CLOSE,0); double admacd_stdev50=iStdDev(NULL,0,50,1,MODE_EMA,PRICE_CLOSE,0); double admacd_stdev10_1=iStdDev(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,1); //Um 1 Periode adjustiert double admacd_stdev50_1=iStdDev(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1); //Um 1 Periode adjustiert int limit; if(adMACD==false) { double admacd_vol=(admacd_stdev10/admacd_stdev50); double admacd_vol_1=(admacd_stdev10_1/admacd_stdev50_1); //Um 1 Periode adjustiert int counted_bars=IndicatorCounted(); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=0; i<limit; i++) { adEMA1[i]=alpha1*admacd_vol*Close[i]+(1-alpha1*admacd_vol)*adEMA1[(i-1)]; adEMA2[i]=alpha2*admacd_vol*Close[i]+(1-alpha1*admacd_vol)*adEMA2[(i-1)]; adjMACD[i]=adEMA1[i]-adEMA2[i]; } Print(adjMACD[i]);
By every tick, I would like to have the new value of adjMACD(1).Therefore I have to calculate the value of adEMA1 and adEMA2 every tick. The problem is the variable adEMA1(i-1) and adEMA2(i-1), which should have the value of adEMA of the last period (eg. the last day). I thought I could program this with a loop, but with this method I don't get an accurate value for adjMACD (always 0). That`s why I think it's wrong.
(And sorry for my programming style, I am very new to it and try to learn it)
Best regards & thanks for your help
paci
You did not specify a size for your arrays. Without that definition, the results can be unpredicatable.
example:
double adEMA1[];
could be
double adEMA1[100];
if you need to store no more than 100 values
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use