Hi All,

I want to realize a function by using RSI.

When RSI is over 80, short EURUSD, Take Profit when RSI hits 50, Stop Loss =100pips;

When RSI is below 20 long EURUSD, Take Profit when RSI hits 50, Stop Loss =100pips;

Each trade, i want to use half of the money for trading. Could you help on the code? Thanks.

import numpy as np

class RSIAlgorithm(QCAlgorithm):

def Initialize(self):

# Set our main strategy parameters
self.SetStartDate(2015,1, 1)   # Set Start Date
self.SetEndDate(2018,1,1)      # Set End Date
self.SetCash(10000)            # Set Strategy Cash

RSI_Period    = 14                # RSI Look back period
self.RSI_OB   = 80                # RSI Overbought level
self.RSI_OS   = 20                # RSI Oversold level
self.Allocate = 20             # Percentage of captital to allocate

# Find more symbols here: http://quantconnect.com/data
self.AddForex("EURUSD", Resolution.Daily,Leverage=1)
self.RSI_Ind = self.RSI("EURUSD", RSI_Period)

# Ensure that the Indicator has enough data before trading,.
self.SetWarmUp(RSI_Period)

def OnData(self, data):
if not self.Portfolio.Invested:
# If not, we check the RSI Indicator
if self.RSI_Ind.Current.Value < self.RSI_OS:
self.SetHoldings("EURUSD", self.Allocate)
else:
if self.RSI_Ind.Current.Value > self.RSI_OB:
self.short("EURUSD")