Account Margin not resetting when backtesting bot
14 May 2024, 03:21
I'm testing the modification of a bot's lot size and updating it on every bar (tried onBar, onBarClosed, same errors occurring) based on some indicator (not important just for reference). It runs fine for a little bit then just does minimum lot size entries. After a bit of investigation it seems like Margin isn't resetting even though trades are being closed? I've triple checked open positions and whatnot through debugging and it shows all positions are closed. I believe this is a bug and I did submit an error weeks ago but haven't heard anything so I thought I'd raise it here. I've tried using both ModifyPosition and partially closing trades to no avail.
Also weirdly enough it doesn't seem to work as it's supposed to when back testing without visual box being ticked. If I tick the box it works how I expect it to (up until the margin gets too high and then it just does minimums which also doesn't make sense it shouldn't work at all).
double lotSize = riskPerPip / pipValuePerStandardLot; // Calculate the initial lot size based on risk per pip
double minLotSizeIncrement = Symbol.VolumeInUnitsMin; // Get the minimum lot size increment from the symbol settings
lotSize = Math.Ceiling(lotSize / minLotSizeIncrement) * minLotSizeIncrement; // Round the lot size up to the nearest minimum lot size increment
double estimatedMarginPerLot = Symbol.GetEstimatedMargin(TradeType.Buy, minLotSizeIncrement); // Estimate the margin required for the minimum lot size increment
double maxLotSizeWithinMargin = Math.Floor(freeMargin / estimatedMarginPerLot) * minLotSizeIncrement; // Calculate the maximum lot size that can be supported by the free margin
lotSize = Math.Min(lotSize, maxLotSizeWithinMargin); // Adjust the lot size to not exceed the maximum lot size that fits within the free margin
// Ensure the final lot size is within the broker's allowed range and is a multiple of the minimum lot size increment
double minLotSize = Symbol.VolumeInUnitsMin;
double maxLotSize = Symbol.VolumeInUnitsMax;
lotSize = Math.Max(minLotSize, lotSize);
lotSize = Math.Min(maxLotSize, lotSize);
return lotSize;
}
}
}
I'd love to get this working as the concept of a continuous market position is something I've been chasing for a while now.
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
Parameters are the default ones built into the bot as it's just an example and it's what I used to replicate. Back testing was a number of markets (forex, spot metals, spot indices, crypto, whatever else I tested it on) and dates are anything available in the range of 2013 - now that runs for longer than 100 trades. Tested on both 1m, the 2h and 15m charts I was testing on and tick data.
See below to show that the balance and equity is basically full but margin is more than the balance of the account:
And then you can see here the only position I have open is minimum lot size:
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
Parameters are the default ones built into the bot as it's just an example and it's what I used to replicate. Back testing was a number of markets (forex, spot metals, spot indices, crypto, whatever else I tested it on) and dates are anything available in the range of 2013 - now that runs for longer than 100 trades. Tested on both 1m, the 2h and 15m charts I was testing on and tick data.
See below to show that the balance and equity is basically full but margin is more than the balance of the account:
And then you can see here the only position I have open is minimum lot size:
Thanks Vik,
We managed to reproduce the problem and it will be fixed in an upcoming update.
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
Parameters are the default ones built into the bot as it's just an example and it's what I used to replicate. Back testing was a number of markets (forex, spot metals, spot indices, crypto, whatever else I tested it on) and dates are anything available in the range of 2013 - now that runs for longer than 100 trades. Tested on both 1m, the 2h and 15m charts I was testing on and tick data.
See below to show that the balance and equity is basically full but margin is more than the balance of the account:
And then you can see here the only position I have open is minimum lot size:
Thanks Vik,
We managed to reproduce the problem and it will be fixed in an upcoming update.
Best regards,
Panagiotis
Ah fantastic, glad to see it wasn't something I was doing! You got a rough timeframe on when that update may be?
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
Parameters are the default ones built into the bot as it's just an example and it's what I used to replicate. Back testing was a number of markets (forex, spot metals, spot indices, crypto, whatever else I tested it on) and dates are anything available in the range of 2013 - now that runs for longer than 100 trades. Tested on both 1m, the 2h and 15m charts I was testing on and tick data.
See below to show that the balance and equity is basically full but margin is more than the balance of the account:
And then you can see here the only position I have open is minimum lot size:
Thanks Vik,
We managed to reproduce the problem and it will be fixed in an upcoming update.
Best regards,
Panagiotis
Ah fantastic, glad to see it wasn't something I was doing! You got a rough timeframe on when that update may be?
Unfortunately we do not have a timeframe at the moment
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
Parameters are the default ones built into the bot as it's just an example and it's what I used to replicate. Back testing was a number of markets (forex, spot metals, spot indices, crypto, whatever else I tested it on) and dates are anything available in the range of 2013 - now that runs for longer than 100 trades. Tested on both 1m, the 2h and 15m charts I was testing on and tick data.
See below to show that the balance and equity is basically full but margin is more than the balance of the account:
And then you can see here the only position I have open is minimum lot size:
Thanks Vik,
We managed to reproduce the problem and it will be fixed in an upcoming update.
Best regards,
Panagiotis
Ah fantastic, glad to see it wasn't something I was doing! You got a rough timeframe on when that update may be?
Unfortunately we do not have a timeframe at the moment
PanagiotisCharalampous hey mate the issue seems to have returned again? It was working fine after the last update but I'm running into it again.
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
Parameters are the default ones built into the bot as it's just an example and it's what I used to replicate. Back testing was a number of markets (forex, spot metals, spot indices, crypto, whatever else I tested it on) and dates are anything available in the range of 2013 - now that runs for longer than 100 trades. Tested on both 1m, the 2h and 15m charts I was testing on and tick data.
See below to show that the balance and equity is basically full but margin is more than the balance of the account:
And then you can see here the only position I have open is minimum lot size:
Thanks Vik,
We managed to reproduce the problem and it will be fixed in an upcoming update.
Best regards,
Panagiotis
Ah fantastic, glad to see it wasn't something I was doing! You got a rough timeframe on when that update may be?
Unfortunately we do not have a timeframe at the moment
PanagiotisCharalampous hey mate the issue seems to have returned again? It was working fine after the last update but I'm running into it again.
Hi there,
Can you share new screenshots showing the version as well?
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
Parameters are the default ones built into the bot as it's just an example and it's what I used to replicate. Back testing was a number of markets (forex, spot metals, spot indices, crypto, whatever else I tested it on) and dates are anything available in the range of 2013 - now that runs for longer than 100 trades. Tested on both 1m, the 2h and 15m charts I was testing on and tick data.
See below to show that the balance and equity is basically full but margin is more than the balance of the account:
And then you can see here the only position I have open is minimum lot size:
Thanks Vik,
We managed to reproduce the problem and it will be fixed in an upcoming update.
Best regards,
Panagiotis
Ah fantastic, glad to see it wasn't something I was doing! You got a rough timeframe on when that update may be?
Unfortunately we do not have a timeframe at the moment
PanagiotisCharalampous hey mate the issue seems to have returned again? It was working fine after the last update but I'm running into it again.
Hi there,
Can you share new screenshots showing the version as well?
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
Parameters are the default ones built into the bot as it's just an example and it's what I used to replicate. Back testing was a number of markets (forex, spot metals, spot indices, crypto, whatever else I tested it on) and dates are anything available in the range of 2013 - now that runs for longer than 100 trades. Tested on both 1m, the 2h and 15m charts I was testing on and tick data.
See below to show that the balance and equity is basically full but margin is more than the balance of the account:
And then you can see here the only position I have open is minimum lot size:
Thanks Vik,
We managed to reproduce the problem and it will be fixed in an upcoming update.
Best regards,
Panagiotis
Ah fantastic, glad to see it wasn't something I was doing! You got a rough timeframe on when that update may be?
Unfortunately we do not have a timeframe at the moment
PanagiotisCharalampous hey mate the issue seems to have returned again? It was working fine after the last update but I'm running into it again.
Hi there,
Can you share new screenshots showing the version as well?
Best regards,
Panagiotis
Thank you, the fix for this issue was not released yet. It will be released in an upcoming update.
PanagiotisCharalampous
14 May 2024, 05:51
Hi there,
Please provide us with dates, cBot parameters and backtesting settings so that we can reproduce this behavior on backtesting. Also share some screenshots demonstrating these positions.
Best regards,
Panagiotis
@PanagiotisCharalampous