| Overall Statistics |
|
Total Trades 49 Average Win 0.60% Average Loss -1.01% Compounding Annual Return -4.449% Drawdown 22.400% Expectancy -0.735 Net Profit -12.771% Sharpe Ratio -0.404 Probabilistic Sharpe Ratio 0.305% Loss Rate 83% Win Rate 17% Profit-Loss Ratio 0.59 Alpha -0.032 Beta -0.003 Annual Standard Deviation 0.081 Annual Variance 0.007 Information Ratio -0.753 Tracking Error 0.221 Treynor Ratio 11.731 Total Fees $0.00 |
class OptimizedCalibratedAutosequencers(QCAlgorithm):
def Initialize(self):
ticker = 'GBPUSD'
self.SetStartDate(2018, 1, 1)
self.SetEndDate(2021,1,1)
self.SetCash(100000)
self.AddForex(ticker, Resolution.Daily)
# INDICATOR CODE #
########################################################################
res = Resolution.Daily
self.fast = self.SMA(ticker, 50, res)
self.slow = self.SMA(ticker, 200, res)
self.true_range = self.ATR(ticker, 25, res)
def OnData(self, data):
ticker = 'GBPUSD'
position_price = self.Portfolio[ticker].AveragePrice
price = float(self.Securities[ticker].Price)
fast_cv = self.fast.Current.Value
slow_cv = self.slow.Current.Value
atr = self.true_range.Current.Value
# EXECUTION CODE #
########################################################################
#BUY CODE
if self.Portfolio[ticker].Quantity == 0:
if fast_cv > slow_cv:
self.SetHoldings(ticker , 1.0)
if self.Portfolio[ticker].Quantity > 0:
if price < position_price - 3*atr: # if short and price goes above (price when opened trade + 3*ATR )
self.Liquidate() # or if (fast SMA crosses above slow SMA)
elif fast_cv < slow_cv: # CLOSE TRADE
self.Liquidate()
########################################################################
#SELL CODE
if self.Portfolio[ticker].Quantity == 0:
if fast_cv < slow_cv:
self.SetHoldings(ticker , -1.0)
if self.Portfolio[ticker].Quantity < 0: # if short and price goes above (price when opened trade + 3*ATR )
if price > position_price + 3*atr: # or if (fast SMA crosses above slow SMA)
self.Liquidate() # CLOSE TRADE
elif fast_cv > slow_cv:
self.Liquidate()
# need to fix this code to get a higher win rate