Strategy - Buy/Sell during Regular hours only - Options

L

leakywaders

New member
HI to all!

Thanks in advance for the help! This website has been truly great and my apologies for not not contributing more. I try to give back what I have gotten from here but I'm just so busy with 2 jobs, and an 18 month old son, and my mother was recently diagnosed with cancer and is just about to start chemo. I just never have time to post as much as I'd like here but I do have some killer algorithms and strategies that work very well. I'll try to contribute more in the future and I've posted my strategy below in the 7th paragraph with an example from today in the next paragraph..

Today even though I'm not trading my system worked perfectly. I would have shorted SPY at the hourly 9 ema retest at 10:30ish at $293.72. I always have the hourly 9ema plotted on all my intraday charts and that is the backbone of my strategy. I achieve $1-3 dollars of net price movement per day in 1-5 trades. There is always a trade everyday with my strategy. So for example today SPY was trending above the hourly 9 ema premarket, it broke through its hourly 9 ema trend at 9:41 (no trade), it crossed back above its 9 ema at 10:00am (no trade), it broke again lower at 10:17 (no trade but sometimes I trade if it breaks the hourly and if it puts in a lower high relative to premarket), but then it retests the hourly 9 ema trend and rejected it at 10:30 for an immediate A+ pattern short - that is my bread and butter low risk trade. It is very close to a stop out point if if fails, has a high probability of succeeding, and high profit ratio.

My question is that I've been having problems building some think or swim strategies that only buy/sell during regular hours along with multiple time frame strategies. My backtesting strategies seem to break if I add a regular trading hours time filter. I have many indicators and custom scripts that work for regular trading hours that use things like:

def trading_day = getTime() >= RegularTradingStart(getYYYYMMDD()) and
getTime() <= RegularTradingEnd(getYYYYMMDD());
plot signal = if trading_day then xxxxxx;

But the above logic for some reason doesn't seem to work in my strategy builds nor selling EOD or buy BOD - really anything time based. I"m also having problems with backtesting multiple time frame strategies but I've worked around that by approximating moving averages of the multiple timeframes instead of using the close(getagg...) function. That also allows my indicator to work on mobile. However it is not the same as using the actual stair stepped higher timeframe moving averages but it's good enough for TOS for now. Also having afterhours turned on and aggregating during AH is important to my strategy.

Does anyone have a strategy that I can use as a template that buy/sells only during regular trading hours? I want to back test my custom algorithmic MTF option strategy but it needs to be limited to trade only during regular hours (when options trading is available) and also sell at EOD regardless of what my algo says. The net dollar P/L I am just going to convert into option strikes and delta to calculate true options P/L unless there is code that works with TOS strategies that automatically gets an option strike (get a $1 OTM option, 3 days <stike expiration<7 days) instead of the buying/seling SPY itself. But either way, I can back calculate the true P/L from the net dollar change.

My strategy is pretty straight forward. I place directional trades (buy to open calls and puts) with the hourly 9ema trend, up or down. and buy bounces, long or short, counting the bounces along the way. If the hourly 9 ema bounce count is greater than 2 then I buy directional bounces(long and short) at the hourly 9ema and sell it at the break of the 5 min 9 ema cross. If it breaks through the hourly 9 ema trend I have to wait for a retest of the hourly 9 ema. If it is below the hourly I will play every short bounce in the direction of the hourly trend but the bounce count has to be greater than 2 (break through hourly and a retest) and vice versa. I also have Trailing ATR filters, volatility filters, EMA crossovers filters, squeeze filters, and trend momentum filters but they just confirm my simple strategy. I have a custom histogram I built using this logic that gives buy and sell signals with high accuracy and good win/loss profit ratio. I don't trade with the daily trend as I capture more intraday movement trading the hourly trend which almost always exists and allows more trading opportunities. But I do trade in the direction of the hourly trend and buy only in that direction. It has worked well in the past and continues to work well through this chop in the market However I never hold overnight so I miss out on some massive SPY afterhour moves. I'm looking to change that and the first step is to backtest my current strategy with and without overnight holds and also backtest the same strategy by bumping up the time frames for overnight and swing hold periods(e.g instead of hourly, 15 and 5 min 9emas - change to weekly, daily, 4 hour 9 emas).


I am also looking to backtest a buy at close sell at open with some additional parameters similar to above to scalp gamma and volatility. So if anyone has a TOS strategy that a)only trades during regular hours but uses premarket data, b)uses multiple time frames and/or bonus c) uses a optionPrice(getstrike()) function I would greatly appreciate it! I can take that example and insert my strategy into it. If anyone wants to code this strategy since it's simple and I'm sharing it then please feel free to do it and share!


I have great success when trading in front of my desk intraday but am looking for longer term strategies that take less work or to algorithmically auto trade my current strategy. Honestly based on what I've coded, an algorithmic version of my strategy would do better as there are no emotions involved and it's not constrained by tiredness or me having to be hyper vigilant. That is how much I trust my signals and I know my coded version is not only in alignment but actually executes my strategy to it's fullest. Every time I step away to go take a leak, walk away from my desk, working my other job, or watching my son and I'll get a signal (or type this post haha). Or sometimes. even with my level of experience, emotions get the best of me and I don't trade signals that are valid and also end up selling too early. The human side of my trading is my biggest weakness - something that I am always striving to improve.

Also In general despite my alog and strategy being solid, unfortunately TOS is not the best for this due to the recursion and MTF limitations and no real auto buying that I would trust. I'm working on building a fully automated quant system in the future, as I've reached my the limitations of TOS, but I am trying to get above the $100K threshold first before I spend time building my algo. Even MTF text alerts don't work correctly and are delayed by minutes so I'm kind of stuck at my desk trading doing a poorer job than my algo would even with being at my desk hehe. I've spend many hours customizing TOS but I've hit it's limits I think. If I knew about these TOS limitations I would have spent those hundreds of hours coding on something that didn't have these limitations.

No trading for me today! Going to have a nice 4 day holiday week but looking to do some backtest during over the weekend. Got to run!

Here is a picture of the simple strategy in action. Just a simple hourly trend following system - purple dashed line is the hourly 9 ema. Entry is shown. The green dashed line is the daily 50Ema. Covering would have been at the break of the 5 min 9 ema. Since its so far below the hourly I would play a counter trend bounce back up to the 15 min 9 ema target, then hourly 9 ema target (if the risk reward was there) and then the following rejection back down short or then wait for a count of 2 if it crosses back up above the hourly. The counting of bounces and breakthroughs of the MTF 9 EMA's helps with making those decisions with my algo. If was watching it I would have shorted earlier but the system is simple reliable and if it executes automatically good enough for me:


Thanks!
Dan
 
L

leakywaders

New member
Here are additional examples. In reality I have other strategies and other criteria but these are trades that the hourly 9 ema strategy provide on its own. This is my main strategy - everything else is built upon this and just involves trade confirmation, risk management, exits, and sometimes other indicators will me to get in earlier than the 9 ema strategies (like a second lower pivot high at open will get me in even if it's above 9 ema , or rejection of premaket resistance) or keep me in longer than just crossing the 5min 9 ema.

Hope this helps people and kindly let me know if you have a similar prebuilt TOS strategy script the involves regular trading hours, options, and MTF or would like to code this very simple yet effective strategy.


Thanks!!!
 
BenTen

BenTen

Administrative
Staff
VIP
Hey, welcome. Sounds like you already have an indicator coded for your strategy, would you mind sharing that so we can contribute to it wherever possible? That way nobody has to write everything from the ground up. Thank you for the detailed explanation by the way.
 
3AMBH

3AMBH

Member
2019 Donor
VIP
Thanks for the post, Leaky.

Is there an indicator script that will place an hourly MA on a lower time frame chart? Thanks
 
R

RandyR

New member
Hi,

Sorry to hear about your mom.

I think it would help if you posted your code (or code share link) as BenTen said, even if it doesn't work exactly as you expect.

I read your detailed description, but still not 100% sure of the strategy. You said you have a histogram that gives buy and sell signals with high accuracy and good win/loss profit ratio. I don't see that in the images you posted.

Please post your code and I'd be happy to help.
 
markos

markos

Well-known member
VIP
@leakywaders thank you for posting such a detailed example of how you trade. This is the spirit that is appreciated! Pardon the question, but what type of coding do you need, specifically? Thanks, Markos
 
L

leakywaders

New member
Hi! I

Thanks !!! I thought all weekend, talked to my wife, and I decided I’m I’m going to pass on the coding help. I would like an example strategy that involves options and only buying selling during regular hours and multi timeframe aggregation. I initially posted just to se if anything exists of its even possible.

I was trying to build a strategy on what I already do and something I already coded as an indicator. But I get stuck with the aggregation and recursion aspect of tos strategy and alerts that isn’t a problem with my indicator. I think the only way around this - if it’s even possible at all - would be to share the whole algorithm. I tried to strip it down but then it works as a strategy - it’s all the bells and whistles that make it not function.

I wanted to share the general strategy and try to make it an actual “TOS strategy” but I’m just going to code it in another language when I get around to it. It’s simple enough that it won’t give me problems and I want my effort spent on something that’s going to work.

So I was trying to request a strategy already created that deals with multi time frame aggregation , options, and time constraints (like sell at EOD ) that I can use to mimic my code. But I’m just going to stick with what I got until I switch to a new platform

It’s basically a follow and wait for bounces off the hourly trend strategy. It’s easy to see, relatively easy to code but it took a lot of time and thought to differentiate between the two cases , a) breakthrough of the hourly ema or bounce off of It. It involves counting , storage of pivots and the aggrated EMA themselves. On the 5 minute chart it’s similar to the 100 ema - (hint as it helps with mobile and puts everything at one aggregation point) using the 10 ema ,50 , 100 , and 200 is close enough to get it into one time fram me and bypass the aggreagatioj but then I have problem with recursion and it’s just not as effective.

So most people buy when price moves up or on an ema crossover if they use mead - think slim ribbon - but I do basically the opposite. When most ema strategies say to “buy” I’m looking to short the longer timeframe ema bounce and vice versa. It’s the time it looks the worst and most ema strategies say to buy that my signals are given -e.g a short at the top of a short time frame uptrend or going long when price it plummeting but within the bounce of a higher timeframe trends. I’m only interested in buying selling when price hits a higher timeframe 9 ema. Examples were given and I think they would be of benefi alone to everyone. But it’s is a combination of price action, pivots, and using the hourly ema as a moving resistance point. The buy logic is 2 lines of code and my indicator is probably less than 100 lines of code including variables. It’s pretty simple.

As a further example I fully expected the drop in spy this morning and made $1k playing the hourly rejection. There were other factors involved in the short that stacked the odds in my favor this morning but simply the rejection at the hourly was all that was needed and is the backbone of the strategy. It seems to work so well, and it’s relatively simple that I’m hesitant to share it. I hope that makes sense. Here is proof that I’m not full of crap. And I just missed another rejection typing this but further proof the strategy works. And my apologies for not sharing - except for the basic logic. Follow the hourly 9ema and play bounces off it it , that’s it:)

 
L

leakywaders

New member
Thanks for the post, Leaky.

Is there an indicator script that will place an hourly MA on a lower time frame chart? Thanks
Hi Sorry!

Here is the one I created. MTF EMA's all plotted on the chart. You can change the script, unplot what you don't want etc. Note - you can change the length of the ema in the inputs or hide what you don't need:) You can delete everything but the hourly if you like and save it as a new script.

https://tos.mx/cdY7rE
And here is one with retest arrows and the ability to show hide arrows for the day only. This has to be used on the 1 minute chart I believe as I I didn't test and compare the agg plots. I created this one months ago when I first started coding this stuff. Very helpful - though I don't use this anymore.
https://tos.mx/Ij5n7p
 
BenTen

BenTen

Administrative
Staff
VIP
@leakywaders Thank you for writing in such details. It looks like you want to receive help but aren’t fully open to the idea of sharing your indicator. That makes it harder for us to help you. I would suggest getting help from a professional service so that they can help you and still have your code protected at the same time.

Unless someone else on here understand what you really want and could contribute some code.
 
L

leakywaders

New member
Thanks Ben for understanding!

Yeah I jumped the gun asking for help last week. My apologies. I realized after the fact that it wouldn’t be possible to really help without the code and I don’t even think it would be of much benefit anyway unless it brought me closer to automation or at the very least text alerts. I’ve spent weeks trying to turn my code into a TOS strategy (which it already basically is) and dumbing it down to get accurate text alerts in TOS. And I’m really good now at coding in thinkscript. I just don’t think it’s possible - and definitely not answerable by you guys without the code. So my thread is kind of pointless. My apologies.

So many thanks and kindly disregard this request! I’m going to spend future coding efforts migrating things over to python or a programming language that can be directly plugged into an API and function as a stand alone algo. Until then I’ll just trade manually in TOS as normal!

Thanks!
Dan
 

Similar threads

Top