Normalizing the iBands (MODE_MAIN) output and using it in an Alert ()
Please can someone shed light on this scenario.
I want to provide an alert/notification that provides me with a message that looks like this:
GBPUSD Buy: @ 1.36104 SL: 1.36015 TP: 1.36987
But I am getting GBPUSD Buy: @ 1.36104 SL: 1.36015 TP: 1.369872341251252351 and neither of the NormalizeDouble() , DoubleToStr() , DoubleToString() functions solve the problem.
So I am calling a little function to handle the alerts and sending it some information:
The message is simple text saying BUY or SELL
The price is easy to fetch and send because it's either bid/Ask
The stop loss is easy to fetch because it's using a simple arithmetic function using the recent low +/- a buffer, depending on the direction of the trade
However the tp is a calculated double from an indicator. The indicator is the iBands indicator and i'm using the MODE_MAIN method.
The issue I have is restricting the number of decimal places. The Alert/Notification/Print has sooooo many decimals and I can not stop it
I have tried all kinds of combinations (obviously not all the same time, but replacing them) including these ideas, but I am still seeing between 8-17 decimals in the Alerts and notifications:
Please help me solve what I considered an easy problem
Example: https://www.screencast.com/t/npPLJqgyZm
Ignore all the extra text I have concatenated in the alert.
Example: https://www.screencast.com/t/npPLJqgyZm
Ignore all the extra text I have concatenated in the alert.
DoubleToString()
This didn't work Alain, I tried DoubleToString() and various other functions, in multiple combinations, but it doesn't have the desired effect.
I am wondering whether it has to do with the indicator not using #property strict
In fact, thinking about it, that's highly likely the issue
-
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't
use it. It's use is usually wrong, as it is in this case.
- Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- You haven't stated a problem, you stated a want.
Show us your attempt
(using CODE button) and state
the nature of your problem.
No free help
urgent help. - The other two do solve your want. If you want to see the correct number of digits, convert it to a string.
question about decima of marketinfo() - MQL4 and MetaTrader 4 - MQL4 programming forum
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is usually wrong, as it is in this case.
- Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- You haven't stated a problem, you stated a want. Show us your attempt (using CODE button) and state the nature of your problem.
No free help
urgent help. - The other two do solve your want. If you want to see the correct number of digits, convert it to a string.
question about decima of marketinfo() - MQL4 and MetaTrader 4 - MQL4 programming forum
Confirmed
The issue for me was the failure to notice that I was not using the strict compilation mode.
The addition of #property strict creates a whole bunch of conversion warnings that are all fixed using DoubleToStr()
Without using the 'strict' compilation mode, the conversions didn't seem to be doing anything
Please can someone shed light on this scenario.
I want to provide an alert/notification that provides me with a message that looks like this:
GBPUSD Buy: @ 1.36104 SL: 1.36015 TP: 1.36987
But I am getting GBPUSD Buy: @ 1.36104 SL: 1.36015 TP: 1.369872341251252351 and neither of the NormalizeDouble() , DoubleToStr() , DoubleToString() functions solve the problem.
So I am calling a little function to handle the alerts and sending it some information:
The message is simple text saying BUY or SELL
The price is easy to fetch and send because it's either bid/Ask
The stop loss is easy to fetch because it's using a simple arithmetic function using the recent low +/- a buffer, depending on the direction of the trade
However the tp is a calculated double from an indicator. The indicator is the iBands indicator and i'm using the MODE_MAIN method.
The issue I have is restricting the number of decimal places. The Alert/Notification/Print has sooooo many decimals and I can not stop it
I have tried all kinds of combinations (obviously not all the same time, but replacing them) including these ideas, but I am still seeing between 8-17 decimals in the Alerts and notifications:
Please help me solve what I considered an easy problem