Overall Statistics Total Trades0Average Win0%Average Loss0%Compounding Annual Return0%Drawdown0%Expectancy0Net Profit0%Sharpe Ratio0Loss Rate0%Win Rate0%Profit-Loss Ratio0Alpha0Beta0Annual Standard Deviation0Annual Variance0Information Ratio0Tracking Error0Treynor Ratio0Total Fees\$0.00
```### <summary>
### Simple RSI Strategy intended to provide a minimal algorithm example using
### one indicator
### </summary>
from clr import AddReference
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, 2, 1)      # 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)
# This is the period of our sma indicators
SimpleMovingAveragePeriod = 20
# This is the number of consolidated bars we'll hold in symbol data for reference
RollingWindowSize = 20

# Contains all of our forex symbols
ForexSymbols =["EURUSD", "GBPUSD", "USDCHF", "AUDUSD","NZDUSD"]

for symbol in ForexSymbols:
self.Data[symbol] = SymbolData(forex.Symbol, BarPeriod, RollingWindowSize)
# self.Data[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.first_stg_up[symbol] = 0
self.first_stg_down[symbol] = 0

def OnData(self,data):

# loop through each symbol in our structure
#Console.Write(self.c)
for symbol in self.Data.keys():
symbolData = self.Data[symbol]
# this check proves that this symbol was JUST updated prior to this OnData function being called

self.bb_ind = self.BB(symbol, 20, 1, MovingAverageType.Simple, Resolution.Hour);
self.slow = self.SMA(symbol, 1, Resolution.Hour)
self.fast = self.SMA(symbol, 1, Resolution.Hour)

fxOpen = data[symbol].Open
fxClose = data[symbol].Close
fxHigh = data[symbol].High
fxLow = data[symbol].Low
price = data[symbol].Price
#trend = self.trend_h(symbolData)
pip = (fxHigh - fxLow)*10000

# bb_ind = BB(data[symbol], 20, 1, MovingAverageType.Simple, Resolution.Hour);
#   slow = self.SMA(data[symbol], 20, Resolution.Hour)
#   fast = self.SMA(data[symbol], 7, Resolution.Hour)
trend_sma = np.where(self.fast.Current.Value > self.slow.Current.Value,1,0)

Console.Write(self.slow.Current.Value)
Console.Write(self.fast.Current.Value)
Console.Write(self.bb_ind.UpperBand.Current.Value)
if  self.long[symbol] == 0 and self.short[symbol] == 0:
if not self.Portfolio[symbol].Invested:
if  fxClose > fxOpen and trend_sma == 1 :#
self.first_stg_up[symbol] = 1
# Console.Write(symbol)
# Console.Write("heeey stage 1 signal buy")

if self.first_stg_up[symbol] == 1 and fxClose > self.bb_ind.LowerBand.Current.Value:
# Console.Write('99999')
#  Console.Write(symbol)
self.first_stg_down[symbol] = 0

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.signal_h_s = 0
#self.signal_h_b = 0
self.MarketOrder(symbol, self.quant)
#   Console.Write("trade 1 trade !!!!!!!!! " )

if self.price[symbol] > 0 and self.long[symbol] == 1 :

if data[symbol].Price >= self.tp_s[symbol] :
self.long[symbol] = 0
#  Console.Write("terminer tp" )
# Console.Write(symbol)
self.Liquidate(symbol)
if data[symbol].Price <= self.sl_s[symbol] :
self.long[symbol] = 0
#  Console.Write("terminer sl" )
#  Console.Write(symbol)
self.Liquidate(symbol)

class SymbolData(object):

def __init__(self, symbol, barPeriod, windowSize):
self.Symbol = symbol
# The period used when population the Bars rolling window
self.BarPeriod = barPeriod
# A rolling window of data, data needs to be pumped into Bars by using Bars.Update( tradeBar ) and can be accessed like:
# mySymbolData.Bars[0] - most first recent piece of data
# mySymbolData.Bars[5] - the sixth most recent piece of data (zero based indexing)
self.Bars = RollingWindow[IBaseDataBar](windowSize)
# The simple moving average indicator for our symbol