regards to everyone,
for a number of months now i have been trying to find - develop a trading system that would allow me to trade in long options positions automated (opening long positions in calls in a symbol instead of a long position in shares and long positions in puts instead of short positions in shares). currently i'm making some of the trades by hand after i receive email alerts but it would be preferable to find a method to automate the entries and exits as this could allow me to trade a larger number of symbols simultaneously, and also evaluate some faster strategies i have developed that hold a lot of promise if i could find a method to trade them instantly. ¿does anyone know whether quantconnect could be modified to open and close long positions on options following email alerts? i have a number of strategies on tradestation and every time an uptrend or downtrend begins or ends the platform generates an email alert like the following:
the subject line reads:
TradeStation : Chart Analysis Alert for -company ticker- by -indicator- (inputs)
and this is the body of the email:
Thu 3/21/2019 11:13 PM
TradeStation : Chart Analysis Alert for -company ticker- by -indicator- (inputs)
Info: Price crossing over average
Source: -indicator(inputs)
Occurred: 22-Mar-19 01:13:42
Price: 00.00
i can change the text on the info line to anything i wanted to, for example: buy call, sell call, buy put, sell put, etc as appropriate. the ticker for the symbol that generated the alert is always included iin the emails texts so i think it should be possible to create an automated system that received these alerts and bought and sold options through interactive brokers' api. ¿does anyone think this could this be feasible? the symbol to be traded and the specific operation to be carried out (buy a call, sell all calls, buy a put, sell all puts) would be determined from the information on the email but the platform would need to calculate the strike price that would be traded from the current price plus or minus a number of points. the platform would also need to be able to know which calls or puts for a particular symbol i had in my account in order to sell them all when appropriate.
very well, i hope quantconnect lean could be used for these purposes, regards.
Douglas Stridsberg
Hey,
There's no way to directly communicate with the LEAN instance. Instead, you will have to indirectly communicate with it through a web call (using Download() ). Perhaps if your email alerts could be parsed and pasted into e.g. a text document uploaded to Dropbox or FTP, then LEAN could periodically download this file and see if there are any new orders to process.
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.
Marcos gonzález
mr, Stridsberg,
thanks a lot.
from your reply i understand that it should indeed be possible to use qc lean to trade options automated. these are very positive news for me.
now, i'm not a programmer so i have no experience whatsoever with the download() command or ftp processes. ¿do you think there would be any working examples anywhere that i could use as a guide of how i should try to put this system together?
regarding the text in the emails and the parsing, that should not be a problem. other ts users have advised me that i can use this script below to customize the email alerts the platform sends to read exactly what i want them to.
http://caspian.dotconf.net/menu/Software/SendEmail/
very well, thanks, regards.
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.
Douglas Stridsberg
Download() is very easy - it simply downloads a file from the URL you give it and saves it to a string. You can then call this function in a scheduled function to run e.g. once every minute, downloading the file and checking if it has any new trades to process.
Where you serve that file from is up to you - you can upload it to Dropbox or an FTP server (webserver).
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.
Marcos gonzález
regards to everyone again,
i have continued to investigate this matter and i have received some very valuable recommendations. several knowledgeable people have suggested that i discard the email exchanges and keep all processes local and it was also pointed out to me that the ts platform does indeed include a couple of mechanisms to export data.:
Print to File
Print(File(“c:\test.txt”), “Date “,Date:7:0,“ Last ”,Close);
File Append
FileAppend("c:\test1.txt", NumtoStr(Date,0) + Spaces(2) + NumtoStr(Close,2) + Newline);
file append looks to me like it could work really well for my purposes. i assume that qc lean must have a command to read text files from the local disk and i can schedule this function to run every 1 or 2 seconds, so that would take care of communicating my entry and exit signals to qc lean.
what i would still need a lof of help with is how i can get qc lean to go from reading a line that reads something like "twtr started an uptrend" to make all appropriate computations and send a twtr 190503c35 buy at ask limit order, and so on for every entry and exit signal.
here i include a much better description of my system. i have a number of charts in tradestation (one for each symbol i'm interested in trading), each of the charts generates an alert when one of four events takes place: an uptrend has started, uptrend has ended, a downtrend has started, downtrend has ended. tradestation is a severely defective platform which i urge everyone to stay away from (if the platform was minimally reliable and it was possible to automate options trading in tradestation i would be trading them there instead of trying to develop my own automation system), but at least these alerts work perfectly. i have been sending the alerts to myself by email for a number of weeks and placing some of the trades by hand and the alerts have worked without incident, unlike the rest of the platform which is a failure.
i think i could just append the same alerts i have been sending to myself by email and the format could maybe look like this:
Thu 3/21/2019 11:13 PM
TradeStation : Chart Analysis Alert for -symbol ticker- by -indicator- (inputs)
Info: Price crossing over average
Source: -indicator(inputs)
Occurred: 22-Mar-19 01:13:42
Price: 00.00
the text on the info line changes depending on the event that triggered the alert (uptrend started, uptrend ended, etc) and i can make it read whatever i want for each one of the four events that result in an alert being generated. using the append file command i could also write alerts with any text and format i wanted.
- for every - uptrend has started - alert, i would want qc lean to send the appropriate buy call order through ib's api.
this requires some elementary computations, first to determine which symbol (let's say twtr, if the alert was for twtr, for example) my system should buy a call for, then to determine the appropriate strike price (the price for the underlying symbol at the time of the alert, rounded to the closest multiple of 5 to which it should then add or substract a fixed number of points or strike intervals), the expiration date would normally be the closest one and then the limit price for the contract (buy at 8/10ths between the bid and the ask for this particular contract, or as close to midmarket as possible). i think at this time it would also be necessary to put something like a "tag" (owned twtr calls, for example) on all contracts i have purchased, or put them in a owned twtr calls "set" so that my system would know which contracts to sell when the uptrend has ended.
- for every - uptrend has ended - alert, send sell limit orders (maybe sell at the bid or as close to midmarket as possible) to liquidate all calls i might own for this particular symbol through ib's api.
- for every - downtrend has started - alert, send the appropriate buy put order through ib's api.
pretty much the same as in the case of uptrends, identify the relevant symbol, calculate the appropriate strike price and expiration date for the contract and send a limit order at 8/10ths between the bid and the ask. create some tag or set or collection of the contracts i have purchased so that the system will know which contracts it has purchased and the should liquidate when the downtrend has ended.
- for every - downtrend has ended - alert, send sell orders to liquidate all puts i might own for this particular symbol through ib's api.
this is the situation so far, having an automated system would allow me to trade significantly more symbols than the 1 to 4 i have learned i can do manually and with much superior reliability. i could also evaluate if i could run my strategies on lower timeframes that generate multiple trades a day and could be very promising, but i would need my system to check for alerts and execute all trades with perfect reliability every 2 seconds or less for this.
very well, i hope this can be accomplished using the qc lean platform, i will wait for replies or suggestions, thanks, regards.
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.
Douglas Stridsberg
The first part - reading from the file in question - I have already described to you. If you're running LEAN on your local system, it's even easier - there's plenty of resources online on how to read files in C#.
The second part - parsing the text in the file - is really up to you. I presume you have some control over the output from TradeStation, so rather than make it output things like "[xxx] has started an uptrend", why not make it output something like "[xxx], up"? My point here is that if you can get it to output in a standardised, comma-separated fashion, it'll be easier to read and parse into C#.
You can wrap this functionality in an event scheduled to run every minute - that way, you can come close to acting instantaneously on the alerts. If you truly want asynchronous polling of the file, you'll be limited to running LEAN locally but there are resources online on how to achieve that.
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!