Code on 4 decimal price vs 5 decimal price

 

My code works on a 5 decimal price broker, but not on a 4 decimal price broker... what should i be doing different in my code?


Thanks!

 
trader346:

My code works on a 5 decimal price broker, but not on a 4 decimal price broker... what should i be doing different in my code?


Thanks!

Factor the variables "Point" and "Digits" into your calculations.

 
cloudbreaker:

Factor the variables "Point" and "Digits" into your calculations.

Does "NormalizeDouble" have anything to possibly do with this? pretty new with mql and trying to wrap my head around it all

 
trader346 wrote >>

Does "NormalizeDouble" have anything to possibly do with this? pretty new with mql and trying to wrap my head around it all

Yes it does, see this as an example

int OpenAtMarketWithLiteralStops (string strPair, int iOrderType, double dLots, double dSL, double dTP, string strOrderComment, int iMagicNumber, datetime dtExpiry, color cColour)
{
int iMaxNumRetries, iNumRetries;
double adPrice, adSL, adTP;

    // is server or context busy - try n times to submit the order
    iNumRetries=OrderRetries;
    
     if(iOrderType > OP_SELL)
      {
        Print("OpenAtMarket Error: OrderType is a Pending Order!");
        return(0);
      }
     
    while(iNumRetries>0)
    {
        RefreshRates();
        if(iOrderType==OP_BUY) 
          {
           adPrice=NormalizeDouble(Ask, Digits);
           adSL=NormalizeDouble(dSL, Digits);
           adTP=NormalizeDouble(dTP, Digits);
          }
          
        if(iOrderType==OP_SELL) 
           {
            adPrice=NormalizeDouble(Bid, Digits);
            adSL=NormalizeDouble(dSL, Digits);
            adTP=NormalizeDouble(dTP, Digits);           
           }
    
        int iTicket =  OrderSend(strPair, iOrderType, dLots, adPrice, Real.Slippage, adSL, adTP, strOrderComment, iMagicNumber, dtExpiry, cColour);

        iNumRetries--;

        if(iTicket == -1 )
        {
            int iError = GetLastError();

            // retry if error is "busy", otherwise give up
            if(iError==ERR_SERVER_BUSY || iError==ERR_TRADE_CONTEXT_BUSY || iError==ERR_BROKER_BUSY || iError==ERR_NO_CONNECTION 
            || iError==ERR_TRADE_TIMEOUT || iError==ERR_INVALID_PRICE || iError==ERR_OFF_QUOTES || iError==ERR_PRICE_CHANGED || iError==ERR_REQUOTE)
                Sleep(SleepBetweenTrades);
            else
            {
                iNumRetries = 0;
                Print("OpenAtMarket: OrderSend Error ", iError );
            }
        }
        else
            iNumRetries = 0;
    }

    return(iTicket);
}

Good Luck

-BB-

 

PS - needs this line at the top of the EA for the standard include if you are going to use the whole thing :)


#include <stderror.mqh>

-BB-

 
BarrowBoy:

PS - needs this line at the top of the EA for the standard include if you are going to use the whole thing :)


#include <stderror.mqh>

-BB-

thanks! I've done through my EA and made these changes and will test it out :) Thanks again!

Reason: