This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.
Hi Panagiotis,
The values I get for the account margin are still not matching while backtesting the code above. Are you backtesting an index? Probably not.
I selected the historical data, as suggested. However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?
I checked this with both Varianse and Pepperstone (using historial data). Below is the backtest output with Varianse.
Hi ncel01,
Yes I do
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?
The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.
Panagiotis,
The functionality should work correctly when the option is checked.
How come, when my screenshot clearly shows that Account.Margin is returning 0 even with an open position? Did you check this with some other accounts/brokers (apart from Spotware)? If not, can you please double-check this?
Thanks.
Hi ncel01,
It works fine on Variance as well.
Please send a full screenshot like the above, so that we can understand what you are doing
Hi Panagiotis,
Thanks for looking into this again. I meant an account with a different broker, not exactly the broker version of cTrader. So far, I found that Account.Margin is not correct in the following cases (at least):
Example 1: Any live account (tested with Pepperstone and TopFX)
Example 2: New demo accounts (without trading activity) where Symbol Leverage > Account Leverage (tested with Varianse)
I've added a screenshot for each of these examples (see below). I am running the cBot shared above (historical data is checked). Note that, regardless of what leverage is considered (symbol/account), the calculated account margin does not match Account.Margin in any of the cases shown.
Something is clearly not going as expected here. The results show that there is not a unique/consistent calculation for Account.Margin, no matter the situation.
Example 1:
Example 2:
Something else I noticed in the meantime that I also don't understand: Positions.Count is returning 0 while called inside Positions_Opened(). See below.
Hi ncel01,
As far as I can see, in all the cases with discrepancy, your account currency is different to the symbol currency, however your calculations do not include any conversion logic. The API's property converts the margin to the account's currency value. The XTE issue seems a separate issue, can you report it in a different thread?
If you are calling LastBar in OnBar() then you will get the same prices, since the method is called on bar opening. Try OnBarClosed() instead and you should get the OHLC values.
Please share the complete cBot code since it is not possible understand everything you are doing just from a snippet.
Best regards,
Panagiotis
Hello. The only thing I really want is for my cTrader account to only allow operations in one direction and when I open an operation, the ones in the opposite direction are closed. I used to have that type of account but now they all allow hedging.
Hi there,
Here is an example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class CloseOpposite : Robot
{
protected override void OnStart()
{
Positions.Closed += Positions_Closed;
}
private void Positions_Closed(PositionClosedEventArgs obj)
{
foreach (var position in Positions.Where(p => p.TradeType != obj.Position.TradeType))
{
position.Close();
}
}
protected override void OnTick()
{
// Handle price updates here
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
}
Given the absence of any clarifications, I will assume that the following has been announced by mistake:
The following issues were addressed
Wrong Account.BrokerName and Account.Number for a bot with cloud instance
Hi ncel01,
Sorry for the delay, I had to do some research for this, it seems this has not been delivered yet. It's fixed on the cAlgo side but the server team needs to do some work as well.
This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.
Hi Panagiotis,
The values I get for the account margin are still not matching while backtesting the code above. Are you backtesting an index? Probably not.
I selected the historical data, as suggested. However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?
I checked this with both Varianse and Pepperstone (using historial data). Below is the backtest output with Varianse.
Hi ncel01,
Yes I do
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?
The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.
Panagiotis,
The functionality should work correctly when the option is checked.
How come, when my screenshot clearly shows that Account.Margin is returning 0 even with an open position? Did you check this with some other accounts/brokers (apart from Spotware)? If not, can you please double-check this?
Thanks.
Hi ncel01,
It works fine on Variance as well.
Please send a full screenshot like the above, so that we can understand what you are doing
This function obviously has changed its behavior, because I had an indicator and source control of it and it had working fine for a long time, debugging it led me to find this problem. Regardless of the broker or pair it returns zero and another user had this issue too but check more on this.
See video attached, first it counts bars without using the function on AUDNZD, then I run it again using the function, it turns into a locked refresh loop (doesn't even print the bars until after it loads the data, doesn't even print the initial bar count), at the end it does increase the number of bars but the function still returns zero.
Before this problem, we were able to control how many bars to load in a simple while loop synchronously without issues.
The behavior is as expected on an indicator. As soon as more bars are loaded the indicator needs to be reinitialized and recalculated. Therefore this leads to a loop until all bars are loaded. Probably you are comparing this with the way it behaves in a cBot which is a different behavior.
PanagiotisCharalampous
22 Aug 2024, 07:54
Hi there,
Thanks for reporting this issue. It will be fixed in an upcoming update of cTrader.
Best regards,
Panagiotis
@PanagiotisCharalampous