Beginner Help

Hi i am new to Quanconnect and this concept of quant trading. I am having this trouble whenever i run a backtest. No trades are bing executed and everything remains 0. ( fees , net equity etc. etc.) even when i'm just backtesting other people codes which are posted in the forum.

The code that i'm currently testing with:

from clr import AddReference

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
import numpy as np

class BasicTemplateAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2015,1, 1)  #Set Start Date
        self.SetEndDate(2017,12,31)    #Set End Date
        self.SetCash(1000)           #Set Strategy Cash
        self.AddForex("EURUSD", Resolution.Hour, Market.Oanda)
        sma_20 = self.SMA("EURUSD", 20, Resolution.Hour)
        sma_50 = self.SMA("EURUSD", 50, Resolution.Hour)
    def OnData(self, data):
        sma_20 = self.SMA("EURUSD", 20, Resolution.Hour)
        sma_50 = self.SMA("EURUSD", 50, Resolution.Hour)
        if self.Portfolio["EURUSD"].Invested<=150 and sma_20 > sma_50:
            self.MarketOrder("EURUSD", 1000)
        if sma_50 > sma_20:

Update Backtest

Welcome to the QuantConnect community! The reason as to why there are no trades is because the conditional statement for the market order is never satisfied. The property .Invested is a boolean value that checks to see if the algorithm is currently invested in the asset. Bootcamp is a great way to learn about QuantConnect and how to create trading strategies. The algorithm below is a working version of the one above. The key changes in the source code were to check if the boolean value was true or false, as opposed to 150, and the SMA indicators were initialized in the beginning before the data was pumped in as opposed to in OnData(). 


Update Backtest


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.


This discussion is closed