Calculate Commission of trade
Calculate Commission of trade
16 Jun 2016, 20:58
Hi all,
I want to calculate the commission of a trade, my account is in GBP base ccy.
I have the following code but I get the following error
23/05/2016 21:05:00.215 | Crashed in OnBar with NotSupportedException: GetSymbol is temporarily not supported in backtesting
private double CalculateCommissionPer1k()
{
double commissionGBP = 0;
string baseCcy = Symbol.Code.Remove(3, 3);
// The Commission parameter is the cost each way per million. Calculate the full commission (in and out) per 1k of the base currency.
double baseCcyCommission = (30 * 2) / 1000;
if (baseCcy == "EUR")
{
// Use EURGBP to convert the EUR commission value to GBP.
commissionGBP = baseCcyCommission * MarketData.GetSymbol("EURGBP").Bid;
}
else if (baseCcy == "USD")
{
// Use GBPUSD to convert the USD commission value to GBP.
commissionGBP = baseCcyCommission / MarketData.GetSymbol("GBPUSD").Bid;
}
else if (baseCcy == "GBP")
{
// The base currency is the same as the account currency. No conversion required.
commissionGBP = baseCcyCommission;
}
else if (baseCcy == "CHF")
{
// Use GBPCHF to convert the CHF commission value to GBP.
commissionGBP = baseCcyCommission / MarketData.GetSymbol("GBPCHF").Bid;
}
else if (baseCcy == "AUD")
{
// Use GBPAUD to convert the AUD commission value to GBP.
commissionGBP = baseCcyCommission / MarketData.GetSymbol("GBPAUD").Bid;
}
else if (baseCcy == "CAD")
{
// Use GBPCAD to convert the CAD commission value to GBP.
commissionGBP = baseCcyCommission / MarketData.GetSymbol("GBPCAD").Bid;
}
else if (baseCcy == "NZD")
{
// Use GBPNZD to convert the NZD commission value to GBP.
commissionGBP = baseCcyCommission / MarketData.GetSymbol("GBPNZD").Bid;
}
return commissionGBP;
}
Any idea how to run this in backtest? Is there a neater way to calculate commission?
Thanks,
Marc
Replies
DELETED_USER
17 Jun 2016, 14:53
Yes I understand, but I want to use this logic in live trading. I want to calculate the commission of the trade before the order is actually placed.
Thanks,
Marc
Spotware
17 Jun 2016, 15:07
Dear Trader,
Please have a look at this thread: /forum/calgo-support/9495
@Spotware
Spotware
17 Jun 2016, 14:49 ( Updated at: 21 Dec 2023, 09:20 )
Dear Trader,
The users set the Commission and Starting Capital in the Backtesting Mode.
@Spotware