Untitled
unknown
plain_text
a year ago
3.2 kB
12
Indexable
//+------------------------------------------------------------------+
//| GetPipValue
//+------------------------------------------------------------------+
/*
Get a symbol's pip value in terms of Account currency.
*/
double GetPipValue(string SymbolPair, double Position_Lots, double AccountCurrency_Exchange_Rate)
{
double pvalue = 0;
double pip = 0.0001;
double askp = MarketInfo(SymbolPair,MODE_ASK);
string BaseCurrency = SymbolInfoString(SymbolPair,SYMBOL_CURRENCY_BASE);
double contractsize = SymbolInfoDouble(SymbolPair,SYMBOL_TRADE_CONTRACT_SIZE);
if(askp > 0)
{
pvalue = (pip/askp) * Position_Lots * contractsize;//this is in Base Currency
pvalue = pvalue / AccountCurrency_Exchange_Rate;
}
else
{
Print("Failed to get ASK price for the symbol "+SymbolPair+" for GetPipValue. Please ensure the symbol is listed in MarkeWatch and that you are connected to the trade server.");
}
return pvalue;
}
//+------------------------------------------------------------------+
//| end of GetPipValue
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| GetSwapRateInAccountCurrency
//+------------------------------------------------------------------+
/*
Get a symbols swap rate in account currency.
*/
double GetSwapRateInAccountCurrency(string aSymbol,int aOrderType, double ExchangeRate)
{
// now check swap type
int swapType=MarketInfo(aSymbol, MODE_SWAPTYPE);
double swapRate=0;
// get out the tick value to calculate swap points
double tickValue=MarketInfo (aSymbol, MODE_TICKVALUE); // tick value in deposit currency (typically USD)
string accntcurrency_str = AccountInfoString(ACCOUNT_CURRENCY);
//Swap calculation method. 0 - in points; 1 - in the symbol base currency; 2 - by interest; 3 - in the margin currency
double AccntCurrency=0;
if (aOrderType==OP_SELL)
{
swapRate=SymbolInfoDouble(aSymbol,SYMBOL_SWAP_SHORT);
}
else if(aOrderType==OP_BUY)
{
swapRate=SymbolInfoDouble(aSymbol,SYMBOL_SWAP_LONG);
}
if (swapType==0)
{
AccntCurrency = swapRate/ExchangeRate;
}
else if (swapType==1)
{
// need to convert to account currency
// get currency of symbol
string base_currency_Str=SymbolInfoString(aSymbol,SYMBOL_CURRENCY_BASE);
AccntCurrency = swapRate/ExchangeRate;
}
else if (swapType==2)
{
// interest rate or percentage version, e.g. bitcoin. Use %tage of price but returned down to a day. Probably wrong...
AccntCurrency=((swapRate/100)*MarketInfo(aSymbol, MODE_BID))/365;
}
else if (swapType==3)
{
// this is easiest. Amount is in margin currency which = account currency
AccntCurrency=swapRate;
}
return(AccntCurrency);
}Editor is loading...
Leave a Comment