Hi, I am trying to calculate the pip value for one standard lot, I have the following code, it looks like OK, but I am not sure if it is OK for indexes too. Could an xp coder please check it? Thank you very much
Code: Select all int GetPairDigits(string pair) { return ((int) SymbolInfoInteger(pair, SYMBOL_DIGITS)); }
double GetPipFactor(string pair)
{
static bool knowbrokerdigits = false;
static int brokerdigits = 0;
//We want the additional pip digits of the broker once
if (!knowbrokerdigits)
{
//Try to get the broker digits for plain EURUSD
brokerdigits = (int) SymbolInfoInteger("EURUSD", SYMBOL_DIGITS) - 4;
//If plain EURUSD was found
if (brokerdigits >= 0) { knowbrokerdigits = true; }
else
{
brokerdigits = 0;
//Cycle through all symbols
for (int i = 0; i < SymbolsTotal(false); i++)
{
string symbol = SymbolName(i, false);
if (StringFind(symbol, "EURUSD") >= 0) { brokerdigits = MathMax(brokerdigits, (int) SymbolInfoInteger(symbol, SYMBOL_DIGITS) - 4); }
}
knowbrokerdigits = true;
}
}
//Calculation of the pip factor for the symbol
double pairdigits = (int) SymbolInfoInteger(pair, SYMBOL_DIGITS);
double pairfactor = MathPow(10, pairdigits - brokerdigits);
return(pairfactor);
}
void PipValue(string pair)
{
double lotsize = 1.0;
double factor = GetPipFactor(pair);
int dig = GetPairDigits(pair);
double pipvalue = NormalizeDouble(MarketInfo(pair, MODE_TICKVALUE) / MarketInfo(pair, MODE_TICKSIZE) / factor, dig);
Comment("Trading 1 standard lot, 1 pip = ", pipvalue * lotsize);
}
|