The API provides all the data, it is left to the developer to implement code to filter the results, what you need to do is only return the patterns that have formed after a set date time. The example below shows a new parameter called Filter Date, the value you enter here will only return patterns formed after this date/time.
using cAlgo.API;
using ClickAlgo.Harmonic;
using ClickAlgo.Harmonics.Scanner;
using System;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
public class HARMONIC : Robot
{
[Parameter("BUY", DefaultValue = 10, MinValue = 1)]
public bool GOb { get; set; }
[Parameter("SELL", DefaultValue = 10, MinValue = 1)]
public bool GOs { get; set; }
[Parameter("VOLUME", DefaultValue = 0)]
public double Volume { get; set; }
[Parameter("SL", DefaultValue = 0, MinValue = 0)]
public double SL { get; set; }
[Parameter("TP", DefaultValue = 0)]
public double TP { get; set; }
[Parameter("Filter Date", DefaultValue = "12/02/2021 08:00")]
public string DateFormed { get; set; }
Client client;
private const string label1 = "BUY";
private const string label2 = "SELL";
DateTime _filterDate;
protected override void OnStart()
{
client = new Client();
// convert string to date time
_filterDate = DateTime.ParseExact(DateFormed, "dd/MM/yyyy hh:mm", null);
}
protected override void OnBar()
{
var patterns = client.GetAllPatterns(SymbolName);
if (patterns == null)
{
return;
}
foreach (var pattern in patterns)
{
// convert the date time string value from API into Date time object
DateTime patternDate = Convert.ToDateTime(pattern.Dateformed);
// filter results based on an accuracy of 98% and all patterns formed after the filter date parameter.
if (pattern.Accuracy > 98 && patternDate > _filterDate)
{
SubmitOrder(pattern);
}
}
}
private void SubmitOrder(Pattern pattern)
{
var gobuy1 = Positions.Find(label1, SymbolName, TradeType.Buy);
var gosell1 = Positions.Find(label2, SymbolName, TradeType.Sell);
if (pattern.Direction == "Bullish" && gobuy1 == null && GOb)
ExecuteMarketOrder(TradeType.Buy, SymbolName, Volume, label1, SL, TP);
if (pattern.Direction == "Bearish" && gosell1 == null && GOs)
ExecuteMarketOrder(TradeType.Sell, SymbolName, Volume, label2, SL, TP);
}
}
}
.
Regional Settings
The example above uses UK date-time formatting, for your country you will need to find your own pattern.
[Parameter("Filter Date", DefaultValue = "12/02/2021 08:00")]
Above you will see the format as Day/Month/Year Hour:Minute
To convert this to a DateTime object you will need to use the following code:
_filterDate = DateTime.ParseExact(DateFormed, "dd/MM/yyyy hh:mm", null);
As you can see above it used the same format, follow the link below for more information on converting date strings to date objects.
https://docs.microsoft.com/en-us/dotnet/standard/base-types/parsing-datetime
The above code is not tested and if you need further help regarding Date conversions from strings it would be best to post on StackOverflow.