public DIFStrategy(Indicator Price, int DecyclePeriod = 20, int InvFisherPeriod = 40, decimal Threshold = 0.9m, decimal Tolerance = 0.001m) { // Initialize the fields. _decyclePeriod = DecyclePeriod; _invFisherPeriod = InvFisherPeriod; _threshold = Threshold; _tolerance = Tolerance; // Initialize the indicators used by the Strategy. _price = Price; DecycleTrend = new Decycle(_decyclePeriod).Of(Price); InverseFisher = new InverseFisherTransform(_invFisherPeriod).Of(DecycleTrend); InvFisherRW = new RollingWindow<decimal>(2); LightSmoothPrice = new Decycle(10).Of(Price); Momersion = new MomersionIndicator(10, 30).Of(LightSmoothPrice, false); // Fill the Inverse Fisher rolling windows at every new InverseFisher observation. // Once the Inverse Fisher rolling windows is ready, at every InverseFisher update, the Check signal method will be called. InverseFisher.Updated += (object sender, IndicatorDataPoint updated) => { if (InverseFisher.IsReady) InvFisherRW.Add(updated); if (InvFisherRW.IsReady) CheckSignal(); }; Position = StockState.noInvested; EntryPrice = null; ActualSignal = OrderSignal.doNothing; }
public DIFStrategy(Indicator Price, int DecyclePeriod = 20, int InvFisherPeriod = 40, decimal Threshold = 0.9m, decimal Tolerance = 0.001m) { // Initialize the fields. _decyclePeriod = DecyclePeriod; _invFisherPeriod = InvFisherPeriod; _threshold = Threshold; _tolerance = Tolerance; // Initialize the indicators used by the Strategy. _price = Price; DecycleTrend = new Decycle(_decyclePeriod).Of(Price); InverseFisher = new InverseFisherTransform(_invFisherPeriod).Of(DecycleTrend); InvFisherRW = new RollingWindow <decimal>(2); LightSmoothPrice = new Decycle(10).Of(Price); Momersion = new MomersionIndicator(10, 30).Of(LightSmoothPrice, false); // Fill the Inverse Fisher rolling windows at every new InverseFisher observation. // Once the Inverse Fisher rolling windows is ready, at every InverseFisher update, the Check signal method will be called. InverseFisher.Updated += (object sender, IndicatorDataPoint updated) => { if (InverseFisher.IsReady) { InvFisherRW.Add(updated); } if (InvFisherRW.IsReady) { CheckSignal(); } }; Position = StockState.noInvested; EntryPrice = null; ActualSignal = OrderSignal.doNothing; }
public void InstantaneousTrendComputesCorrectly() { int _period = 5; DateTime time = DateTime.Now; decimal[] actualValues = new decimal[20]; Decycle dTrend = new Decycle(_period); # region Arrays inputs
public override void Initialize() { SetStartDate(_startDate); //Set Start Date SetEndDate(_endDate); //Set End Date SetCash(_initialCapital); //Set Strategy Cash #region Logging stuff - Initializing Operations Logging transactionLogging.AppendLine("Time,Symbol,Order"); dailyProfitsLogging.AppendLine("Date,Symbol,Trades,Profit/Loss"); int i = 0; // Only used for logging. #endregion Logging stuff - Initializing Operations Logging foreach (string symbol in Symbols) { AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); // Define and register a Decycle indicator to be // injected in the Strategy. var decycle = new Decycle("Decycle_" + symbol, DecyclePeriod); RegisterIndicator(symbol, decycle, Resolution.Minute, Field.Close); // Define the PSAR for each symbol PSARDict.Add(symbol, new ParabolicStopAndReverse(afStart: 0.01m, afIncrement:0.001m, afMax: 0.2m)); RegisterIndicator(symbol, PSARDict[symbol], Resolution.Minute); Strategy.Add(symbol, new MSAStrategy(decycle, PreviousDaysN, RunsPerDay)); // Define the Share size for each symbol. ShareSize.Add(symbol, (maxLeverage * maxExposure) / Symbols.Count()); // Strategy warm-up. var history = History(symbol, (PreviousDaysN + 1) * 390); foreach (var bar in history) { decycle.Update(bar.EndTime, bar.Close); } #region Logging stuff - Initializing Stock Logging stockLogging.Add(new StringBuilder()); stockLogging[i].AppendLine("Time,Close,Decycle,PSAR,Position"); i++; #endregion Logging stuff - Initializing Stock Logging } #region Schedules // Set flags correctly at market open Schedule.Event("MarketOpen") .EveryDay() .At(9, 29) //.AfterMarketOpen(Symbols[0], minutesAfterOpen: -1) .Run(() => { isMarketJustOpen = true; isMarketAboutToClose = false; Log(string.Format("========== {0} Market Open ==========", Time.DayOfWeek)); }); Schedule.Event("MarketOpenSpan") .EveryDay() .At(9, 50) .Run(() => isMarketJustOpen = false); Schedule.Event("MarketAboutToClose") .EveryDay() .At(15, 50) //.BeforeMarketClose(Symbols[0], minuteBeforeClose: 10) .Run(() => isMarketAboutToClose = true); Schedule.Event("MarketClose") .EveryDay() .At(15, 59) //.BeforeMarketClose(Symbols[0], minuteBeforeClose: 10) .Run(() => CloseDay()); #endregion Schedules }