Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
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, 1, 5)      #Set End Date
        self.SetCash(100000)             #Set Strategy Cash
        # Find more symbols here: http://quantconnect.com/data
   
        self.eurUsd = SymbolData(self,self.AddForex("EURUSD", Resolution.Minute).Symbol)
 


    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:
            self.Debug("Place Order!")
            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
            #Place an order with the following features:
            # - enter 100% long position once price of currency pair is above limitPrice
            # - close long position once the price of the currency pair is below stopLossPrice or above profitTargetPrice
        else:
            #cancel all open orders
            self.Debug("Cancel orders!")
            openOrders = self.Transactions.GetOpenOrders()
            if len(openOrders)> 0:
                for x in openOrders:
                     self.Transactions.CancelOrder(x.Id)
                        
        self.eurUsd.bbUpperPrevious = self.eurUsd.bb.UpperBand.Current.Value
        
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)