Loop

What if you need to run the moving average crossover every 5 or 10 seconds… or continously ?

You can use the data.current function to pull the ‘price’ per second. Then, append it to a Python dataframe. Using the prices in the dataframe, the two moving averages can be computed. (e.g. 5-second and 15-second average prices).



A sample code below:







Note: Generate the trading signals only after the longer period timeframe data is available.



Thank you

Thanks for the answer. I still have some questions. 1: How do I pull out price per minute. 2. Does the iBridgepy monitor the market and execute when the condition occurs ? or do u need to keep on running the crossover file. sorry it was not very clear in the video

The code within handle_data(context, data) can be called every second or every minute. The default frequency is one second. You can change this by setting repBarFreq=60 in the RUN_ME.py file. When you use the IBridgePy API, it first establishes a connection with the Interactive Brokers Trader Workstation (TWS) or the IB Gateway. You need to have either of these platforms open on your system. Based on the set repBarFreq argument, your strategy code under the handle_data(context, data) runs eithe

Thank u… Do u have any Bollinger Band Sample also… How to Calculate it … i.e. Buy below lower Band and Sell Above upper

You can use the talib library to build the Bollinger bands. Check the link for more details: https://mrjbq7.github.io/ta-lib/

Thank u… I’m having a small problem… Trying to add Lupin but not able to get it picked up in the CSV Exchange of STK LUPIN is missing. Please add this security in IBridgePy/security_info.csv ( Already added ) SHY,NASDAQ,STK,USD, DAX,FUT,EUR,DTB, LUPIN,NSE,STK,INR,NSE,

Please subscribe to the specified stock data from IB site. If you already have an account and subscription, and if you are still not able to get the data, then please contact the IB support team.

Only under IBridgepy I am unable to get this data. In TWS and other locations this is showing

Hi Samir, You will be able to see the data in the charts, but to pull the data using an API you would need the subscription.

Not sure what subscription… Just a client right of the broker

All Subscription there but I am still getting the error … Exchange of STK XXXXXX is missing … Exchange and Primary exchange are NSE

I don’t know if I am doing something wrong… but even the file fileName=‘example_get_historical_data.py’ is not working on NSE

In the “security_info.csv” file add the following in an empty row: 1) Symbol for LUPIN 2) Specify the exchange and primaryExchange as NSE 3) Mention the secType as STK in case you are trading in the cash segment 4) Mention the sectype as FUT in case you are trading futures and OPT in case you are trading Options 5) Mention the currency as INR

Thank you problem solved. INR was added in this function if ‘,’ not in s1: s1=‘STK,%s,INR’ %(s1,) #USD

I'm having the same issue with "security_info.csv" for HK stocks (HKD).  Can you help clarify where/how you added "INR  in this function if ',' not in s1: s1='STK,%s,INR' %(s1,) #USD" in order to solve the issue please?  I think I need to do the same with HKD.  Thanks!