Overall Statistics
Total Trades
11
Average Win
0.00%
Average Loss
-0.01%
Compounding Annual Return
2.230%
Drawdown
2.200%
Expectancy
-0.751
Net Profit
2.061%
Sharpe Ratio
0.733
Loss Rate
80%
Win Rate
20%
Profit-Loss Ratio
0.25
Alpha
-0.025
Beta
2.665
Annual Standard Deviation
0.025
Annual Variance
0.001
Information Ratio
0.081
Tracking Error
0.025
Treynor Ratio
0.007
Total Fees
$0.00
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from datetime import datetime

### <summary>
### Simple indicator demonstration algorithm of MACD
### </summary>
### <meta name="tag" content="indicators" />
### <meta name="tag" content="indicator classes" />
### <meta name="tag" content="plotting indicators" />
class ForexScalping(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.'''

        self.SetStartDate(2015, 1, 1)    #Set Start Date
        self.SetEndDate(2015, 12, 5)      #Set End Date
        self.SetCash(5000)             #Set Strategy Cash
        # Find more symbols here: http://quantconnect.com/data
   
        self.eurUsd = SymbolData(self,self.AddForex("EURUSD", Resolution.Minute).Symbol)
        self.limitOrderTicket = None
        self.profitTargetOrderTicket = None
        self.stopLossOrderTicket = None

    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
        if not self.Portfolio.Invested \
        and self.eurUsd.macd.Current.Value>0 \
        and self.eurUsd.macd.Current.Value > self.eurUsd.macd.Signal.Current.Value \
        and self.eurUsd.bb.UpperBand.Current.Value>self.eurUsd.bbUpperPrevious \
        and self.eurUsd.rsi.Current.Value>0.7:
            stopLoss = self.eurUsd.atr.Current.Value * 0.1
            profitTarget = self.eurUsd.atr.Current.Value * 0.15
            currentPrice = data[self.eurUsd.symbol].Price
            stopLossPrice = currentPrice - stopLoss
            profitTargetPrice = currentPrice + profitTarget
            #limitPrice = self.eurUsd.bb.UpperBand.Current.Value
            self.Buy(self.eurUsd.symbol, 1000)
            self.LimitOrder(self.eurUsd.symbol, -1000, profitTargetPrice)
            self.StopMarketOrder(self.eurUsd.symbol, -1000, stopLossPrice)
        self.eurUsd.bbUpperPrevious = self.eurUsd.bb.UpperBand.Current.Value
        
    def OnOrderEvent(self, orderEvent):
        order = self.Transactions.GetOrderById(orderEvent.OrderId)
            
        if order.Status == OrderStatus.Filled:
            if order.Type == OrderType.Limit or order.Type == OrderType.Limit:
                self.Transactions.CancelOpenOrders(order.Symbol)
                
        if order.Status == OrderStatus.Canceled:
            self.Log(str(orderEvent))   
        
class SymbolData:
    def __init__(self,qcContext, symbol):
        self.qcContext = qcContext
        self.symbol = symbol
        self.macd = qcContext.MACD(self.symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Minute)
        self.qcContext.RegisterIndicator(self.symbol, self.macd, Resolution.Minute)
        self.bb = qcContext.BB(self.symbol, 12, 2,  Resolution.Minute)
        self.qcContext.RegisterIndicator(self.symbol, self.bb, Resolution.Minute)
        self.rsi =  qcContext.RSI(self.symbol, 7,  Resolution.Minute)
        self.qcContext.RegisterIndicator(self.symbol, self.rsi, Resolution.Minute)
        self.bbUpperPrevious = self.bb.UpperBand.Current.Value 
        self.atr = qcContext.ATR(self.symbol, 7, Resolution.Daily)
        self.qcContext.RegisterIndicator(self.symbol, self.atr, Resolution.Daily)

        #self.qcContext.PlotIndicator("MACD_"+self.symbol, True, self.macd, self.macd.Signal)