Topics
Replies
cW22Trader
03 Oct 2021, 18:57
RE:
Hi Panagiotis,
PanagiotisCharalampous said:
Hi cW22Trader,
How could the indicator already know the high and low value (sma period = 1) at 9 pm of the previous day (see 1. screen shot)?
Because you are retrieving data for historical bars that have already been closed. All the bars you retrieve are closed bars. When you get data using GetIndexByTime(), you don't get the bar as it was at the specific point of time, but the completed bar where the requested time falls in.
If you are looking to find the bar state at the specific point of time, then this functionality is not offered by the API. You will need to develop something yourself.
Best Regards,
Panagiotis
I understand that the API does not offer intermediat data of a past bar of a different time frame. Unfortunately, this makes it impossible to run in backtest since the data form a different time frame is futur data.
E.g. on a 1h chart with an indicator using data form the 4h time frame and simply displays the OHLC data as static text on chart, every time a new 4h bar starts it already shows the future high and low of the next 4h in visual backtesting. I would expect that the last bar of the 4h time frame "builds up" during the next 4h in visual backtesting and only stores the open, high, low and close of that bar once it is complete just like it does in real-time mode.
Kind regards
@cW22Trader
cW22Trader
08 Sep 2021, 23:28
( Updated at: 21 Dec 2023, 09:22 )
Historical Data is wrong
Hi,
Why is the historical data wrong when using a different time frame and retrieving the index by GetIndexByTime? How could the indicator already know the high and low value (sma period = 1) at 9 pm of the previous day (see 1. screen shot)? If I a reduce dataIndex by 1 it is correct but is this how you should use GetIndexByTime? If you leave the indicator on the chart for a while, the values calculated while the chart was open behave different then the ones calculated from historical data during initializaiton of the indicator (see 2. screen shot). The last 3 bars all have different low values (red line) but all others (calculated during init) alway have 2 same values (this was done on 1m chart with tf parameter set to 2m).
Kind regards
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TimeFrameMA : Indicator
{
[Parameter("Time Frame", DefaultValue = "Daily")]
public TimeFrame Timeframe { get; set; }
[Parameter("MA Periods", DefaultValue = 3, MinValue = 1)]
public int Periods { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Exponential)]
public MovingAverageType MAType { get; set; }
[Output("High", Thickness = 3)]
public IndicatorDataSeries High { get; set; }
[Output("Low", Thickness = 3, LineColor = "Red")]
public IndicatorDataSeries Low { get; set; }
private Bars data;
private MovingAverage maH, maL;
protected override void Initialize()
{
data = MarketData.GetBars(Timeframe);
maH = Indicators.MovingAverage(data.HighPrices, Periods, MAType);
maL = Indicators.MovingAverage(data.LowPrices, Periods, MAType);
}
public override void Calculate(int index)
{
var indexData = data.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (indexData > 0)
{
High[index] = maH.Result[indexData];
Low[index] = maL.Result[indexData];
}
}
}
}
@cW22Trader
cW22Trader
04 Aug 2021, 12:32
Use this every time PositionsOnClosed is called:
private double peak;
private List<double> drawdown = new List<double>();
private double CalcMaxDrawDown()
{
peak = Math.Max(peak, Account.Balance);
drawdown.Add((peak - Account.Balance) / peak * 100);
drawdown.Sort();
var maxDrawdown = drawdown[drawdown.Count - 1];
return maxDrawdown;
}
@cW22Trader
cW22Trader
03 Aug 2021, 00:27
Thanks for the answer.
Unfortunately, this example does not use any indicators it is code for an indicator. But how does it work in a bot using an indicator (e.g. an EMA)?
@cW22Trader
cW22Trader
29 Jul 2021, 22:17
( Updated at: 29 Jul 2021, 22:18 )
Could you also provide a simple example with an indicator used for multiple symbols at the same time?
Is it still initialized in OnStart? Do I need one per symbol or is this handled automatically?
Kind regards
@cW22Trader
cW22Trader
28 Jan 2022, 22:53
RE: Refer price/indicator values on different Range chart
Marin0ss said:
I think this is possible at least with Renko. This should be the same with Range bars.
But be carefull when using OHLC data of "higher" or larger TF. On historical data of e.g. on a chart it will use future data of the higher TF. E.g. a Ra100 bar just closed and your indicator algo gets triggered and you also get the data from the Ra500 bar using this API "Ra500bar.OpenTimes.GetIndexByTime(Ra100bar.OpenTimes[index])". The Ra500 bar may not be closed yet but since on historical data you only have access to completed OHLC data, you would use future data of that Ra500 bar which produces unrealistic results.
@cTrader Team: please correct me if I'm wrong...
Kind regards
@cW22Trader