Dieter Daniel: Is there any way to code the Bid price that was like 3, 5 , 10 , 20 seconds ago ? ( I mean in less than a minute ).
-
Yes.
How To Ask Questions The Smart Way. 2004
Only ask questions with yes/no answers if you want "yes" or "no" as the answer. - Store each tick with Bid and timestamp. Use the timestamp to find the Bid you want. Not compiled, not tested, just typed.
struct Price{ double price; datetime when; void set(double p, datetime w){ price=p; datetime when=w; } }; class Ticks{ public: Ticks(uint anLB=999) : miLast(0), mkLookback(anLB){ Arrayresize(mValues, anLB); add_value(Bid, 0); } void add_value(double aValue, datetime aWhen){ miLast = (miLast+1) % mkLookback; mValues[miLast].set(aValue, aWhen); } double get_price(datetime when){ return mValues[get_index(when)].price; } uint get_index(datetime when){ uint iVal = miLast; while(mValue[iVal].when > when) iVal = (iVal + mkLookback - 1) % mkLookback; return iVal; } private: Price mValues[]; uint miLast; uint mkLookback; }; void OnTick(){ datetime now = TimeCurrent(); static Ticks bids; bids.add_tick(Bid, now); double bid10sec = bids.get_price(now - 10); ⋮
Not compiled, not tested, just typed.
Thanks for the kind answer Mr.William. There is something I don't seem to get.
1. What is anLB?
(uint anLB=999)
2. Do the uint values in the code below have to be external global variables?
private: Price mValues[]; uint miLast; uint mkLookback;
Thanks in advance.
P-S: Sorry for the "stupid questions" I ask, just new in coding.
- Argument number lookback. You define how many entries you need when you create the static/global class variable; a thousand should be plenty.
- They are member variables of the class.
Now I get everything. Works wonderful, thanks !!!
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Is there any way to code the Bid price that was like 3, 5 , 10 , 20 seconds ago ? ( I mean in less than a minute ).
Honestly, I found something similar, but coded in the old mq4 language, here:
https://www.mql5.com/en/forum/121764
But what I've found doesn't work in nowadays mq4 language.
Can you help me restore this piece of code:
Thanks very much!
Sincerely,
Dieter Daniel