Back

Novice. I need to understand the LEAN principle.

Hi, first of all I would like to thank you for this amazing service! I really appreciate it and I'm very happy to have discovered this service.

Now to the problem ...

I came from the MT4 trading platform, where the situation was quite trivial. Thus, the backtest ran classically in time (from beginning to end) and the entire source code was executed (readed) once every time the price (tick) changed. Within the Event Handling Function - void OnTick().

Here, however, the situation is different, as I understand it. Can someone please explain it to me briefly.

In initialization, I set the data type, for example minute:

var aapl = AddEquity ("AAPL", Resolution.Minute);

Then comes the OnData event... However, it does not behave like OnTick(). What exactly is the difference?

For example, if I have it set up like this:

public override void OnData (Slice data)

How often will the code be executed in the backtest?

Or better yet, what exactly does this piece of code do? I don't really understand that OnData.

 

And the last question. How do I do the following ... so for every day, for a specific minute, some command will be executed (only once). For example, every trading day 10 minutes before the AAPL market closes, write something in the log ...

Thank you

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.


I'm not familiar with MT4, but here OnData is called every time data is streamed into the engine. Since you subscribed to minutely data, OnData will be called every minute during market hours. If you want it to be called every tick, simply change your asset to self.AddEquity("SPY", Resolution.Tick).

For the other question, look into scheduled functions in the docs. In Python this is done by:

def Initialize(self):
# Schedule LogSomething() to be called 10 minutes before market close
self.Schedule.On(self.DateRules.EveryDay("SPY"),
self.TimeRules.BeforeMarketClose(10),
self.LogSomething)
def LogSomething(self):
self.Log('Hello world.')

(change syntax for C#)

3

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