stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

How to code nearest round number level?
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3676
Page 1 of 2
Author:  dsugums [ Fri Jun 13, 2014 4:56 am ]
Post subject:  How to code nearest round number level?

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
Author:  SpiderX [ Fri Jun 13, 2014 6:49 am ]
Post subject:  How to code nearest round number level?

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
Author:  SteveHopwood [ Fri Jun 13, 2014 7:20 am ]
Post subject:  How to code nearest round number level?

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:
Author:  dsugums [ Fri Jun 13, 2014 7:54 am ]
Post subject:  How to code nearest round number level?

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
Author:  Elixe [ Fri Jun 13, 2014 9:02 am ]
Post subject:  How to code nearest round number level?

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:
Author:  dsugums [ Wed Jun 18, 2014 10:16 am ]
Post subject:  How to code nearest round number level?

I am ever so confused with your explanation :shock: :shock: :shock:
Author:  Elixe [ Wed Jun 18, 2014 10:37 am ]
Post subject:  How to code nearest round number level?

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.
Author:  Elixe [ Wed Jun 18, 2014 7:10 pm ]
Post subject:  How to code nearest round number level?

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.
Author:  SteveHopwood [ Thu Jun 19, 2014 11:06 am ]
Post subject:  How to code nearest round number level?

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:
Author:  Elixe [ Thu Jun 19, 2014 1:36 pm ]
Post subject:  How to code nearest round number level?

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.
All times are UTC Page 1 of 2