I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.
Best regards,
Panagiotis
Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.
I am not sure what you mean, can you elaborate?
When my indicator is on the chart. Adds objects to the chart, such as rectangles and trend lines These objects are interactive. "IsInteractive = true;" When I remove the indicator from the chart, those objects remain in the chart! If their interactive feature is false, they will be deleted automatically, but as I said, I will turn on their interactive feature. I want to delete all the objects added to the chart when the indicator is deleted
Hi there,
Can you share the code you are using to delete the objects so that we can check?
No that is not what I said. Indicators referenced in a strategy will use the source set in the backtesting settings. Indicators applied on the chart will be rendered at the moment they are applied, so all past bars will be considered historical
first of all, Panagiotis thanks for your great replies to actually all threads I found in this forum already, as well to this one.
Just to make it sure in my own (not native English speaking … poorer) words ;-)
with “strategy” I guess you mean a cBot.
backtesting settings & optimization settings (e.g. ticks instead of chart timeframe data) will be correct processed, in the backend of backtesting & optimization
point 2. is also applicable for indicators on the chart shown on backtesting in visual mode
all other indicators (chart in trade section or chart in backtesting in NON visual mode) will show historically only chart timeframe data, for “IsLastBar” it will be also consider ticks
That's what I extracted as summary and it's no open question, except I wrote something wrong.
I have the same issue with cTrader Desktop 5.0.25. There's only been one trade in the history for the past few days. It seems to be showing current day's trades correctly. However, I have the entire history on cTrader for Android. Demo account with FxPro: 10580044.
Can you take full screenshots so that we can see the account number, broker and cTrader version?
Best regards,
Panagiotis
Evening,
The cTrader desktop version 4.8.34 and the broker is Pepperstone Aus, I am not willing to share my account number. I do appreciate any help you can give.
The history is appearing today it has done this before and disappearing the next day, I am wondering if a clean install would help. today's history shot
Many thanks :)
Hi there,
Does this happen in cTrader v5.0?
Best regards,
Many thanks,
I have not tried V5.0 version only version 4.8.34.
If you recommend I will give it a try and upgrade to V5.
The history came back yesterday is is also ok today, I restart the platform once a day.
One question where is the history stored local machine or broker ?
Appreciate your support.
:)
The history is on the server, let us know if this still happens on v5.0
I am experiencing the same issue. CTrader freezes within a couple of minutes of commencing a backtest, every time. It is currently unusable for me until this is resolved. Using version 5.0.25. Can we roll back to a previous version?
Your broker should have an older version of cTrader
hmmm, so for backtesting in non visual mode, the setting “tick-data” (instead of m1 data) will not be used, that was not clear to me and looks frankly spoken … wrong ;-)
but now I know how it works. Thank you for clarification!
By the way, how about Optimization, there we can also select "tick-data accurate”. Are the indicators there also only calculated once per bar? Because there is no visual mode available.
Thank you.
No that is not what I said. Indicators referenced in a strategy will use the source set in the backtesting settings. Indicators applied on the chart will be rendered at the moment they are applied, so all past bars will be considered historical
I am not sure what the problem is but if you subscribe to market data using 35=V, then you will receive 35=W and 35=X responses, which are real market data.
hello can I get the script for sample advanced take profit
I dont know what I did it just stop playing thank you hanselkate@outlook.com
Hi there,
Here it is
// -------------------------------------------------------------------------------------------------
//
// This code is a cTrader Automate API example.
//
// This cBot is intended to be used as a sample and does not guarantee any particular outcome or
// profit of any kind. Use it at your own risk.
//
// All changes to this file might be lost on the next application update.
// If you are going to modify this file please make a copy using the "Duplicate" command.
//
// -------------------------------------------------------------------------------------------------
using System;
using System.Linq;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SampleAdvancedTakeProfit : Robot
{
private const string DefaultPositionIdParameterValue = "PID";
[Parameter("Position Id", Group = "Position", DefaultValue = DefaultPositionIdParameterValue)]
public string PositionId { get; set; }
[Parameter("Enabled", Group = "Take Profit 1", DefaultValue = false)]
public bool TakeProfit1Enabled { get; set; }
[Parameter("Pips", Group = "Take Profit 1", DefaultValue = 10)]
public double TakeProfit1Pips { get; set; }
[Parameter("Volume", Group = "Take Profit 1", DefaultValue = 1000)]
public int TakeProfit1Volume { get; set; }
[Parameter("Enabled", Group = "Take Profit 2", DefaultValue = false)]
public bool TakeProfit2Enabled { get; set; }
[Parameter("Pips", Group = "Take Profit 2", DefaultValue = 20)]
public double TakeProfit2Pips { get; set; }
[Parameter("Volume", Group = "Take Profit 2", DefaultValue = 2000)]
public int TakeProfit2Volume { get; set; }
[Parameter("Enabled", Group = "Take Profit 3", DefaultValue = false)]
public bool TakeProfit3Enabled { get; set; }
[Parameter("Pips", Group = "Take Profit 3", DefaultValue = 10)]
public double TakeProfit3Pips { get; set; }
[Parameter("Volume", Group = "Take Profit 3", DefaultValue = 3000)]
public int TakeProfit3Volume { get; set; }
private TakeProfitLevel[] _levels;
private SymbolInfo _symbolInfo;
protected override void OnStart()
{
if (PositionId == DefaultPositionIdParameterValue)
PrintErrorAndStop("You have to specify \"Position Id\" in cBot Parameters");
var position = FindPositionOrStop();
_symbolInfo = Symbols.GetSymbolInfo(position.SymbolName);
_levels = GetTakeProfitLevels();
ValidateLevels(position);
}
private void ValidateLevels(Position position)
{
MakeSureAnyLevelEnabled();
ValidateTotalVolume(position);
ValidateReachedLevels(position);
ValidateVolumes();
}
private void ValidateVolumes()
{
var enabledLevels = _levels.Where(level => level.IsEnabled);
foreach (var level in enabledLevels)
{
if (level.Volume < _symbolInfo.VolumeInUnitsMin)
PrintErrorAndStop("Volume for " + _symbolInfo.Name + " cannot be less than " + _symbolInfo.VolumeInUnitsMin);
if (level.Volume > _symbolInfo.VolumeInUnitsMax)
PrintErrorAndStop("Volume for " + _symbolInfo.Name + " cannot be greater than " + _symbolInfo.VolumeInUnitsMax);
if (level.Volume % _symbolInfo.VolumeInUnitsMin != 0)
PrintErrorAndStop("Volume " + level.Volume + " is invalid");
}
}
private void ValidateReachedLevels(Position position)
{
var reachedLevel = _levels.FirstOrDefault(l => l.Pips <= position.Pips);
if (reachedLevel != null)
PrintErrorAndStop("Level " + reachedLevel.Name + " is already reached. The amount of Pips must be more than the amount of Pips that the Position is already gaining");
}
private void MakeSureAnyLevelEnabled()
{
if (_levels.All(level => !level.IsEnabled))
PrintErrorAndStop("You have to enable at least one \"Take Profit\" in cBot Parameters");
}
private void ValidateTotalVolume(Position position)
{
var totalVolume = _levels.Where(level => level.IsEnabled).Sum(level => level.Volume);
if (totalVolume > position.VolumeInUnits)
PrintErrorAndStop("The sum of all Take Profit respective volumes cannot be larger than the Position's volume");
}
private TakeProfitLevel[] GetTakeProfitLevels()
{
return new[]
{
new TakeProfitLevel("Take Profit 1", TakeProfit1Enabled, TakeProfit1Pips, TakeProfit1Volume),
new TakeProfitLevel("Take Profit 2", TakeProfit2Enabled, TakeProfit2Pips, TakeProfit2Volume),
new TakeProfitLevel("Take Profit 3", TakeProfit3Enabled, TakeProfit3Pips, TakeProfit3Volume)
};
}
private Position FindPositionOrStop()
{
var position = Positions.FirstOrDefault(p => "PID" + p.Id == PositionId || p.Id.ToString() == PositionId);
if (position == null)
PrintErrorAndStop("Position with Id = " + PositionId + " doesn't exist");
return position;
}
private void PrintErrorAndStop(string errorMessage)
{
Print(errorMessage);
Stop();
throw new Exception(errorMessage);
}
protected override void OnTick()
{
var position = FindPositionOrStop();
var reachedLevels = _levels.Where(level => level.IsEnabled && !level.IsTriggered && level.Pips <= position.Pips);
foreach (var reachedLevel in reachedLevels)
{
reachedLevel.MarkAsTriggered();
Print("Level \"" + reachedLevel.Name + "\" is reached. Level.Pips: " + reachedLevel.Pips + ", Position.Pips: " + position.Pips + ", Position.Id: " + position.Id);
var volumeToClose = Math.Min(reachedLevel.Volume, position.VolumeInUnits);
ClosePosition(position, volumeToClose);
if (!LastResult.IsSuccessful)
Print("Cannot close position, Id: " + position.Id + ", Error: " + LastResult.Error);
var remainingLevels = _levels.Where(level => level.IsEnabled && !level.IsTriggered);
if (!remainingLevels.Any())
{
Print("All levels were reached. cBot is stopping...");
Stop();
return;
}
}
}
}
internal class TakeProfitLevel
{
public TakeProfitLevel(string name, bool isEnabled, double pips, int volume)
{
Name = name;
IsEnabled = isEnabled;
Pips = pips;
Volume = volume;
}
public string Name { get; private set; }
public bool IsEnabled { get; private set; }
public double Pips { get; private set; }
public int Volume { get; private set; }
public bool IsTriggered { get; private set; }
public void MarkAsTriggered()
{
IsTriggered = true;
}
}
}
The bug is in your code. The difference between visual and non visual is that in visual mode, the indicator is calculated on every tick, while in non visual mode, the indicator is calculated once at the end of the backtesting. So in visual mode, your condition will become true at some tick while in non visual mode, it will never become true, since the calculate method is only called once per bar, considering only the closed prices.
I would suggest you use High/Low values instead of Close values to resolve the problem.
I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.
PanagiotisCharalampous
26 Jun 2024, 06:48 ( Updated at: 26 Jun 2024, 06:50 )
RE: RE: RE: RE: Non -executing the OnDestroy() function
AlgoCreators said:
Hi there,
Can you share the code you are using to delete the objects so that we can check?
Best regards,
Panagiotis
@PanagiotisCharalampous