Problems with a calculation

To add comments, please log in or register
jugivi
211
jugivi  
Good morning, I have a problem and need help please.
I recover ...
open = iOpen (Symbol (), PERIOD_M1, 1);
close = iClose (Symbol (), PERIOD_M1, 1);

I need open and close with 5 decimal places, but I come with 4 decimal places and if the string step puiedo not operate with them, and I need you to put the result subtract without decimal numbers:

open = 1.61256
close = 1.61154

result = 0.00102 (NO)

I need result = 102

Can anyone help me to make it easy?

thanks
Tjipke de Vries
6625
Tjipke de Vries  
jugivi:
Good morning, I have a problem and need help please.
I recover ...
open = iOpen (Symbol (), PERIOD_M1, 1);
close = iClose (Symbol (), PERIOD_M1, 1);

I need open and close with 5 decimal places, but I come with 4 decimal places and if the string step puiedo not operate with them, and I need you to put the result subtract without decimal numbers:

open = 1.61256
close = 1.61154

result = 0.00102 (NO)

I need result = 102

Can anyone help me to make it easy?

thanks
result = 0.00102 (NO)/Point = 102
William Roeder
20069
William Roeder  
jugivi:
need open and close with 5 decimal places, but I come with 4 decimal places and
I need result = 102
  1. iOpen/iClose return a double, INFINITE decimal places. RTFM Print/Comment/Alert and then the link to DoubleToStr.
    string  PriceToStr(double p){   return( DoubleToStr(p, Digits) );              }
    string  DeltaToPips(double d){
        if (d > 0)  string sign = "+";  else    sign = "";
        double pips = d / pips2dbl;
        return( sign + DoubleToStr(pips, Digits.pips) );                           }
    

  2. int result = (close-open) / pips2dbl;
    Your EA must adjust for 4/5 digit brokers. Pips (tp, sl) and Points (Slippage) EA's must adjust for ECN brokers
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){                                             
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(..., 0,0,...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0))
           Alert("OrderModify failed: ", GetLastError());
         */
    
jugivi
211
jugivi  
Thanks.
dineshydv
170
dineshydv  
You should use Point in your calculation to get exact pip.
William Roeder
20069
William Roeder  
dineshydv: You should use Point in your calculation to get exact pip.
A point is NOT a pip on a 5 digit broker.
To add comments, please log in or register