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.
This happens because you are using the current open bar value in your conditions. The value of the current open bar can change by the time the bar closes, leading to several false signals. Try checking closed bars only e.g.
if ((_fastTimeSeriesMovingAverage.Result.Last(2) < _slowTimeSeriesMovingAverage.Result.Last(2) && _fastTimeSeriesMovingAverage.Result.Last(1) > _slowTimeSeriesMovingAverage.Result.Last(1))
Can you please share more information? Why do you think you have sufficient funds? What is the volume you are trying to trade, what is your leverage and what is your balance?
Pending orders are only limit, stop and stop limit orders. A market order is not a pending order.
Best regards,
Panagiotis
MetaTrader has a way to find orders before they actually become an open position. I need to do the same with cTrader. If I put on several async market orders all at once I need to be able to check if they've been filled otherwise I get duplicates. I don't want to use callbacks. I need to be able to look them up by their custom label. Something like my example:
foreach(Order order in SomeListOfUnfilledOrders) {
if(order.Label == “order123”) return true;
Then you need to store this information on your side e.g. add market orders in a collection and remove them only after you have received an execution response from the server.
PanagiotisCharalampous
21 Aug 2024, 14:50
RE: RE: Bars can only fetch latest 200 bars
raypang said:
Can you tell us the broker and the symbol?
@PanagiotisCharalampous