How to code nearest round number level?

dsugums
Trader
Posts: 117
Joined: Mon Jan 30, 2012 9:57 pm

How to code nearest round number level?

Post by dsugums »

I have been following a strategy in FF and I like the idea of automating it. I have the shell EA from Steve and pretty much know how tweak it.

My problem is getting the pending order at certain level from current bid price.

For example, if the pa is at 80.130, I want to have a pending order buy at 80.20o for buy and 80.100 for sell.

I am only interested in the XX.100/X.00100 ~ XX.900/X.00900 levels.

Any one can advise me on the coding lines to be incorporated in the shell EA?

Cheers
ds
Image
Image
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

How to code nearest round number level?

Post by SpiderX »

Hi,

maybe the closest reference you can get for your issue is Steve's price action EA:

http://www.stevehopwoodforex.com/phpBB3 ... 389#p94389

Cheers
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

How to code nearest round number level?

Post by SteveHopwood »

Which shell are you using, ds? The one just above AllAverages contains code that identifies the next round/big number, provided originally by George.

:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
dsugums
Trader
Posts: 117
Joined: Mon Jan 30, 2012 9:57 pm

How to code nearest round number level?

Post by dsugums »

I am using the same shell ea as you have coded for me previously. I have all the other conditions implemented in the EA except when it comes to pending order, I have no clue how to get order pending at the next available round number, i.e. price = current bid +/- XXX pips (to make it tenth number).

Anyway, still learning to figure out the coding mystery and did some fair bit on my own to my surprise by looking into other available EA in this forum.

cheers
ds
Image
Image
User avatar
Elixe
Trader
Posts: 98
Joined: Tue Jun 04, 2013 6:44 pm
Location: France

How to code nearest round number level?

Post by Elixe »

I don't have any code or compiler available here, but here's the logic to get to round numbers, you just have to convert that to code that understand Empty4

I though of another possibility while writing this message, I forgot that there was ceil and floor functions available, I did not wanted to delete the first one so you have both logics :

Taking your price of 80.130, that is a 3/5 digits broker. You want to get 80.100 and 80.200.

You need to get rid of 0.030 :

Lets divide our price by the Point value (that is 0.001 for a 3 digits price, but Point is an available var in MQL), you will get an integer representing your price :

80.130 / 0.001 = 80130

To remove the 30 part, you will use a modulo, it will return the remainder of a division :
you want the last 2 digits removed, so you'll use a modulo 100, if you wanted the last 3, use a modulo 1000 :

80130 mod 100 = 30

substract that of your int : 80130 - 30 = 80100

Multiply this by the point value and you'll get the "floor" of your price : 80100 * 0.001 = 80.100

Now that you have the floor, you can easily get the ceiling with an addition :)

--
AAAANNNNND, I've just realized that there might be an easier way of doing this with mathfloor, mathceiling and the pFactor :arrrg: :

(thinking out loud)
You floor at 10 pips : 80.130 * (100/10) (100 is the pfactor for 3 digits) = 801.30
floor(801.30) = 801; ceil(801.30) = 802

divide this by your new factor (100/10) :
801 / (100/10) = 80.100
802 / (100/10) = 80.200

For a 5 digits price, that would be :
pFactor = 10000
pipRound = 10

Well, I Hope I did not confused you :mrgreen:
:D
dsugums
Trader
Posts: 117
Joined: Mon Jan 30, 2012 9:57 pm

How to code nearest round number level?

Post by dsugums »

I am ever so confused with your explanation :shock: :shock: :shock:
Image
Image
User avatar
Elixe
Trader
Posts: 98
Joined: Tue Jun 04, 2013 6:44 pm
Location: France

How to code nearest round number level?

Post by Elixe »

Haha,

If you cannot make it into code lines (that's a good exercise for any coder beginner).
I'll post functions doing it, you'll have to wait until I'm home and I have some minutes to make it useable.
Last edited by Elixe on Thu Jun 19, 2014 8:06 am, edited 1 time in total.
:D
User avatar
Elixe
Trader
Posts: 98
Joined: Tue Jun 04, 2013 6:44 pm
Location: France

How to code nearest round number level?

Post by Elixe »

Here you go, a little script with 2 functions :
func_floor.mq4
i've commented the process used, you can input the pip floor you want (must be 1, 10, 100, 1000 or 10000)

Let me know if you need more details.

E.
You do not have the required permissions to view the files attached to this post.
:D
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

How to code nearest round number level?

Post by SteveHopwood »

Elixe, I am coding a scalper that ds is going to share with all of us, and just used your func-floor code. Brilliant and much easier to use than my existing code.

Nice one. Thanks. :clap: :clap: :clap:

:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
Elixe
Trader
Posts: 98
Joined: Tue Jun 04, 2013 6:44 pm
Location: France

How to code nearest round number level?

Post by Elixe »

Glad you find it useful :mrgreen:

I'll probably make the "second" logic using pfactor function when I have some spare time, that might be easier to use in your shell if you want to keep theses functions in future EA.
:D
Post Reply

Return to “Coders Hangout”