Is it possible to have algorithm run faster than every minute?

Back

I"m running live backtest on a scalping algo, and would love to see the difference in trading every 10 seconds rather than every minute...is that possible?

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.


Hi Bryan, 

you can use Resolution.Second and consolidate the bars to 10-second bars. 

1

I think the limitations block this?

Brokerage Warning: The API request has been rate limited. To avoid this message, please reduce the frequency of API calls. Brokerage Warning: The API request has been rate limited. To avoid this message, please reduce the frequency of API calls. Brokerage Warning: The API request has been rate limited. To avoid this message, please reduce the frequency of API calls.

0

This is where I had defined it.

self.twtr = self.AddEquity("twtr", Resolution.Second)

0

Yes its possible. Please post an algorithm or snippet for further assistance.

The error above is not related to LEAN but the algorithm design. It sounds like its using IB for history calls and hitting IB rate limit.

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.


Right now I'm running through Alpaca. Not trying to pull any historical data other than the current price of the ticker. Get that error if I change Resolution.Minute to Resolution.Second.

Maybe this is because I'm using "if" statements rather than something more elegant? Maybe I put in something that only loops when there's a transaction event?

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *

class NadionResistanceFlange(QCAlgorithm):

def Initialize(self):
self.twtr = self.AddEquity("twtr", Resolution.Minute)

self.Securities["twtr"].FeeModel = ConstantFeeModel(0.01)



def OnData(self, data):

currentprice_twtr = self.twtr.Price


currentqty_twtr = self.Portfolio["twtr"].Quantity

cash = self.Portfolio.Cash

# define first position and trading step size.
startingpoint_twtr = 46.00
stepsize_twtr = 1.00


# Define the trade value for buy and sell based on the quantity of shares held, starting point, and step size.
buyprice_twtr = startingpoint_twtr-stepsize_twtr*(currentqty_twtr)
sellprice_twtr = startingpoint_twtr+stepsize_twtr*(2-currentqty_twtr)


#start by cancelling all open orders
allCancelledOrders = self.Transactions.CancelOpenOrders()


#Start of a block
if currentqty_twtr == 0:
self.LimitOrder("twtr",1, startingpoint_twtr)

if currentqty_twtr != 0 and cash > buyprice_twtr:
self.LimitOrder("twtr",1,buyprice_twtr)
self.LimitOrder("twtr",-1,sellprice_twtr)

 

0

Hi Bryan,

The algorithm above issues orders very frequently. Thus by setting the resolution to second, it's exceeding the API limit.

Instead of cancelling all the open orders at each timestep, consider just sending a new limit order after one of the active ones is filled.

Best,
Derek Melchin

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.


At the bottom of the code, can I add something like this that says hold until an order is filled, then loop?

 

def OnOrderEvent(self, orderEvent):
order = self.Transactions.GetOrderById(orderEvent.OrderId)
if orderEvent.Status == OrderStatus.Filled:
Pass

 

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...

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!