I get multiple prints for one daily candle, sometimes even 15 prints at random time stamps for the same day

 

I am new to MQL,

I have done some codes, it runs, but not as expected.

Can you guide me on my study.

For example:

I want to code to analyze history data of "daily" chart, print data onto journal so that I can read the numbers to verify.

I did this:

"

Print(Open[0]," ",Close[0]," ",High[0]," ",Low[0]," ",Ask," ",Bid);

"

My problem, I get multiple prints for one daily candle, sometimes even 15 prints at random time stamps for the same day. Why so many prints for one daily candle? I can't figure out. Logically we should get only 1 print per day right!


If I got to do some setting please advice, because without getting to understand this I can't any further.


Adding to that, lets say i want to study from 2008/08/22 to 2008/09/22, the journal do not stop on the last date, it keeps filling at different time stamp for the same day, probably it is linked to my earlier problem.


Please help me, earlier on of our member tried helping but, he may be taking a break due to time difference, please help, thanks.


Thanks
 
datetime barTime; // global variable
 
int start() {
    ...
    if( barTime < Time[0] ) {
        // we have a new bar opened
        barTime = Time[0]; // keep the new bar open time
        ...<do whatever you want with the new bar>
    }
    ...
}

above - is on 'this' site.

it is telling u many things.

0. u know how use any other block structured program language? - if YES then u in essence KNOW how use MQL4 syntax! if NO - u must say u not know programming BUT want learn...

1. u have heard about Data Tics

2. a 'bar' can be made of many Data Tics

3. IF not want process Data Tics that make up 'bar' THEN u must ignore them

4. how do this? above is template for how to do this...

.

see line "<do whatever you want with the new bar>" ?

.

replace line with:

Print(Open[0]," ",Close[0]," ",High[0]," ",Low[0]," ",Ask," ",Bid);

.

Now... watevr timeframe - the Print() will only ever execute when FIRST DATA TIC of a *new bar*

ie, Bar[1] has 'just' completed and now Bar[0] is beginning. This Bar[0] will have maybe many Data Tics but your code WILL NOT print UNTIL 'next' *new bar*

.

please, u take below, put into editor and compile INTO ...\experts dir and then u select M1 on chart > drag expert/attach/run on this chart.

take few mins and WATCH Experts tab in Terminal window below chart.

1. code MUST be 'kicked' into life *first time* and since it has no knowledge of barTime except time of zero, the *first time* code WILL PRINT when Broker server sends data tic to Terminal client.

no biggie - code has now loaded valid time into barTime.

Do u know bout Time[] series array?

no? then learn about it

now, u see that Time[] array *only* holds Bar Open time - this is important to remember.

yes, get maybe many Data Tics per Bar... BUT there is only one first tic!

this first tic has a time - the new bar time and it is this value that goes into Time[0] and this has now been 'remembered' in barTime

Now... regardless how many Data Tics come to Terminal Client and then to your EA, Time[0] NEVER EVER CHANGES *until* Data Tic is *first* Data Tic of a NEW bar.

this mean that if( barTime < Time[0] ) *not TRUE* is false - means code between {..} never ever executed.

anyway - nuff talki talki, u must run as suggested above.

FORGET ABOUT TESTER - for moment, look and learn how and why code is working!

so important to understand some basics of wat going on... - tester not go away :)

See next example Print() to Expert tab:

.

2. see red seconds of 30 and 38 at begin of run?

well... Terminal Client NOT GET Data Tic from Broker Server for these 8 seconds and then at 2008.10.23 11:56:38 Data Tic incoming = EA 'kicked' into life *first time*

.

3. get it in mind... now go play with tester using any timeframe want and the same type thing be printed as below

BUT not have BIG test window of bars cuz eg, M1 or M15 ... will be MANY and so MANY prints :o)

.

.

2008.10.23 12:13:26 _quicky_EXPERT EURUSD,M1: 1.2811 1.2811 1.2811 1.2811 1.2813 1.2811
2008.10.23 12:12:34 _quicky_EXPERT EURUSD,M1: 1.2812 1.2812 1.2812 1.2812 1.2814 1.2812
2008.10.23 12:11:28 _quicky_EXPERT EURUSD,M1: 1.2808 1.2808 1.2808 1.2808 1.281 1.2808
2008.10.23 12:10:22 _quicky_EXPERT EURUSD,M1: 1.2806 1.2806 1.2806 1.2806 1.2808 1.2806
2008.10.23 12:09:26 _quicky_EXPERT EURUSD,M1: 1.2808 1.2808 1.2808 1.2808 1.281 1.2808
2008.10.23 12:08:31 _quicky_EXPERT EURUSD,M1: 1.2808 1.2808 1.2808 1.2808 1.281 1.2808
2008.10.23 12:07:21 _quicky_EXPERT EURUSD,M1: 1.2808 1.2808 1.2808 1.2808 1.281 1.2808
2008.10.23 12:06:22 _quicky_EXPERT EURUSD,M1: 1.281 1.281 1.281 1.281 1.2812 1.281
2008.10.23 12:05:21 _quicky_EXPERT EURUSD,M1: 1.2805 1.2805 1.2805 1.2805 1.2807 1.2805
2008.10.23 12:04:24 _quicky_EXPERT EURUSD,M1: 1.2802 1.2802 1.2802 1.2802 1.2804 1.2802
2008.10.23 12:03:21 _quicky_EXPERT EURUSD,M1: 1.2795 1.2795 1.2795 1.2795 1.2797 1.2795
2008.10.23 12:02:21 _quicky_EXPERT EURUSD,M1: 1.2802 1.2802 1.2802 1.2802 1.2804 1.2802
2008.10.23 12:01:21 _quicky_EXPERT EURUSD,M1: 1.2806 1.2806 1.2806 1.2806 1.2808 1.2806
2008.10.23 12:00:22 _quicky_EXPERT EURUSD,M1: 1.2805 1.2805 1.2805 1.2805 1.2807 1.2805
2008.10.23 11:59:21 _quicky_EXPERT EURUSD,M1: 1.2806 1.2806 1.2806 1.2806 1.2808 1.2806
2008.10.23 11:58:20 _quicky_EXPERT EURUSD,M1: 1.2806 1.2806 1.2806 1.2806 1.2808 1.2806
2008.10.23 11:57:26 _quicky_EXPERT EURUSD,M1: 1.2804 1.2804 1.2804 1.2804 1.2806 1.2804
2008.10.23 11:56:38 _quicky_EXPERT EURUSD,M1: 1.2806 1.2805 1.2807 1.2805 1.2807 1.2805
2008.10.23 11:56:30 _quicky_EXPERT EURUSD,M1: initialized
2008.10.23 11:56:25 _quicky_EXPERT EURUSD,M1: loaded successfully
2008.10.23 11:55:54 Compiling '_quicky_EXPERT'

wow... red where not want - never mind!

datetime barTime=0; // global variable
//-----
int init()
{
  return(0);
}
//-----
int deinit()
{
  return(0);
}
//-----
int start()
{
  if( barTime < Time[0] )
  {
    //ONLY get here IF *new bar*
    // we have a new bar opened
    barTime = Time[0]; // keep the new bar open time
    //now we do ALL new bar work...
    Print(Open[0]," ",Close[0]," ",High[0]," ",Low[0]," ",Ask," ",Bid);
  }
  return(0);  //exit EA back to Terminal
}
 

FBJ,

I thank you for your time to explain in such detial.

OK, Each candle has n number of ticks in it. Thus I got the n number of entries each with different time stamp even for daily chart.

In such case, lets say in real time, how should I trigger an order (after positive validation of a rule), I am confused due to non stop in coming of ticks, please give me an example order trigger statement, with “blablablabla” validation rule. I am confused because in real life trading, I use intuition, thus it is not discrete in nature. But I want to execute immediately after validating on the recently closed candle.

I am not a paranoid, but just want to get in a bit deeper, you mentioned

Print() will only ever execute when FIRST DATA TIC of a *new bar*

ie, Bar[1] has 'just' completed and now Bar[0] is beginning. This Bar[0] will have maybe many Data Tics but your code WILL NOT print UNTIL 'next' *new bar*

If so, the Bar[0] is incomplete at the time of print, so your code only prints Bar[1] when Bar[0] starts right. Thus even the FIRST print will only happen after the completion of Bar[0]. BUT we are explicitly asking for Close[0] thus what gets printed 0 or 1.

What I actually want is the details of the bar on complete completion. By using Time[0] I think we are using first tick value but not the completed candle info, please correct me or can we twitch the code a bit.

Additionally it is ok if you explain int init() and int deinit(), till date I have never used it.
 

FBJ,

Do you think you can reply me before you go offline.

 

ok -

FBJ,

I thank you for your time to explain in such detial.

--well, i sometimes get help too and is always liked so i try 'sometimes' umm - oh yes, "pass it on"!

.

OK, Each candle has n number of ticks in it. Thus I got the n number of entries each with different time stamp even for daily chart.

--yes

.

In such case, lets say in real time, how should I trigger an order (after positive validation of a rule), I am confused due to non stop in coming of ticks, please give me an example order trigger statement, with “blablablabla” validation rule. I am confused because in real life trading, I use intuition, thus it is not discrete in nature. But I want to execute immediately after validating on the recently closed candle.

I am not a paranoid, but just want to get in a bit deeper, you mentioned

Print() will only ever execute when FIRST DATA TIC of a *new bar*

ie, Bar[1] has 'just' completed and now Bar[0] is beginning. This Bar[0] will have maybe many Data Tics but your code WILL NOT print UNTIL 'next' *new bar*

If so, the Bar[0] is incomplete at the time of print,

--yes

.

so your code only prints Bar[1] when Bar[0] starts right.

--no, is data for [0] - cuz we are at the transition from 'last or ending tic' of the 'last Bar[0]' AND the 'first data tic of new Bar[0]' (meaning last Bar[0]+last tic -> Bar[1])

Code compares the saved/remembered (aka: barTime) Time[0] *of last bar -> the old just completed bar*, against the Time[0] or *first data tic* of new in building state bar. (remember: is ONLY time that bar time changes, only have one open time for a bar)

sumry: bar has y tics and on y+1 tics it now morfs to [1] and this y+1th tic is first tic of new [0] - this is also when Time[0] changes.

do test: u put print in that prints barTime AND Time[1] and do this befor u update barTime. this demonstrate how wat was Time[0] has now gone to Time[1] cuz u remembered Time[0] *first data tic* time in barTime. I expect to see they equal times... oh boy, if not i give up!

.

only 'last or ending price tic' u can grab is Close[1] eg, bar timeframe sees 9 data tics incoming. tic.1 is wat Time[0] and Open[0] use. Tics.2,..,8 are wat C,H,L,V[0] use. Tic.9 is the *final* Close[0] and so is the Bar's Close price and guess Volume[0] also like wat just say to, cuz Vol can alter each tic incomming... as for H,L[0] depends on all 9tics, maybe same as Close or watever...

.

as u see now, is in a 'building' state, getting tics as server sends them. Print shows OCHL[0] of this 'in a building' state Bar[0] - *on first data tic of this new bar forming*

but... Open[0] like Time[0] are in a way special - cuz they can ONLY have data from *first data tic* of Bar[0]. u know? only one open price - one open time...

Close,High,Low may change *every* data tic incoming - cuz reflect realtime market prices *at the moment* and Open,Time are not *at the moment* datums except for FIRST new bar in a building state data tic...

Ask,Bid is showing u current tic's data and is also wat prices u use to OrderSend(): Bid if selling, Ask if buying. MUST be most recent when OrderSend() else get error 129 invalid price.

maybe i confuse u and me... Code prints current tic's data associated with 'in a building' state Bar[0].

if want the LAST complete bar that has ALL data - this is Bar[1] and befor that is Bar[2]...all way back to history start/oldest bar which is Bar[Bars-1] (Bars, is one of 11 predefined values maintained by Terminal for the EA attached/default chart. eg, Digits, Point, Ask, Bid, etc. Please look help: MQL4 Reference - Predefined variables)

[0] is always the 'in a building' state bar datum series array element.

MANY traders work with COMPLETE BARS only - meaning [1],[2],..[Bars-1] and... u have template for 'knowing' when a bar has JUST completed, yes?

MANY traders use 'in building state' Bar[0] - specifically Close[0], for TakeProfit and StopLoss and vip is TrailingStop, workings - cuz wanna mess with LATEST price - is vip! u know? as Close price of building bar 'could' be lots diff and impact on profit (or loss :) and if still 'in trade' wanna keep that TrailingStop uptodate to lock in profit (using OrderModify())

oh boy - i get confused, maybe u 'get it' - me? i go back school i think -lol

.

Thus even the FIRST print will only happen after the completion of Bar[0]. BUT we are explicitly asking for Close[0] thus what gets printed 0 or 1.

yes and no, think about bar transition when first tic of new bar incomes. at that moment [0] becomes [1] so any refs to [0] must be for in building state just started new bar ie Bar[0]/Close[0]

.

lets see, EA attached to chart, init() called and returns and NOW... Terminal NOT call start() why? cuz needs data tic from broker, ok? 'when' that happens is 'at any time'...

is TOTAL chance - EA could run and be 'ready to run' (ie, init() done and so EA is in a 'go state' :) 'at any time'. eg, 9 data tics gonna make up current in building state bar, maybe 'go state' happens at tic 5. Well... so Terminal receives next server data tic - tic.6 and 'sees' that got EA for sympair+timeframe in a 'go state' so then... it calls this EAs start() and away it goes.

.

Remember this is FIRST time start() entered and barTime is 0 = no time. Ok, is tic.6 of Bar[0] and got tics 7,8,9 left (in future) and for sure is not end of Bar[0] BUT... EA not know that! cuz when do compare of barTime with Time[0] it gonna be comparing 0 < Time[0] and of course we know that Time[0] gonna equal time of tic.1 of currently in build state Bar[0], yes?

.

Wat happen? u see it? code block gonna be entered and ALL [0]'s,Bid and Ask gonna relate to the *in build state* Bar[0].

Open[0] = O of tic.1 and C,H,L,Bid,Ask gonna be whatever 'current' values as given in tic.6 or of course watevr lowest/highest for all up to now received tics for this forming bar...

.

so why i say: EA runs, no control when it runs with ref to tic# of current in build state bar[0]

oh i answer? forget anyway u can work it out now, yes?

.

What I actually want is the details of the bar on complete completion. By using Time[0] I think we are using first tick value but not the completed candle info, please correct me or can we twitch the code a bit.

yes, is FIRST tic of NEW BAR. twitch = use [1] = What I actually want is the details of the bar on complete completion

.

Additionally it is ok if you explain int init() and int deinit(), till date I have never used it.

.

i have in a way, given ideas on init() and deinit() is just the other end when EA stopped by Terminal. Think "cleanup". like maybe u got data in arrays/buffers and must write to disk file or even FileClose() or maybe save EA current state in file or Terminal Global variables or print "asta la vista baby" or whatever ok?

and... by same token, init() is composed of operations/MUST-DO's *once only* b4 main body/start() starts getting called - like open files, vip job could be to be data validation cuz users can always put in EA inputs that if used, gonna CRASH ea or maybe wipe out a/c... ;) maybe, open log file and write header to it, you know? any job that is like beginnings of new day... put clothes on, eat some fuel, brush teeth, throw cat and dog outside... ONLY need do once yes? now u ready to do your thing all day eg, start() ready for action!

deinit() same idea but at end of day. mop up jobs like cat/dog mess :), feed self and maybe them too....

all analogus to life or whatever - lead in tasks for job > do job > final job complete tasks == init() > start() > deinit()

.

please do look at MQL4 book cuz it have ALL and more coming from those that know - please give me break!

and... they do pretty pictures and make more sense!

bye

:)

 

Hello,

A survey is conducted in the context of the evolution of Expert Advisors.

Less than 2 minutes are needed to complete the form.

You will be automatically registered in a draw for an iPhone 16GB.

The results may be published on MorningNews.com & FinancialTimes.com

To participate: http://expertadvisor.questionform.com/public/Expert-Advisor
 
fbj:

ok -

FBJ,

I thank you for your time to explain in such detial.

--well, i sometimes get help too and is always liked so i try 'sometimes' umm - oh yes, "pass it on"!

.

OK, Each candle has n number of ticks in it. Thus I got the n number of entries each with different time stamp even for daily chart.

--yes

.

In such case, lets say in real time, how should I trigger an order (after positive validation of a rule), I am confused due to non stop in coming of ticks, please give me an example order trigger statement, with “blablablabla” validation rule. I am confused because in real life trading, I use intuition, thus it is not discrete in nature. But I want to execute immediately after validating on the recently closed candle.

I am not a paranoid, but just want to get in a bit deeper, you mentioned

Print() will only ever execute when FIRST DATA TIC of a *new bar*

ie, Bar[1] has 'just' completed and now Bar[0] is beginning. This Bar[0] will have maybe many Data Tics but your code WILL NOT print UNTIL 'next' *new bar*

If so, the Bar[0] is incomplete at the time of print,

--yes

.

so your code only prints Bar[1] when Bar[0] starts right.

--no, is data for [0] - cuz we are at the transition from 'last or ending tic' of the 'last Bar[0]' AND the 'first data tic of new Bar[0]' (meaning last Bar[0]+last tic -> Bar[1])

Code compares the saved/remembered (aka: barTime) Time[0] *of last bar -> the old just completed bar*, against the Time[0] or *first data tic* of new in building state bar. (remember: is ONLY time that bar time changes, only have one open time for a bar)

sumry: bar has y tics and on y+1 tics it now morfs to [1] and this y+1th tic is first tic of new [0] - this is also when Time[0] changes.

do test: u put print in that prints barTime AND Time[1] and do this befor u update barTime. this demonstrate how wat was Time[0] has now gone to Time[1] cuz u remembered Time[0] *first data tic* time in barTime. I expect to see they equal times... oh boy, if not i give up!

.

only 'last or ending price tic' u can grab is Close[1] eg, bar timeframe sees 9 data tics incoming. tic.1 is wat Time[0] and Open[0] use. Tics.2,..,8 are wat C,H,L,V[0] use. Tic.9 is the *final* Close[0] and so is the Bar's Close price and guess Volume[0] also like wat just say to, cuz Vol can alter each tic incomming... as for H,L[0] depends on all 9tics, maybe same as Close or watever...

.

as u see now, is in a 'building' state, getting tics as server sends them. Print shows OCHL[0] of this 'in a building' state Bar[0] - *on first data tic of this new bar forming*

but... Open[0] like Time[0] are in a way special - cuz they can ONLY have data from *first data tic* of Bar[0]. u know? only one open price - one open time...

Close,High,Low may change *every* data tic incoming - cuz reflect realtime market prices *at the moment* and Open,Time are not *at the moment* datums except for FIRST new bar in a building state data tic...

Ask,Bid is showing u current tic's data and is also wat prices u use to OrderSend(): Bid if selling, Ask if buying. MUST be most recent when OrderSend() else get error 129 invalid price.

maybe i confuse u and me... Code prints current tic's data associated with 'in a building' state Bar[0].

if want the LAST complete bar that has ALL data - this is Bar[1] and befor that is Bar[2]...all way back to history start/oldest bar which is Bar[Bars-1] (Bars, is one of 11 predefined values maintained by Terminal for the EA attached/default chart. eg, Digits, Point, Ask, Bid, etc. Please look help: MQL4 Reference - Predefined variables)

[0] is always the 'in a building' state bar datum series array element.

MANY traders work with COMPLETE BARS only - meaning [1],[2],..[Bars-1] and... u have template for 'knowing' when a bar has JUST completed, yes?

MANY traders use 'in building state' Bar[0] - specifically Close[0], for TakeProfit and StopLoss and vip is TrailingStop, workings - cuz wanna mess with LATEST price - is vip! u know? as Close price of building bar 'could' be lots diff and impact on profit (or loss :) and if still 'in trade' wanna keep that TrailingStop uptodate to lock in profit (using OrderModify())

oh boy - i get confused, maybe u 'get it' - me? i go back school i think -lol

.

Thus even the FIRST print will only happen after the completion of Bar[0]. BUT we are explicitly asking for Close[0] thus what gets printed 0 or 1.

yes and no, think about bar transition when first tic of new bar incomes. at that moment [0] becomes [1] so any refs to [0] must be for in building state just started new bar ie Bar[0]/Close[0]

.

lets see, EA attached to chart, init() called and returns and NOW... Terminal NOT call start() why? cuz needs data tic from broker, ok? 'when' that happens is 'at any time'...

is TOTAL chance - EA could run and be 'ready to run' (ie, init() done and so EA is in a 'go state' :) 'at any time'. eg, 9 data tics gonna make up current in building state bar, maybe 'go state' happens at tic 5. Well... so Terminal receives next server data tic - tic.6 and 'sees' that got EA for sympair+timeframe in a 'go state' so then... it calls this EAs start() and away it goes.

.

Remember this is FIRST time start() entered and barTime is 0 = no time. Ok, is tic.6 of Bar[0] and got tics 7,8,9 left (in future) and for sure is not end of Bar[0] BUT... EA not know that! cuz when do compare of barTime with Time[0] it gonna be comparing 0 < Time[0] and of course we know that Time[0] gonna equal time of tic.1 of currently in build state Bar[0], yes?

.

Wat happen? u see it? code block gonna be entered and ALL [0]'s,Bid and Ask gonna relate to the *in build state* Bar[0].

Open[0] = O of tic.1 and C,H,L,Bid,Ask gonna be whatever 'current' values as given in tic.6 or of course watevr lowest/highest for all up to now received tics for this forming bar...

.

so why i say: EA runs, no control when it runs with ref to tic# of current in build state bar[0]

oh i answer? forget anyway u can work it out now, yes?

.

What I actually want is the details of the bar on complete completion. By using Time[0] I think we are using first tick value but not the completed candle info, please correct me or can we twitch the code a bit.

yes, is FIRST tic of NEW BAR. twitch = use [1] = What I actually want is the details of the bar on complete completion

.

Additionally it is ok if you explain int init() and int deinit(), till date I have never used it.

.

i have in a way, given ideas on init() and deinit() is just the other end when EA stopped by Terminal. Think "cleanup". like maybe u got data in arrays/buffers and must write to disk file or even FileClose() or maybe save EA current state in file or Terminal Global variables or print "asta la vista baby" or whatever ok?

and... by same token, init() is composed of operations/MUST-DO's *once only* b4 main body/start() starts getting called - like open files, vip job could be to be data validation cuz users can always put in EA inputs that if used, gonna CRASH ea or maybe wipe out a/c... ;) maybe, open log file and write header to it, you know? any job that is like beginnings of new day... put clothes on, eat some fuel, brush teeth, throw cat and dog outside... ONLY need do once yes? now u ready to do your thing all day eg, start() ready for action!

deinit() same idea but at end of day. mop up jobs like cat/dog mess :), feed self and maybe them too....

all analogus to life or whatever - lead in tasks for job > do job > final job complete tasks == init() > start() > deinit()

.

please do look at MQL4 book cuz it have ALL and more coming from those that know - please give me break!

and... they do pretty pictures and make more sense!

bye

:)

FBIJ,

Thanks, after talking to you yesterday, i did my homework, I did tried the array levels, yes it works exactly the way mentioned. Yap we tune to the way we want to view and work. OK I will move on to next level.

 

enjoy the trip... is hard, but when usd's seen in account balance - is worth it ALL

Best

Reason: