Overall Statistics |
Total Trades 5 Average Win 4.77% Average Loss 0% Compounding Annual Return -0.367% Drawdown 15.200% Expectancy 0 Net Profit -0.582% Sharpe Ratio 0.03 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha -0.206 Beta 12.847 Annual Standard Deviation 0.114 Annual Variance 0.013 Information Ratio -0.113 Tracking Error 0.114 Treynor Ratio 0 Total Fees $2.00 |
import numpy as np from System.Drawing import Color from decimal import Decimal class stochasticIndicatorExample(QCAlgorithm): def Initialize(self): self.SetStartDate(2017, 6, 1) self.SetEndDate(2019, 1, 1) self.SetCash(5000) self.forex = self.AddForex("EURUSD", Resolution.Daily, Market.FXCM) self.SetBrokerageModel(BrokerageName.FxcmBrokerage) # Set the Stochastic Indicator self.stochasticIndicator = self.STO(self.forex.Symbol, 14,14, 3, Resolution.Daily) # Set parameters for "Trade Plot" self.overBought = 80 self.overSold = 20 # Construct "Trade Plot" IndicatorPlot = Chart("Trade Plot") IndicatorPlot.AddSeries(Series("D", SeriesType.Line,"", Color.Red)) IndicatorPlot.AddSeries(Series("K", SeriesType.Line,"", Color.Blue)) IndicatorPlot.AddSeries(Series("Over Bought", SeriesType.Line,"", Color.Black)) IndicatorPlot.AddSeries(Series("Over Sold", SeriesType.Line, "", Color.Black)) self.AddChart(IndicatorPlot) def OnData(self,data): if not self.stochasticIndicator.IsReady: return stochD=self.stochasticIndicator.StochD stochK=self.stochasticIndicator.StochK # Add values to "Trade Plot" self.Plot("Trade Plot", "D", str(stochD)) self.Plot("Trade Plot", "K", str(stochK)) self.Plot("Trade Plot", "Over Bought", str(self.overBought)) self.Plot("Trade Plot", "Over Sold", str(self.overSold)) # Enter a long position when the current value of the indicator is less than the 20 if not self.Portfolio.Invested and stochD.Current.Value < self.overSold: self.MarketOrder(self.forex.Symbol,10000) # Liquidate position when the current value of the indicator is greater than 80 elif self.Portfolio.Invested and stochD.Current.Value > self.overBought: self.Liquidate()