x.NetProfit with commissions
x.NetProfit with commissions
01 Feb 2023, 14:39
Hello everyone,
I have a code able to close a group of positions "BUY - SELL" with positive profit.
Is possibile subtract from the ".netprofit" of this code the expenses of Commission and swap ?
if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0)
{
if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0)
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID)
ClosePosition(position);
}
Thank you for your time
Replies
Goulk
01 Feb 2023, 17:19
( Updated at: 21 Dec 2023, 09:23 )
RE: RE:
ncel01 said:
Goulk said:
Hello everyone,
I have a code able to close a group of positions "BUY - SELL" with positive profit.
Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?
if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0) { if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0) foreach (var position in Positions) { if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID) ClosePosition(position); }
Thank you for your time
Hi Goulk,
NetProfit should already reflect all the costs deducted:
NetProfit = GrossProfit - Swaps - Comissions
If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.
When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest
@Goulk
ncel01
02 Feb 2023, 00:24
( Updated at: 21 Dec 2023, 09:23 )
RE: RE: RE:
Goulk said:
ncel01 said:
Goulk said:
Hello everyone,
I have a code able to close a group of positions "BUY - SELL" with positive profit.
Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?
if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0) { if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0) foreach (var position in Positions) { if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID) ClosePosition(position); }
Thank you for your time
Hi Goulk,
NetProfit should already reflect all the costs deducted:
NetProfit = GrossProfit - Swaps - Comissions
If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.
When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest
Hi Goulk,
I am not sure about comissions but swaps are not taken into account when backtesting.
That should explain the difference in case the take profit is set based on a net profit and not on the distance to the entry price. Since the net profit will reduce due to the swaps, the distance to the entry price will need increase accordingly to end up with the same net profit.
@ncel01
Goulk
02 Feb 2023, 00:55
( Updated at: 21 Dec 2023, 09:23 )
RE: RE: RE: RE:
ncel01 said:
Goulk said:
ncel01 said:
Goulk said:
Hello everyone,
I have a code able to close a group of positions "BUY - SELL" with positive profit.
Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?
if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0) { if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0) foreach (var position in Positions) { if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID) ClosePosition(position); }
Thank you for your time
Hi Goulk,
NetProfit should already reflect all the costs deducted:
NetProfit = GrossProfit - Swaps - Comissions
If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.
When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest
Hi Goulk,
I am not sure about comissions but swaps are not taken into account when backtesting.
That should explain the difference in case the take profit is set based on a net profit and not on the distance to the entry price. Since the net profit will reduce due to the swaps, the distance to the entry price will need increase accordingly to end up with the same net profit.
Ok thanks ncel01. This is exactly the problem I have. So, is it possible to add swap in my code? And if so, how? Thank you for your time.
@Goulk
PanagiotisChar
02 Feb 2023, 08:23
Hi Goulk,
No, it's not possible at the moment.
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar
ncel01
02 Feb 2023, 08:28
( Updated at: 21 Dec 2023, 09:23 )
RE: RE: RE: RE: RE:
Goulk said:
ncel01 said:
Goulk said:
ncel01 said:
Goulk said:
Hello everyone,
I have a code able to close a group of positions "BUY - SELL" with positive profit.
Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?
if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0) { if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0) foreach (var position in Positions) { if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID) ClosePosition(position); }
Thank you for your time
Hi Goulk,
NetProfit should already reflect all the costs deducted:
NetProfit = GrossProfit - Swaps - Comissions
If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.
When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest
Hi Goulk,
I am not sure about comissions but swaps are not taken into account when backtesting.
That should explain the difference in case the take profit is set based on a net profit and not on the distance to the entry price. Since the net profit will reduce due to the swaps, the distance to the entry price will need increase accordingly to end up with the same net profit.
Ok thanks ncel01. This is exactly the problem I have. So, is it possible to add swap in my code? And if so, how? Thank you for your time.
Hi Goulk,
I don't think it is possible to add it directly but it should be possible to somehow account for it.
What I would do:
I'd code the bot to reduce the distance to TP by the number of pips applied to swaps on a daily basis.
Cons:
Costs associated to the swaps will only be reflected when the positions close.
Some brokers apply a 3-day swap on wednesdays. You can also adjust this programmatically.
Alternatively (easier):
I'd increase the commissions to compensate this. I told you I was not sure about comissions but these are definitely considered when backtesting and can be defined by the user.
Cons: not so accurate.
I hope this helped.
@ncel01
Goulk
02 Feb 2023, 17:38
( Updated at: 21 Dec 2023, 09:23 )
RE: RE: RE: RE: RE: RE:
ncel01 said:
Goulk said:
ncel01 said:
Goulk said:
ncel01 said:
Goulk said:
Hello everyone,
I have a code able to close a group of positions "BUY - SELL" with positive profit.
Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?
if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0) { if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0) foreach (var position in Positions) { if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID) ClosePosition(position); }
Thank you for your time
Hi Goulk,
NetProfit should already reflect all the costs deducted:
NetProfit = GrossProfit - Swaps - Comissions
If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.
When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest
Hi Goulk,
I am not sure about comissions but swaps are not taken into account when backtesting.
That should explain the difference in case the take profit is set based on a net profit and not on the distance to the entry price. Since the net profit will reduce due to the swaps, the distance to the entry price will need increase accordingly to end up with the same net profit.
Ok thanks ncel01. This is exactly the problem I have. So, is it possible to add swap in my code? And if so, how? Thank you for your time.Hi Goulk,
I don't think it is possible to add it directly but it should be possible to somehow account for it.
What I would do:
I'd code the bot to reduce the distance to TP by the number of pips applied to swaps on a daily basis.
Cons:
Costs associated to the swaps will only be reflected when the positions close.
Some brokers apply a 3-day swap on wednesdays. You can also adjust this programmatically.
Alternatively (easier):
I'd increase the commissions to compensate this. I told you I was not sure about comissions but these are definitely considered when backtesting and can be defined by the user.
Cons: not so accurate.
I hope this helped.
Ncel01,
Thanks for the answers,
At this point, I wonder if it is possible to use the . GrossProfit to make the backtest equal to LIVE.
Is SWAP considered in the .GrossProfit "LIVE" ?
Thank you.
@Goulk
ncel01
02 Feb 2023, 18:26
( Updated at: 21 Dec 2023, 09:23 )
RE: RE: RE: RE: RE: RE: RE:
Goulk said:
ncel01 said:
Goulk said:
ncel01 said:
Goulk said:
ncel01 said:
Goulk said:
Hello everyone,
I have a code able to close a group of positions "BUY - SELL" with positive profit.
Is possibile subtract from the ".netprofit" of this code the expenses of Commisione and swap ?
if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID) > 0) { if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == LabelID).Average(x => x.NetProfit) >= 0) foreach (var position in Positions) { if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == LabelID) ClosePosition(position); }
Thank you for your time
Hi Goulk,
NetProfit should already reflect all the costs deducted:
NetProfit = GrossProfit - Swaps - Comissions
If so, my backtest results would be the same as 'LIVE'. Unfortunately this is not the case.
When positions are closed in 'LIVE', they have a different closing price than the 'Tick' backtest
Hi Goulk,
I am not sure about comissions but swaps are not taken into account when backtesting.
That should explain the difference in case the take profit is set based on a net profit and not on the distance to the entry price. Since the net profit will reduce due to the swaps, the distance to the entry price will need increase accordingly to end up with the same net profit.
Ok thanks ncel01. This is exactly the problem I have. So, is it possible to add swap in my code? And if so, how? Thank you for your time.Hi Goulk,
I don't think it is possible to add it directly but it should be possible to somehow account for it.
What I would do:
I'd code the bot to reduce the distance to TP by the number of pips applied to swaps on a daily basis.
Cons:
Costs associated to the swaps will only be reflected when the positions close.
Some brokers apply a 3-day swap on wednesdays. You can also adjust this programmatically.
Alternatively (easier):
I'd increase the commissions to compensate this. I told you I was not sure about comissions but these are definitely considered when backtesting and can be defined by the user.
Cons: not so accurate.
I hope this helped.
Ncel01,
Thanks for the answers,
At this point, I wonder if it is possible to use the . GrossProfit to make the backtest equal to LIVE.
Is SWAP considered in the .GrossProfit "LIVE" ?
Thank you.
Goulk,
GrossProfit is only based on the distance I guess, so the results should match in this case.
Why do you want and exact match between backtest and a real-time run, if I may ask?
@ncel01
ncel01
01 Feb 2023, 16:39
RE:
Goulk said:
Hi Goulk,
NetProfit should already reflect all the costs deducted:
NetProfit = GrossProfit - Swaps - Comissions
@ncel01