How to buy/sell/tp/sl at a main price level like 1.13, 1.14 ... etc?
-
I am trying to test some ideas where I want the system to buy/sell/tp/sl on specific
and main rounded price value like 1.13, 1.14, or even smaller values like 1.1310, 1.1320, 1.1330 ... etc.
Is that possible to be programmed here as a variable?
Regards, -
There is one block "Round numbers detector" which can pass at such levels.
-
Thanks You Dreema, it worked.
How can I apply this to TP or SL? Is there any way to link the TP to an object like "Round numbers detector"?
Regards,
-
If you open at round prices, then SL and TP can be placed at almost round prices also. But if in any case you want to use exact round price, it can be calculated. Try this for example: https://fxdreema.com/shared/b8l8pXC4e
Sometimes the SL can be placed too close to the trade, but I want to show how to round the price, which is pure math. So I have this formula:
MathFloor(Ask * 100) / 100Here Ask is Ask, this is a predefined variable that MetaTrader changes on every tick, so its value is the current Ask. MathFloor is described here: https://www.mql5.com/en/docs/math/mathfloor Also look at MathCeil().
Let's say that Ask is 1.2345. Then Ask * 100 is 123.45. After MathFloor() it becomes 123.00. Then we divide by 100 and at the end we have 1.2300.
-
@fxdreema Thank you Dreema!
It worked perfectly.
One more question that would help a lot if you can answer. Is it possible to round the SL and TP to half levels like 123.0, 123.5, 124.0, 124.5 ... etc.
It is easy in the ROUND NUMBER DETECTOR because I can write the grid size as 0.0050. But is it possible to be make with MathFloor for example?Cheers,
-
Is it needed. Because with the detector block you detect those numbers and then a trade is created. But this trade could be opened at a little bit different price, not at exactly the round number. If the trade is off with let's say 2 pips and you set SL and TP at round numbers, one of them will be 2 pips bigger than the other.
Otherwise it can be calculated. As you can see, what we do with that formula is to remove the last parts of a number. if we have 1.2345 we can remove the last 5, last 45, last 345... But it also depends, because what if we have 1.2678 - should we use MathFloor or MathCeil? Should the rounded number be 1.26 or 1.27?