Need help in writing Code to find the before price of the current BID/ASK price.

 

Hi all:


I am too new to MQL4 programming. Having problem with my program. I do appreciate if anyone can assist me.


1. I wish to find the before price of the current BID/ASK price. I do not know which code shall i use. Price_OPEN or Open[1]? The before price and BID price is within then same bar.

2. Is that any different between MODE_ASK/MODE_BID and ASK/BID? Are they showing the same number?


Thank you so much.


Have a great day ahead.


regards,

miki

 
miki308:

Hi all:


I am too new to MQL4 programming. Having problem with my program. I do appreciate if anyone can assist me.


1. I wish to find the before price of the current BID/ASK price. I do not know which code shall i use. Price_OPEN or Open[1]? The before price and BID price is within then same bar.

2. Is that any different between MODE_ASK/MODE_BID and ASK/BID? Are they showing the same number?


Thank you so much.


Have a great day ahead.


regards,

miki

What does before price mean: the price of the previous bar or the previous tick?

 

he said this : "The before price and BID price is within then same bar." so I dont think its the previous bars data he wants....this is an odd request.

 

Hi gekko,117 & all:

Good day. My apologize, the "before price" mean the price of the "previous tick". Sorry for the mistake.

I wish to get the price different between "current tick" and "previous tick",

Please kindly advice how shall i do it? Thank you.

regards,

miki

 
ggekko wrote >>

What does before price mean: the price of the previous bar or the previous tick?

Hi gekko,117 & all:

Good day. My apologize, the "before price" mean the price of the "previous tick". Sorry for the mistake.

I wish to get the price different between "current tick" and "previous tick",

Please kindly advice how shall i do it? Thank you.

regards,

miki

 
miki308 wrote >>

Hi gekko,117 & all:

Good day. My apologize, the "before price" mean the price of the "previous tick". Sorry for the mistake.

I wish to get the price different between "current tick" and "previous tick",

Please kindly advice how shall i do it? Thank you.

regards,

miki

There is no specific command for doing what you want. So, what you have to do is keep track of each tick that you want to know about. Your EA will execute each time a new tick comes in. So you should place a command somewhere in your EA that saves the Bid and/or Ask price to a variable that you can use the next time you get a new tick. If you're using an EA to do this then your EA needs to execute quickly to be affective. Otherwise you will miss some ticks while you are in your EA loop. If you use an indicator it will re-start each time it gets a new tick whether it finished the last execution or not. So if you put this kind of code in an indicator then it should be right at the beginning of the Start() section so you catch each tick quickly.

- Tovan

 
tovan:

There is no specific command for doing what you want. So, what you have to do is keep track of each tick that you want to know about. Your EA will execute each time a new tick comes in. So you should place a command somewhere in your EA that saves the Bid and/or Ask price to a variable that you can use the next time you get a new tick. If you're using an EA to do this then your EA needs to execute quickly to be affective. Otherwise you will miss some ticks while you are in your EA loop. If you use an indicator it will re-start each time it gets a new tick whether it finished the last execution or not. So if you put this kind of code in an indicator then it should be right at the beginning of the Start() section so you catch each tick quickly.

- Tovan

Tovan's solution is great.

Here is a little sample for an EA:

double tick_now, tick_prev=0.0;

int start()
   {

   tick_now=Bid;

   if(tick_now>tick_prev)
      {
      // ... calculations, order execution, etc.
      }

   tick_prev=tick_now;

   }
Cheers
 

Hi Tovan & ggekko:


Thank you so much for the great help. I truly appreciate this. This mean a lots for a beginner like me. I will try to work with it. Thanks a lots.


Have a great day ahead.


regards,

miki

 
tovan:

There is no specific command for doing what you want. So, what you have to do is keep track of each tick that you want to know about. Your EA will execute each time a new tick comes in. So you should place a command somewhere in your EA that saves the Bid and/or Ask price to a variable that you can use the next time you get a new tick. If you're using an EA to do this then your EA needs to execute quickly to be affective. Otherwise you will miss some ticks while you are in your EA loop. If you use an indicator it will re-start each time it gets a new tick whether it finished the last execution or not. So if you put this kind of code in an indicator then it should be right at the beginning of the Start() section so you catch each tick quickly.

- Tovan

With respect: Please supply supporting documentation on this as I have never read anywhere that an indicator will be chopped in mid flow. tbh, that implies that in the extreme bounds, an indicator would never do it's job as it would be constantly interrupted. If I have missed such an important detail [which of course we all can do :] I would like to 'get it right' since this, for me, is a massive shift from my current knowledge base. Thanx.

At incoming of new quotes, the start() function of the attached experts and custom indicators will be executed. If the start() function launched at the preceding quote was running when a new quote came, the new quote will be skipped by the expert. All new quotes income while the program was being executed are skipped by the program until the current execution of the start() function has been completed. After that, the start() function will be run only when a successive new quote incomes. For custom indicators, the start() function will be launched for recalculation after the current chart symbol or timeframe has been changed independently on new quotes incoming. The start() function will not be run when the expert properties window is open. The latter cannot be opened during the expert execution.

 
fbj wrote >>

With respect: Please supply supporting documentation on this as I have never read anywhere that an indicator will be chopped in mid flow. tbh, that implies that in the extreme bounds, an indicator would never do it's job as it would be constantly interrupted. If I have missed such an important detail [which of course we all can do :] I would like to 'get it right' since this, for me, is a massive shift from my current knowledge base. Thanx.

Hi Fred,

Now you've put me in a spot. I can't remember where I read that and can't seem to find anything that supports what I said. So perhaps I'm mistaken? The paragraphs you quote above are fairly clear about EA's and tend to backup what I said, but they fail to finish with specific information on Indicators.

I wonder if anyone else who is following this thread knows what the answer is? If an indicator is still calculating when a new tick comes in does it skip that tick or does it stop calculating and start over?

- Tovan

 

Tovan -

Well... not trying to cause mental unrest or have knives hurled at me - lol, your post put me into tailspin for sure, ya know? Shaky foundation stones are not what's needed when programming ;)

What can i say... this has been an enlightening R&D session, I hope others feel the same :)

.

further to my last post, the brain keeps ticking...

1. An indicator is a program with a as it were, predefined list of actions required to be done to completion prior to it fullfilling it's life purpose.

eg, to be cut off in it's prime... it would not do the to completion thing 'all the time' and additionally, there would be no warranty as to when or if or how often this cut off would happen.

2. Being a program, it is legal for it to have persistent memory ie, state memory/program global scoped identifiers.

Think what would happen if these state datums were never warranted to have a consistent value - this would happen if indicator was summarily cut off - at any time.

ie, the indicators results would certainly be interesting I'd of thot... ;)

3.

. okaaay, i went walk about and got well and trully into stuff not fully read. Maybe you like? I did cuz not often these days spend read time - just sweat time over keyboard+MQL :-O)

.

ref: https://book.mql4.com/samples/icustom
search for: For the implementation of the described technology there is a very useful standard
function in MQL4 - IndicatorCounted()
why? notice a bit further into this section, the timing charts + supporting text...

ref: https://book.mql4.com/samples/icustom
search for: There are some limitations in MQL4 that should be taken into account in the programming
of custom indicators.
why? "This is also why algorithms based on looping cannot be used in custom indicators. Start of a
custom indicator containing an endless loop (in terms of actual execution time) can result in client
terminal hanging up with further necessity to restart a computer."

ref: https://book.mql4.com/basics/programms#Tabl_17
why? well.. I just got into reading, tbh, not read this stuff before so is interesting...

ref: https://book.mql4.com/basics/programms
search for: Expert Advisor and custom indicator. Once you have attached a program
why? this section [should you want to agree] will answer in more succint way what the editor docs
doing. (uggg, those ed docs are bane of my life -lol)


am off to do my futile daily drill of exercising and then a bit of chow - then back to the keyboard cuz getting deeeeesperate in the financial arena! This is not good at my age. Pulse+heart just not like the current global situation - LOL ??


take care Tovan