- florenceale: I can also define it from 1 to 59 using for or while but after few ticks it says "array out of range" 263Show all relevant code. Like your definition of array_price_difference and its context.
array_price_difference[time] = (Bid - open_price)*100000;
Don't hard code constants. Your 100000 breaks on JPY pairs and metals. Divide by _Point instead.- Do you realize that you're not going to get a tick each second, so what you're doing with the array may be bogus. What if there are no ticks during a
specific candle period? There can be minutes between ticks during the Asian
session, think M1 chart.
"Free-of-Holes" Charts - MQL4 Articles
No candle if open = close ? - MQL4 and MetaTrader 4 - MQL4 programming forum
A wrap around buffer may be better:double array_price_difference[60]; int iLast=0; void newTick(void){ array_price_difference[++iLast % 60] = Bid - open_price; } int getDiff(int iTick){ return array_price_difference[(iLast - iTick + 60) % 60]/_Point; }
getDiff(0) is the current value, getDiff(1) is the previous, etc.
i have this:
aopen[0] = iOpen(0,PERIOD_CURRENT,0); //this returns the opening price correctly int time = TimeSeconds(TimeCurrent()); //this returns the number of seconds correcty. Sometime if the trade is very slow we have to consider that some seconds can be skipped cur_var = (Bid - aopen[0])*100000; //and this returns the ticks positive of negative are passed from the beginning of the current candle.
this is the base modifying it with _Point as u said.
my goal now should be to define a period inside the minute, like ten seconds...and understand every ten seconds how big is the tick variation.
- Show all relevant code. Like your definition of array_price_difference and its context.
- Don't hard code constants. Your 100000 breaks on JPY pairs and metals. Divide by _Point instead.
- Do you realize that you're not going to get a tick each second, so what you're doing with the array may be bogus. What if there are no ticks during a
specific candle period? There can be minutes between ticks during the Asian
session, think M1 chart.
"Free-of-Holes" Charts - MQL4 Articles
No candle if open = close ? - MQL4 and MetaTrader 4 - MQL4 programming forum
A wrap around buffer may be better:
Why don't you just create a EMA of the variations:
Not compiled, not tested.
double roc10(void){ static double price[60]; static datetime when[60]; static int iLast=0; datetime now = TimeCurrent(); if(when[iLast] != now){ iLast = (iLast + 1) % 60; when[iLast] = now; } price[iLast] = Bid; static double roc=0; #define SMOOTHING 5 static const double alpha = 2.0 / (SMOOTHING+1); #define SECONDS_BACK 10 int i = (iLast - SECONDS_BACK + 60) % 60; roc += alpha*( (Bid - price[i]) / (now - when[i]) ) return roc; } void OnTick(void){ double roc = rac10();Not compiled, not tested.
Why don't you just create a EMA of the variations:
Not compiled, not tested.
ok ill study a little bit the code you wrote me and ill tell you if i can make it works. Thanks a lot.
maybe is not the most stylish code, i have studied this language from just few weeks...but now it works. I made that it fills the gaps by itself, with the previous values, every second now has a value. I took some idea from yours. Thanks for help
double roc10(void){ static double price[60]; static datetime when[60]; static int iLast=1; static int s; static int tempo_a=0; static int tempo_c[10]; static int dif_tempo; static int old_price; price[0]=(Bid-(iOpen(0,PERIOD_M1,0)))*100000; //tempo_c[0]=0; Print(iOpen(0,PERIOD_M1,0)); if(iLast == 1){ tempo_c[iLast]=TimeSeconds(TimeCurrent()); iLast = 2; dif_tempo = tempo_c[1]-tempo_c[2]; //when we have gaps if(dif_tempo>1){ for(s=1; s <= dif_tempo; s++ ){ price[tempo_c[2]+s]=price[tempo_c[2]]; } } //when go back to beginning with gap if(dif_tempo<0){ for(s=1; s <= tempo_c[1]; s++ ){ price[0+s]=price[0]; } } price[tempo_c[1]]=(Bid-iOpen(0,PERIOD_M1,0))*100000; //Alert("diff: ",dif_tempo," secondi:",tempo_c[1]," prezzo",price[tempo_c[1]]); } if(iLast == 2){ tempo_c[iLast]=TimeSeconds(TimeCurrent()); iLast = 1; dif_tempo = tempo_c[2]-tempo_c[1]; //when we have gaps if(dif_tempo>1){ for(s=1; s <= dif_tempo; s++ ){ price[tempo_c[1]+s]=price[tempo_c[1]]; } } //when goes back to beginning with gap if(dif_tempo<0){ for(s=1; s <= tempo_c[2]; s++ ){ price[0+s]=price[0]; } } price[tempo_c[2]]=(Bid-iOpen(0,PERIOD_M1,0))*100000; //Alert("diff: ",dif_tempo," secondi:",tempo_c[2]," prezzo:",price[tempo_c[2]]); } Print("Tempo:",TimeSeconds(TimeCurrent())," Prezzo:",price[1]," ",price[2]," ",price[3]," ",price[4]," ",price[5]," ",price[6]," ",price[7]," ",price[8]," ",price[9]," ",price[10]," ",price[11]," ",price[12]," ",price[13]," ",price[14]," ",price[15]," ",price[16]," ",price[17]," ",price[18]," ",price[19]," ",price[20]," ",price[21]," ",price[22]," ",price[23]," ",price[24]); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi im trying to create an array with a lenght of 59, where each value stores the tick number second by second.
i have simplified the code here, I can also define it from 1 to 59 using for or while but after few ticks it says "array out of range" 263