Overall Statistics
Total Trades
22
Average Win
0.33%
Average Loss
-0.28%
Compounding Annual Return
-62.872%
Drawdown
2.100%
Expectancy
-0.559
Net Profit
-1.616%
Sharpe Ratio
-7.86
Loss Rate
80%
Win Rate
20%
Profit-Loss Ratio
1.20
Alpha
-1.019
Beta
12.31
Annual Standard Deviation
0.104
Annual Variance
0.011
Information Ratio
-8.027
Tracking Error
0.104
Treynor Ratio
-0.066
Total Fees
$0.00
### <summary>
### Simple RSI Strategy intended to provide a minimal algorithm example using
### one indicator
### </summary>
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")
import time
import matplotlib.pyplot as plt
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from datetime import datetime
from System import *
from QuantConnect import *
from QuantConnect.Data.Consolidators import *
from QuantConnect.Data.Market import *
from QuantConnect.Orders import OrderStatus
from QuantConnect.Algorithm import QCAlgorithm
from QuantConnect.Indicators import *
import numpy as np
from datetime import timedelta, datetime
import pandas 
import numpy as np 
### <summary>
### Simple RSI Strategy intended to provide a minimal algorithm example using
### one indicator
### </summary>
class MultipleSymbolConsolidationAlgorithm(QCAlgorithm):
    
    
    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        
      
        # Set our main strategy parameters
        self.SetStartDate(2015, 1, 1)
        self.SetEndDate(2015, 1, 6)      # Set End Date
        self.SetCash(10000)    
        self.quant = 10000
        
        self.spread = 15/10000
        self.spread_15 = 15/10000
        self.first_stg_up = 0
        self.first_stg_down = 0
        
        self.pip_s = 5
        
        self.tp = 33/10000
        self.sl = 14/10000
        self.tp_s = {} 
        self.sl_s = {} 
        self.tp_s_n = 0 
        self.sl_s_n = 0
        self.long = {} 
        self.short = {}
        self.price = {} 
        self.trade_ind = {}
        self.first_stg_up = {} 
        self.first_stg_down = {}
        self.Data = {}
        self.trades = {}
        self.c = 0 
        
        
        BarPeriod = TimeSpan.FromHours(20)
        
        SimpleMovingAveragePeriod = 20
        
        RollingWindowSize = 20
        
        self.window = RollingWindow[QuoteBar](20)
        
        ForexSymbols =["EURUSD", "GBPUSD"]#, "USDCHF", "AUDUSD","NZDUSD"]
     
        for symbol in ForexSymbols:
            forex = self.AddForex(symbol, Resolution.Hour)
           # self.Data[symbol] = SymbolData(forex.Symbol, BarPeriod, RollingWindowSize)
            self.Data[symbol] = RollingWindow[QuoteBar](20)
            self.trades[symbol] = 0
            self.price[symbol] = 0
            self.short[symbol] = 0
            self.long[symbol] = 0
            self.sl_s[symbol] = 0
            self.tp_s[symbol] = 0
            self.trade_ind[symbol] = 0
            self.first_stg_up[symbol] = 0 
            self.first_stg_down[symbol] = 0
          
        for symbol, symbolData in self.Data.items():
            symbolData.sma_f = self.SMA(symbol, 20)
            symbolData.sma_s = self.SMA(symbol, 7)
            
            
            
            symbolData.sma_f.Updated += self.SmaUpdated
            self.smaWin_f = RollingWindow[IndicatorDataPoint](20)
            
            symbolData.sma_s.Updated += self.SmaUpdated_s
            self.smaWin_s = RollingWindow[IndicatorDataPoint](20)
            self.SetWarmUp(timedelta(20))
        
            
    def SmaUpdated(self, sender, updated):
        self.smaWin_f.Add(updated)
    
    def SmaUpdated_s(self, sender, updated):
        self.smaWin_s.Add(updated)
        
        
        
        
    def OnData(self,data):
        
        for symbol in self.Data.keys():
            symbolData = self.Data[symbol]
            
            self.Data[symbol].Add(data[symbol])


            
  
            fxOpen = data[symbol].Open         
            fxClose = data[symbol].Close
            fxHigh = data[symbol].High
            fxLow = data[symbol].Low
            price = data[symbol].Price
            pip = (fxHigh - fxLow)*10000
            
            
            currSma = self.smaWin_f[0]                     
            
            
            #Console.Write(symbol)
            #Console.Write(currSma)
            
            
            
       
            trend_sma = np.where(self.smaWin_f[0] > self.smaWin_s[0],1,0)
            
                 # this is a test to write the sma value to the consol, this is where the error occure.

            # Trade logic: 

            if  self.long[symbol] == 0 and self.short[symbol] == 0:
                if not self.Portfolio[symbol].Invested:
                    if  fxClose > fxOpen:# and trend_sma == 1 :         # The trend sma parameter do not work as i do not get any parameters from the sma  
                        self.first_stg_up[symbol] = 1 
       
            
                    if self.first_stg_up[symbol] == 1 :#and fxClose > self.bb_ind.LowerBand.Current.Value:
                
                        self.first_stg_down[symbol] = 0
                        self.trade_ind[symbol] = 1
                
            
          
           
        
        # Line 137 - 161 take trade, stopp loss and tp function (works not any faults in here) 
            
            if not self.Portfolio[symbol].Invested:
                if pip >self.pip_s and fxOpen < fxClose and self.trade_ind[symbol] == 1 :
                        if  self.long[symbol] == 0 and self.short[symbol] == 0: 
                 
                            self.price[symbol] = data[symbol].Price
                            self.tp_s[symbol] = price + self.tp
                            self.sl_s[symbol] = price - self.sl
                            self.long[symbol] = 1
                            self.MarketOrder(symbol, self.quant)
                   
     
            if self.price[symbol] > 0 and self.long[symbol] == 1 : 
                    
                    if data[symbol].Price >= self.tp_s[symbol] :
                        self.long[symbol] = 0 
                        self.Liquidate(symbol) 
                    if data[symbol].Price <= self.sl_s[symbol] :
                        self.long[symbol] = 0 

                        self.Liquidate(symbol)