Back

EMA/SMA Indicator Issues

Hello! This my first post so here goes: i am working on an algo that uses the 13ema and the 20sma and tracks when they cross on the 1hour time frame. I don't get any errors when it runs but when i look at the test trades it made they dont align with the same indicator crossover data from my Oanda charts. Did i set these up correctly or am i missing something to make these indicators show the true data. I'd laso like to have it execute the trade as soon as they cross instead of waiting on the 1 hour candle to close. Please help & thanks in advance!

   
 

def __init__(self):
self.symbol = "EURUSD"
self.previous = None
self.fast = None
self.slow = None

def Initialize(self):

self.SetStartDate(2017,6,25) #Set Start Date
self.SetEndDate(2018,2,1) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.AddForex("EURUSD", Resolution.tick, Market.Oanda) #Set time frame for bars.

# create a 13 period exponential moving average
self.fast = self.EMA(self.symbol, 13, Resolution.hour);

# create a 20 period simple moving average
self.slow = self.SMA(self.symbol, 20, Resolution.hour);

self.PlotIndicator("EMA", self.fast);
self.PlotIndicator("SMA", self.slow);

self.previous = None

def OnData(self, data):

# wait for our fast ema to fully initialize
if not self.fast.IsReady:
return

# wait for our slow ema to fully initialize
if not self.slow.IsReady:
return
Update Backtest








hi,

add next time the full backtest so the code is included....people can clone it and help you better.

take a look at consolidators i think you play to use it.

but its a very good start!! :)

so you have taken maybe from here:

https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python

 

the MovingAverageCrossAlgorithm.py example and modified it?

you could subscribe to minute data instead to tick.

with minute data you could consolidate one minute data to one hour.

take a look at the DataConsolidationAlgorithm.py

But still when you get the data every hour you can execute the order? where is the 1 hour delay?

1

Thanks so much! I really appreciate the help! I've attached the latest backtest as requested. With the 1hour time frame being a standard and listed one what would the consolidators do for me? Just trying to understand why the 1hr cross on here doesnt match the 1hr cross on my Oanda chart and how to get it to line up correctly.

0


the ondata gets called every hour right!? so if you get the last value at 4 o 'clock its too late to get out. (you didnt set extended market hours to true....so last candle for you is at 4 which is than a market on open order. if the trend goes in the wrong direction you would want to go out of the trade at the last candle if its a cross over.......BUT!!! thats something you would have to test!!!!!!!! very few orders which shouldnt be executed.....

you would calcutlate two ema & sma to check with the last minute candle if its a crossover and get out. 

thats a usecase for minute subscription and consolidate to one hour.

with an event like BeforeMarketClose you could check something like that.

0

So even though its the forex market the data treats it according to the standard stock market hours? That's very interesting. I'll dig into the BeforeMarketClose to see what i can find on that. Thanks!

0

Update Backtest





0

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.


Loading...

This discussion is closed