Topics
Replies
ys2310
11 Mar 2022, 05:49
RE: RE:
Hi amusleh,
I'm trying the following code and the index is -1
DateTime dt = Server.Time.AddMinutes(-128160);
int index = MarketData.GetBars(TimeFrame.Minute).OpenTimes.GetIndexByTime(dt);
Print("{0} {1}", index, MarketData.GetBars(TimeFrame.Minute).ClosePrices[index]);
if I instead use the code below the index has a value.
DateTime dt = Server.Time.AddMinutes(-1);
int index = MarketData.GetBars(TimeFrame.Minute).OpenTimes.GetIndexByTime(dt);
Print("{0} {1}", index, MarketData.GetBars(TimeFrame.Minute).ClosePrices[index]);
Is this because I'm referring way back in the past and there is no data with it?
How can I work around this problem? I want to get a correct value with the specified date and time.
Best regards,
@ys2310
ys2310
14 Feb 2022, 12:05
The following code returns index of two different time stamp. The two index show identical number. Why is this?
index1, index2 are supposed to be different numbers, no?
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
protected override void OnStart()
{
// Put your initialization logic here
var series5 = MarketData.GetBars(TimeFrame.Minute);
long index1 = series5.OpenTimes.GetIndexByTime(DateTime.Parse("2022-02-14 18:50:00"));
long index2 = series5.OpenTimes.GetIndexByTime(DateTime.Parse("2022-02-14 18:54:15"));
Print("{0} {1}", index1, index2);
}
}
}
@ys2310
ys2310
12 Feb 2022, 00:38
RE:
Thank you for the code, it seems bar.OpenTime creates identical results and I know this.
Discrepancies happen when I use MarketData.GetBars(TimeFrame.Minute, "SP") as a second symbol for data feed.
Can you also please try this on your side and check the difference?
Best regards,
@ys2310
ys2310
09 Feb 2022, 00:52
Hello amusleh, LoadMoreHistory method solved my problem.
though, I see there are small discrepancies in data obtained from backtesting and data obtained from Live.
Is there any method for this problem? backtesing results are different from Live results because of this data gap.
Best regards,
@ys2310
ys2310
03 Jan 2022, 09:13
( Updated at: 21 Dec 2023, 09:22 )
RE:
ys2310 said:
In my first screen shot, why do I see 5, 5, 6, 6 instead of 4, 5, 6, 7?
The last number is the number of opened position. it 4, 4, 4, 4, 4, 6, 6, 4, 4
positions.Count increments by 2 and the same number appears multiple times instead of
1, 2, 3, 4, 5... Am I misunderstanding anything here?
Hi,
I'm trying to count how many positions are open at each OnPositionsOpened() event inside of
this OnPositionsOpened() function. the num_of_open_position variable increment like 1,1, 2,2,
3, 3, 4, 4, 5, 5, 6, 6, instead of 1, 2, 3, 4, 5, 6. Anyone understands what's happening in this case?
---
private void OnPositionsOpened(PositionOpenedEventArgs args)
{
int num_of_open_position = 0;
foreach (var p in Positions)
num_of_open_position++;var position = args.Position;
Print("OnPositionOpened: {0} {1} {2} {3} {4}", position.Id, position.EntryTime, position.TradeType, position.Comment, num_of_open_position);
}
@ys2310
ys2310
03 Mar 2023, 10:14
Hello Panagiotis,
Thank you for the indicator! But when I tried use it from cBot like below, I got a run-time error:
26/10/2020 07:00:00.210 | Crashed in OnStart with NullReferenceException: Object reference not set to an instance of an object.
26/10/2020 07:00:00.210 | CBot instance [Test, XAUUSD, m1] crashed with error "Crashed in OnStart with NullReferenceException: Object reference not set to an instance of an object."
---
private MovingAverage _emaSignal;
private NewIndicator7 _emaDiff;
protected override void OnStart()
{
_emaSignal = Indicators.MovingAverage(_emaDiff.Result, 9, MovingAverageType.Exponential);
}
---
What might be wrong in here?
Thank you gain in advance.
@ys2310