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 ResetsProperly() { int _period = 5; DateTime time = DateTime.Now; InverseFisherTransform InvFisher = new InverseFisherTransform(_period); for (int i = 0; i < 6; i++) { InvFisher.Update(new IndicatorDataPoint(time, prices[i])); time.AddMinutes(1); } Assert.IsTrue(InvFisher.IsReady, "Instantaneous Trend ready"); InvFisher.Reset(); TestHelper.AssertIndicatorIsInDefaultState(InvFisher); }
public void InverseFisherComputesCorrectly() { int _period = 6; DateTime time = DateTime.Now; decimal[] actualValues = new decimal[20]; InverseFisherTransform InvFisher = new InverseFisherTransform(_period); for (int i = 0; i < prices.Length; i++) { InvFisher.Update(new IndicatorDataPoint(time, prices[i])); actualValues[i] = Math.Round(InvFisher.Current.Value, 6); Console.WriteLine(actualValues[i]); time.AddMinutes(1); } Assert.AreEqual(expectedValues, actualValues, "Estimation Inverse Fisher(6)"); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { //mylog.Debug(transheader); mylog.Debug(ondataheader); //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(22000); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); Price = new RollingWindow <IndicatorDataPoint>(14); cycleSignal = new RollingWindow <IndicatorDataPoint>(14); cycle = new CyberCycle(7); Price = new RollingWindow <IndicatorDataPoint>(14); diff = new RollingWindow <IndicatorDataPoint>(20); standardDeviation = new StandardDeviation(30); fish = new InverseFisherTransform(10); fishHistory = new RollingWindow <IndicatorDataPoint>(7); fishDirectionHistory = new RollingWindow <IndicatorDataPoint>(7); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { //mylog.Debug(transheader); mylog.Debug(ondataheader); //Initialize dates SetStartDate(_startDate); SetEndDate(_endDate); SetCash(22000); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); Price = new RollingWindow<IndicatorDataPoint>(14); cycleSignal = new RollingWindow<IndicatorDataPoint>(14); cycle = new CyberCycle(7); Price = new RollingWindow<IndicatorDataPoint>(14); diff = new RollingWindow<IndicatorDataPoint>(20); standardDeviation = new StandardDeviation(30); fish = new InverseFisherTransform(10); fishHistory = new RollingWindow<IndicatorDataPoint>(7); fishDirectionHistory = new RollingWindow<IndicatorDataPoint>(7); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { // mylog.Debug(",CurrentBar,Time,Price,smooth,low,i1,cycle0,cycle1,cycle2,fish,medianDelta,DC,instaperiod, v2,DCPeriod,realpart,imagpart,dcphase"); mylog.Debug(ondataheader); //mylog.Debug(",Time,CurrentBar,Direction,TradeProfit,,Price,Profit,HoldingCost,FillQty,Fees,TransAmt"); //mylog.Debug(transheader); //Initialize SetStartDate(2015, 05, 12); SetEndDate(2015, 05, 12); SetCash(25000); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute); _indicators = new AlgoIndicators { //BB = BB(_symbol, 20, 1, MovingAverageType.Simple, Resolution.Daily), RSI = RSI(_symbol, 14, MovingAverageType.Simple, Resolution.Daily), //ATR = ATR(_symbol, 14, MovingAverageType.Simple, Resolution.Daily), //EMA = EMA(_symbol, 14, Resolution.Daily), //SMA = SMA(_symbol, 14, Resolution.Daily), MACD = MACD(_symbol, 12, 26, 9, MovingAverageType.Simple, Resolution.Minute) //AROON = AROON(_symbol, 20, Resolution.Daily), //MOM = MOM(_symbol, 20, Resolution.Daily), //MOMP = MOMP(_symbol, 20, Resolution.Daily), //STD = STD(_symbol, 20, Resolution.Daily), //MIN = MIN(_symbol, 14, Resolution.Daily), // by default if the symbol is a tradebar type then it will be the min of the low property //MAX = MAX(_symbol, 14, Resolution.Daily), // by default if the symbol is a tradebar type then it will be the max of the high property //open = new WindowIndicator<IndicatorDataPoint>(4) //Ft = FT(_symbol, samplesize, Resolution.Minute), //Rvi = RVI(_symbol, samplesize, Resolution.Minute) }; //open = new RollingWindow<IndicatorDataPoint>(samplesize); //close = new RollingWindow<IndicatorDataPoint>(samplesize); //high = new RollingWindow<IndicatorDataPoint>(samplesize); //low = new RollingWindow<IndicatorDataPoint>(samplesize); //i1 = new RollingWindow<IndicatorDataPoint>(samplesize); //instperiod = new RollingWindow<IndicatorDataPoint>(samplesize); //v2 = new RollingWindow<IndicatorDataPoint>(samplesize); //v1 = new RollingWindow<IndicatorDataPoint>(samplesize); //Rvi = new RollingWindow<IndicatorDataPoint>(samplesize); unrealized = new RollingWindow<IndicatorDataPoint>(samplesize); iFishes = new RollingWindow<IndicatorDataPoint>(samplesize); RsiHistory = new RollingWindow<IndicatorDataPoint>(samplesize); //Signal = new RollingWindow<IndicatorDataPoint>(samplesize); //maxRvi = new Maximum("RVI_Max", samplesize); //minRvi = new Minimum("RVi_Min", samplesize); //maxSignal = new Maximum("Sig_Max", samplesize); //minSignal = new Minimum("Sig_Min", samplesize); fish = new FisherTransform(samplesize); ifish = new InverseFisherTransform(samplesize); //Crossing = new RollingWindow<IndicatorDataPoint>(samplesize); //FisherHistory = new RollingWindow<IndicatorDataPoint>(samplesize); Rvi = new RelativeVigorIndex(_symbol, samplesize); for (int x = 0; x < samplesize; x++) { //open.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //close.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //high.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //low.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //i1.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //instperiod.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //v1.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //v2.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //Rvi.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); unrealized.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); iFishes.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //Signal.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //Crossing.Add(new IndicatorDataPoint(DateTime.MinValue, .0001m)); } }
public override void OnInitialize() { ifsh = new InverseFisherTransform(); AddIndicator(ifsh); }
/// <summary> /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. /// </summary> /// <seealso cref="QCAlgorithm.SetStartDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetEndDate(System.DateTime)"/> /// <seealso cref="QCAlgorithm.SetCash(decimal)"/> public override void Initialize() { // mylog.Debug(",CurrentBar,Time,Price,smooth,low,i1,cycle0,cycle1,cycle2,fish,medianDelta,DC,instaperiod, v2,DCPeriod,realpart,imagpart,dcphase"); mylog.Debug(ondataheader); //mylog.Debug(",Time,CurrentBar,Direction,TradeProfit,,Price,Profit,HoldingCost,FillQty,Fees,TransAmt"); //mylog.Debug(transheader); //Initialize SetStartDate(2015, 05, 12); SetEndDate(2015, 05, 12); SetCash(25000); //Add as many securities as you like. All the data will be passed into the event handler: AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute); _indicators = new AlgoIndicators { //BB = BB(_symbol, 20, 1, MovingAverageType.Simple, Resolution.Daily), RSI = RSI(_symbol, 14, MovingAverageType.Simple, Resolution.Daily), //ATR = ATR(_symbol, 14, MovingAverageType.Simple, Resolution.Daily), //EMA = EMA(_symbol, 14, Resolution.Daily), //SMA = SMA(_symbol, 14, Resolution.Daily), MACD = MACD(_symbol, 12, 26, 9, MovingAverageType.Simple, Resolution.Minute) //AROON = AROON(_symbol, 20, Resolution.Daily), //MOM = MOM(_symbol, 20, Resolution.Daily), //MOMP = MOMP(_symbol, 20, Resolution.Daily), //STD = STD(_symbol, 20, Resolution.Daily), //MIN = MIN(_symbol, 14, Resolution.Daily), // by default if the symbol is a tradebar type then it will be the min of the low property //MAX = MAX(_symbol, 14, Resolution.Daily), // by default if the symbol is a tradebar type then it will be the max of the high property //open = new WindowIndicator<IndicatorDataPoint>(4) //Ft = FT(_symbol, samplesize, Resolution.Minute), //Rvi = RVI(_symbol, samplesize, Resolution.Minute) }; //open = new RollingWindow<IndicatorDataPoint>(samplesize); //close = new RollingWindow<IndicatorDataPoint>(samplesize); //high = new RollingWindow<IndicatorDataPoint>(samplesize); //low = new RollingWindow<IndicatorDataPoint>(samplesize); //i1 = new RollingWindow<IndicatorDataPoint>(samplesize); //instperiod = new RollingWindow<IndicatorDataPoint>(samplesize); //v2 = new RollingWindow<IndicatorDataPoint>(samplesize); //v1 = new RollingWindow<IndicatorDataPoint>(samplesize); //Rvi = new RollingWindow<IndicatorDataPoint>(samplesize); unrealized = new RollingWindow <IndicatorDataPoint>(samplesize); iFishes = new RollingWindow <IndicatorDataPoint>(samplesize); RsiHistory = new RollingWindow <IndicatorDataPoint>(samplesize); //Signal = new RollingWindow<IndicatorDataPoint>(samplesize); //maxRvi = new Maximum("RVI_Max", samplesize); //minRvi = new Minimum("RVi_Min", samplesize); //maxSignal = new Maximum("Sig_Max", samplesize); //minSignal = new Minimum("Sig_Min", samplesize); fish = new FisherTransform(samplesize); ifish = new InverseFisherTransform(samplesize); //Crossing = new RollingWindow<IndicatorDataPoint>(samplesize); //FisherHistory = new RollingWindow<IndicatorDataPoint>(samplesize); Rvi = new RelativeVigorIndex(_symbol, samplesize); for (int x = 0; x < samplesize; x++) { //open.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //close.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //high.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //low.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //i1.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //instperiod.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //v1.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //v2.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //Rvi.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); unrealized.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); iFishes.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //Signal.Add(new IndicatorDataPoint(DateTime.MinValue, 0m)); //Crossing.Add(new IndicatorDataPoint(DateTime.MinValue, .0001m)); } }