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: 

void NewAlert(string message,int shift,double price,double sl,double tp)
  {
   if(Time[shift]!=lastAlertTime )
     {
      lastAlertTime=Time[shift];
      if(DisplayPush){SendNotification(Symbol()+" "+message+" @ "+price+" SL: "+sl+" TP: "+tp+TimeCurrent());}
      Alert(Symbol()+" "+message+" @ "+price+" SL: "+sl+" TP: "+tp+TimeCurrent());
     }

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:

// I tried declaring a whole bunch of global variables, and various combinations like these

   theTP = iBands(NULL,0,BBPeriod,BBStdDev,0,PRICE_CLOSE,MODE_MAIN,1);
   theTP = NormalizeDouble(iBands(NULL,0,BBPeriod,BBStdDev,0,PRICE_CLOSE,MODE_MAIN,1),Digits);   
   theTP = NormalizeDouble(iBands(NULL,0,BBPeriod,BBStdDev,0,PRICE_CLOSE,MODE_MAIN,1),5);   
   theTP = DoubleToStr(iBands(NULL,0,BBPeriod,BBStdDev,0,PRICE_CLOSE,MODE_MAIN,1),Digits); 
   theTP = DoubleToStr(iBands(NULL,0,BBPeriod,BBStdDev,0,PRICE_CLOSE,MODE_MAIN,1),5); 
   theTP2 = DoubleToString(theTP,Digits);
   theTP3 = NormalizeDouble(theTP,Digits);
   theTP4 = DoubleToString(theTP,5);
   theTP5 = NormalizeDouble(theTP,5);

// I tried it with Print() and Alert() but no matter how I try to restrict the decimal places, I can not do it

Please help me solve what I considered an easy problem

 
Christopher Bailey:

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. 

2018-05-01_1617
2018-05-01_1617
  • www.screencast.com
Shared from Screencast.com
 
Christopher Bailey:

Example: https://www.screencast.com/t/npPLJqgyZm

Ignore all the extra text I have concatenated in the alert. 

Example
 
Christopher Bailey:
DoubleToString()
 
Alain Verleyen:
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

 
Christopher Bailey: 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.
  1. 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.

  2. 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.

  3. 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

 
whroeder1:
  1. 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.

  2. 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.

  3. 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

Reason: