Overall Statistics
# Your New Python File
from main import *
from System import *
from QuantConnect import *

from datetime import datetime, timedelta
import pandas as pd
import decimal as d
import numpy as np

class BB_Algorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2015,1,1)
        self.SetEndDate(2018,12,31)
        self.SetCash(100000)
        
        self.Data = {}
        self.symbols = ["EURUSD", "EURGBP", "EURAUD", "EURJPY", "EURCAD",
                        "USDHKD", "USDJPY", "USDDKK", "USDCZK", "USDZAR",
                        "USDSEK", "USDSAR", "USDNOK", "USDMXN", "USDHUF"]
                        
        self.SetWarmUp(21)
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        self.SetTimeZone(DateTimeZone.Utc)
        
        for symbol in self.symbols:
            self.AddForex(symbol, Resolution.Daily, Market.Oanda)
            self.Data[symbol] = self.Bolband(symbol, 21, 2, MovingAverageType.Simple, Resolution.Daily)
        
        equity = self.AddForex(symbol, Resolution.Daily, Market.Oanda)
        self.currencies = equity.Symbol
        
    def OnData(self, data):
        
        price = self.Securities[symbols].price
        holdings = self.Portfolio[symbols].Quantity
        
        close = self.Securities[self.currencies.value].Close
        
        STOPLOSS_Long = self.StopmarketOrder(self.currencies, holdings, close * d.Decimal(1.0025))
        STOPLOSS_Short = self.StopmarketOrder(self.currencies, holdings, close * d.Decimal(.9975))
        
        if price >= self.Bolband.LowerBand.Current.Value:
           SetHoldings(symbol, 100)
           LimitOrder(self.currencies, holdings, close * d.Decimal(1.0025))
           StopMarketOrder(self.currencies, holdings, close * d.Decimal(.9975))
          
    def OnOrderEvent(self, orderEvent):
        order = self.Transactions.GetOrderById(orderEvent.OrderId)
        
        if order.Status == OrderStatus.Filled:
            if order.Type == OrderType.Limit or order.Type == OrderType.StopMarket:
                self.Transactions.CancelOpenOrders(order.Symbol)
                
        if order.Status == OrderStatus.Canceled:
            self.Log(str(orderEvent))