Hi i am a new coder so please help me if you can.
import numpy as np
### <summary>
### Basic template algorithm simply initializes the date range and cash. This is a skeleton
### framework you can use for designing an algorithm.
### </summary>
class BasicTemplateAlgorithm(QCAlgorithm):
'''Basic template algorithm simply initializes the date range and cash'''
def Initialize(self):
self.SetStartDate(2017,1, 1) #Set Start Date
self.SetEndDate(2017,12,31) #Set End Date
self.SetCash(5000) #Set Strategy Cash
self.AddForex("EURGBP", Resolution.Hour, Market.Oanda)
self.SetBrokerageModel(BrokerageName.OandaBrokerage)
self.rsi = self.RSI("EURGBP", 14)
def OnData(self, data):
if not self.rsi.IsReady:
return
if self.rsi.Current.Value < 30 and self.Portfolio["EURGBP"].Invested <= 0:
self.Debug("RSI is less then 30")
self.MarketOrder("EURGBP", 25000)
self.Debug("Market order was placed")
if self.rsi.Current.Value > 70:
self.Debug("RSI is greater then 70")
self.Liquidate()
def OnEndOfDay(self):
self.Plot("Indicators","RSI", self.rsi.Current.Value)
Basically i want to replace the exit from RSI is greater then 70") to a volexpclose Atr indicator.
input numATRs = 1.5;
input length = 5;
input averageType = AverageType.SIMPLE;
def val = MovingAverage(averageType, TrueRange(high, close, low), length);
def condition = low[-1] <= close - val * numATRs;
thanks in advance!
Shile Wen
Hi Oscar,
To create a Simple Moving Average of the True Range, we can use ATR and specify its Moving Average Type as Simple. Furthermore, we can access the closing and low price from the bars passed in through OnData. I've shown both in the attached backtest.
Best,
Shile Wen
Oscar Ferrel
Hi Shile,
Thanks for your answer, unfortunately i was looking for the past bar[-1] in my ART exit condition..
And if the condition is true the idea is to sell at open of the next bar.
Thank you again!
Shile Wen
Hi Oscar,
We can store the past bar as a field, and access it when we need it. I've shown this in the attached backtest.
Best,
Shile Wen
Oscar Ferrel
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!