Overall Statistics Total Trades22Average Win0.33%Average Loss-0.28%Compounding Annual Return-62.872%Drawdown2.100%Expectancy-0.559Net Profit-1.616%Sharpe Ratio-7.86Loss Rate80%Win Rate20%Profit-Loss Ratio1.20Alpha-1.019Beta12.31Annual Standard Deviation0.104Annual Variance0.011Information Ratio-8.027Tracking Error0.104Treynor Ratio-0.066Total Fees\$0.00
```### <summary>
### Simple RSI Strategy intended to provide a minimal algorithm example using
### one indicator
### </summary>
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.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.first_stg_up = {}
self.first_stg_down = {}
self.Data = {}
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:
# self.Data[symbol] = SymbolData(forex.Symbol, BarPeriod, RollingWindowSize)
self.Data[symbol] = RollingWindow[QuoteBar](20)
self.price[symbol] = 0
self.short[symbol] = 0
self.long[symbol] = 0
self.sl_s[symbol] = 0
self.tp_s[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):

def SmaUpdated_s(self, sender, updated):

def OnData(self,data):

for symbol in self.Data.keys():
symbolData = self.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.

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

# 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)```