Hello everyone,
1)
is there a way to store in variables previous days closing price? Each day in a single variable
(i.e. yesterday, the day before yesterday and so on).
2)
i want to enter trades only in specific hour of the day, is it possible to implement it?
(i.e. if var time > than 10:00 enter)
Thank you
Jing Wu
Hi DavidAckman, you could refer to this thread for the first question
In terms of the question (2), time variables like Time.Hour, Time.Minute and Time.Second would help. For your example,
if (Time.Hour > 10)
{
//enter trade
}
Quant Trader
You can also use a scheduled event for your timing. That does use event handler and not run over the complete dataset. You can declare a variable decimal _previousClose and set it on the OnData event if you have it run Daily or you use the OnEndOfDay() if you are using only one market.
// Fire plotting events once per day:
public override void OnEndOfDay()
DavidAckman
thank you both for your kind replies, they were helpfull!
I have 2 more questions if you don't mind:
1) how can i use 2 different resolutions on the same asset? lets say i want to know the high or the close of the last 5 bars for both daily and 5 minutes resolution?
2) i want to insert a stop market order with a stop loss at a specific price (so i want to set both the entry price and the stop loss price) how can i implement that?
thank you in advance,
you were very helpful
Quant Trader
1) look at consolidator in which you put 1 day of minute data as you need minutes resolution data as basis to get the 1 day. So you have 2 consolidators: 1 for a day and 1 for 5 minutes;
2) I am not sure, there are some samples around of stopp limit orders on bitcoins. Why not place a LimitOrder() at the time you want the specific pirce and stop loss to trigger?
DavidAckman
Thank you Quant Trader for your replies....
just to make sure... i create the 2 consolidators:
public override void Initialize(){
AddEquity("SPY", Resolution.Minute);
var fiveMinutes = new TradeBarConsolidator(TimeSpan.FromMinutes(5));
fiveMinutes.DataConsolidated += OnFiveMinutes;
SubscriptionManager.AddConsolidator("SPY", fiveMinutes);
var dailyMinutes = new TradeBarConsolidator(TimeSpan.FromMinutes(1440));
dailyMinutes.DataConsolidated += OnDaily;
SubscriptionManager.AddConsolidator("SPY", dailyMinutes);
}
public void OnFiveMinutes(object sender, TradeBar bar)
{
// how do i use rolling windows here to get previous 5min bars close high low etc?
//do i implement entry and exit here or on OnData method?
}
public void OnDaily(object sender, TradeBar bar)
{
// how do i use rolling windows here to get previous days close high low etc?
//do i implement entry and exit here or on OnData method?
}
DavidAckman
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!