Overall Statistics
Total Trades
71
Average Win
0.39%
Average Loss
-0.23%
Compounding Annual Return
-47.029%
Drawdown
2.400%
Expectancy
-0.105
Net Profit
-1.039%
Sharpe Ratio
-9.71
Loss Rate
67%
Win Rate
33%
Profit-Loss Ratio
1.69
Alpha
-0.614
Beta
5.387
Annual Standard Deviation
0.054
Annual Variance
0.003
Information Ratio
-10.032
Tracking Error
0.054
Treynor Ratio
-0.097
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.Data = {}
        ForexSymbols =["EURUSD", "GBPUSD", "USDCHF", "AUDUSD","NZDUSD"]
        for symbol in ForexSymbols:
            forex = self.AddForex(symbol, Resolution.Hour).Symbol
            self.Data[forex] = SymbolData(forex, self)
            
            
    def OnData(self,data):
        for symbol in self.Data.keys():
            self.Data[symbol].trade(data[symbol])
            
            

class SymbolData(object):
    
    def __init__(self, symbol, algorithm):
        self.symbol = symbol
        self.algorithm = algorithm
        self.quant = 10000
        self.spread = 15/10000
        self.spread_15 = 15/10000
        
        self.pip_s = 5
        self.tp = 33/10000
        self.sl = 14/10000
        self.trades = 0
        self.price = 0
        self.short = 0
        self.long = 0
        self.sl_s = 0
        self.tp_s = 0
        self.trade_ind = 0
        self.first_stg_up = 0
        self.first_stg_down = 0
        
        self.sma_f = self.algorithm.SMA(symbol, 20)
        self.sma_s = self.algorithm.SMA(symbol, 7)
        self.bars = RollingWindow[QuoteBar](20)
    
    def trade(self, bar):
        pip = (bar.High - bar.Low)*10000
        currSma = self.sma_f.Current.Value
        trend_sma = np.where(self.sma_f.Current.Value > self.sma_s.Current.Value,1,0)
        
        if self.long == 0 and self.short == 0:
            if not self.algorithm.Portfolio[self.symbol].Invested:
                if  bar.Close > bar.Open:
                    self.first_stg_up = 1 
   
                if self.first_stg_up == 1:
                    self.first_stg_down = 0
                    self.trade_ind = 1
                    
        if not self.algorithm.Portfolio[self.symbol].Invested:
            if pip >self.pip_s and bar.Open < bar.Close and self.trade_ind == 1 :
                if  self.long == 0 and self.short == 0: 
                    self.price = bar.Price
                    self.tp_s = bar.Price + self.tp
                    self.sl_s = bar.Price - self.sl
                    self.long = 1
                    self.algorithm.MarketOrder(self.symbol, self.quant)
                   
     
        if self.price > 0 and self.long == 1: 
                
            if bar.Price >= self.tp_s:
                self.long = 0
                self.algorithm.Liquidate(self.symbol) 
            if bar.Price <= self.sl_s:
                self.long = 0
                self.algorithm.Liquidate(self.symbol)