
Topics
Replies
whis.gg
03 Apr 2017, 13:52
Hi, just remove or comment following lines.
if (Time.Year >= 2016 && Time.Month >= 3 && Time.Day > 2) { ChartObjects.DrawText("Demo_Expired", "DEMO EXPIRED!!!\nDEMO EXPIRED!!!\nDEMO EXPIRED!!!\nDEMO EXPIRED!!!\nDEMO EXPIRED!!!\n", StaticPosition.TopLeft, Colors.Red); OnStop(); }
if (Time.Year >= 2016 && Time.Month >= 3 && Time.Day > 1) return;
@whis.gg
whis.gg
31 Mar 2017, 02:16
Sorry for late reply, I didn't notice you have replied already. :)
The code I have provided is based on daily net profit, not account balance growth. It sets daily net profit on monday and doesnt change during certain week. Onn each position closed it calculates current daily net profit and if it reached the target then it stops core logic till the next day.
Update OnPositionClosed() method to following and check the log if it's working as supposed.
private void OnPositionClosed(PositionClosedEventArgs obj) { double dailyNetProfit = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit); // sums net profit of current day // pauses core logic if daily net target was exceeded if (dailyNetProfit >= dailyNetTarget) { isPausedTillNextDay = true; Print("Pausing core logic till {0}. Daily Net target of {1} ({2} %) reached. Current net profit is {3} ({4} %).", nextDay, dailyNetTarget, DailyTargetPercentage, dailyNetProfit, Math.Round(dailyNetProfit / dailyNetTarget, 2)); } }
P.S.: That graph is looking like a holy grail already! Feel free to contact me via email below if you need to discus anything privately.
@whis.gg
whis.gg
29 Mar 2017, 13:40
Yes or you can put both between brackets.
if (!isPausedTillNextDay) { if (shortSignal) { EnterInPosition(TradeType.Sell); } else if (longSignal) { EnterInPosition(TradeType.Buy); } }
One more thing that should be updated in case the cBot would be started on Sunday.
Line 19: DateTime lastMonday = Time.AddDays(1 - (Time.DayOfWeek == 0 ? 7 : (int)Time.DayOfWeek)).Date Line 58: nextMonday = Time.AddDays(8 - (Time.DayOfWeek == 0 ? 7 : (int)Time.DayOfWeek)).Date;
Please keep in mind I haven't tested it so there might be more to fix.
@whis.gg
whis.gg
28 Mar 2017, 17:20
Updated code.
using System; using System.Linq; using cAlgo.API; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NotTestedSample : Robot { [Parameter("Daily Target %", DefaultValue = 1)] public double DailyTargetPercentage { get; set; } private DateTime nextMonday, nextDay; private double weeklyStartingBalance, dailyNetTarget; private bool isPausedTillNextDay; protected override void OnStart() { DateTime lastMonday = Time.AddDays(-(int)Time.DayOfWeek + 1).Date; HistoricalTrade trade = History.LastOrDefault(x => x.ClosingTime <= lastMonday); // finds last historical trade before this week weeklyStartingBalance = trade != null ? trade.Balance : Account.Balance; // if there is historical trade it uses its balance for better accuracy dailyNetTarget = weeklyStartingBalance * DailyTargetPercentage / 100; nextMonday = Time.AddDays(8 - (int)Time.DayOfWeek).Date; nextDay = Time.AddDays(1).Date; Positions.Closed += OnPositionClosed; } private void OnPositionClosed(PositionClosedEventArgs obj) { double dailyNet = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit); // sums net profit of current day // pauses core logic if daily net target was exceeded if (dailyNet >= dailyNetTarget) { isPausedTillNextDay = true; } } protected override void OnTick() { // unpauses core logic if it's new day if (Time >= nextDay) { isPausedTillNextDay = false; nextDay = Time.AddDays(1).Date; } // sets new daily net target on each Monday if (Time >= nextMonday) { weeklyStartingBalance = Account.Balance; dailyNetTarget = weeklyStartingBalance * DailyTargetPercentage / 100; nextMonday = Time.AddDays(8 - (int)Time.DayOfWeek).Date; } // passes if core logic isn't paused if (!isPausedTillNextDay) { // Put your core logic here } } } }
@whis.gg
whis.gg
28 Mar 2017, 17:11
I just realized you should update nextDay each new day with following code. Because of the weekends and days when daily net target isn't exceeded.
nextDay = Time.AddDays(1).Date;
And I forgot to set new nextMonday on each monday. Line 56:
nextMonday = Time.AddDays(8 - (int)Time.DayOfWeek).Date;
@whis.gg
whis.gg
28 Mar 2017, 17:03
Hi, you can start with that. Sorry if there is any error - I don't have time to test it.
using System; using System.Linq; using cAlgo.API; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NotTestedSample : Robot { [Parameter("Daily Target %", DefaultValue = 1)] public double DailyTargetPercentage { get; set; } private DateTime nextMonday, nextDay; private double weeklyStartingBalance, dailyNetTarget; private bool isPausedTillNextDay; protected override void OnStart() { DateTime lastMonday = Time.AddDays(-(int)Time.DayOfWeek + 1).Date; HistoricalTrade trade = History.FirstOrDefault(x => x.ClosingTime >= lastMonday); // finds first historical trade of this week weeklyStartingBalance = trade != null ? trade.Balance : Account.Balance; // if there is historical trade it uses its balance for better accuracy dailyNetTarget = weeklyStartingBalance * DailyTargetPercentage / 100; nextMonday = Time.AddDays(8 - (int)Time.DayOfWeek).Date; nextDay = Time.AddDays(1).Date; Positions.Closed += OnPositionClosed; } private void OnPositionClosed(PositionClosedEventArgs obj) { double dailyNet = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit); // sums net profit of current day // pauses core logic if daily net target was exceeded if (dailyNet >= dailyNetTarget) { isPausedTillNextDay = true; } } protected override void OnTick() { // unpauses core logic if it's new day if (isPausedTillNextDay && Time >= nextDay) { isPausedTillNextDay = false; nextDay = nextDay.AddDays(1); } // sets new daily net target on each Monday if (Time >= nextMonday) { weeklyStartingBalance = Account.Balance; dailyNetTarget = weeklyStartingBalance * DailyTargetPercentage / 100; } // passes if core logic isn't paused if (!isPausedTillNextDay) { // Put your core logic here } } } }
@whis.gg
whis.gg
28 Mar 2017, 16:10
Hi, try this.
double maximumBalance = double.MinValue; double minimumBalance = double.MaxValue; foreach (var historicalTrade in History) { maximumBalance = Math.Max(historicalTrade.Balance, maximumBalance); minimumBalance = Math.Min(historicalTrade.Balance, minimumBalance); }
@whis.gg
whis.gg
16 Mar 2017, 11:47
Try this.
using cAlgo.API; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NotificationTest : Indicator { protected override void Initialize() { Timer.Start(3); } protected override void OnTimer() { Notifications.PlaySound("C:\\Windows\\Media\\tada.wav"); } public override void Calculate(int index) { } } }
@whis.gg
whis.gg
27 Feb 2017, 12:19
Not sure if it's the best way but it's the one cAlgo uses.
using System; using cAlgo.API; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Vidya : Indicator { [Parameter()] public DataSeries Source { get; set; } [Parameter("Period", DefaultValue = 14)] public int Period { get; set; } [Parameter("Sigma", DefaultValue = 0.65, MinValue = 0.1, MaxValue = 0.95)] public double Sigma { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } public override void Calculate(int index) { double num = this.Result[index - 1]; if (double.IsNaN(num)) { num = Source[index - 1]; } double num2 = Sigma * Cmo(index); Result[index] = (1.0 - num2) * num + num2 * Source[index]; } private double Cmo(int index) { double num = 0.0; double num2 = 0.0; for (int i = 0; i < Period; i++) { double num3 = Source[index - i] - Source[index - i - 1]; if (num3 > 0.0) { num += num3; } else { num2 += -num3; } } if (num + num2 == 0.0) { return 0.0; } return Math.Abs((num - num2) / (num + num2)); } } }
@whis.gg
whis.gg
27 Feb 2017, 02:34
Hi, Time Series Moving Average is equal to Linear Regression Forecast. The cAlgo platform calculates it by multiplying Linear Regression Slope with Period plus Linear Regression Intercept. Here's is better solution that gives you same result.
using cAlgo.API; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class LinearRegression : Indicator { [Parameter()] public DataSeries Source { get; set; } [Parameter(DefaultValue = 14)] public int Period { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } public override void Calculate(int index) { double sumX = 0, sumY = 0, sumXY = 0, sumXPower = 0; for (int i = 0; i < Period; i++) { sumXPower += i * i; sumX += i; sumY += Source[index - i]; sumXY += i * Source[index - i]; } Result[index] = (sumXPower * sumY - sumX * sumXY) / (sumXPower * Period - sumX * sumX); } } }
@whis.gg
whis.gg
21 May 2017, 11:51
Why do you want to get a quote from all different timeframes at exact same time - every 60 seconds? This is going to return same price on all of them.
@whis.gg