Repaints The PAM High Low Chart Setup For ThinkOrSwim

Repaints
Status
Not open for further replies.

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I have read this whole thread and am so impressed with the cooperation and communication, this is just inspiring.

I have the Squeeze Pro as well as the EarlyInNOut candles from ST, and I will say the 5m works best for me, the 1m with your indicator @OGOptionSlayer is too noisy. And I see what you mentioned a while ago about how your indicator will alert before the squeeze does, but I need everything to work together for confidence.

There was just a beautiful 5m AAPL buy call that alerted at 10am PST which had a red squeeze with it and saw the 0DTE calls go +250%

I did have a question about OnDemand market replay, maybe it was on my end, but has anyone else gotten this indicator to load properly and work in OnDemand replay?
 
Last edited:
This is a modification of an earlier post here on usethinkscript modified to show only Buy/Sell Bubbles. I don't like a lot of clouds as it interferes with my ORB's. Here is the modified code which is to my liking and helpful to my trading (I use it on a 1 min and 5 min chart for entries/exits):

# High_Low_range_carter_00e

#https://usethinkscript.com/threads/looking-to-setup-a-high-low-range.13750/
#Looking to Setup A High-Low Range
#OGOptionSlayer 12/19
#Modified by C. Ricks 1/10/23 to show only Buy/Sell Bubbles



input show_stop = no;
input buffer = 10;
input show_min = yes;
input show_five_min = yes;
input show_15min = yes;
input show_30min = yes;
input show_hour = yes;

def bn = BarNumber();
def na = Double.NaN;

input buy_bubbles_on = yes;

input buy_type = { default completed_bar , active_bar };
def buyoff;
switch (buy_type) {
case completed_bar:
buyoff = 1;
case active_bar:
buyoff = 0;
}

input bars = 20;
def period = (!IsNaN(close) and IsNaN(close[-bars]));


# define group of x bars
def first = (!IsNaN(close[-(bars - 1)]) and IsNaN(close[-bars]));


# price level of the highest high
def hihi = if bn == 1 or IsNaN(close) then 0
# else if first then Highest(high[-(bars - 1)], (bars - 1))
else if first then Highest(high[-(bars - 1)], (bars - 0))
else hihi[1];

# find bn of just the first occurance of hihi
def hihifirstbn =
if hihi == 0 then 0
else if hihifirstbn[1] > 0 then hihifirstbn[1]
else if (hihi == high) then bn
else hihifirstbn[1];

# bars after the hihi
def hi_bars = (hihifirstbn > 0 and bn >= hihifirstbn);

# hihi price level from 1st highest bar
def hihi_level = if bn == 1 or IsNaN(close) then na
# else if hihifirstbn > 0 and bn >= hihifirstbn then hihi
else if hi_bars then hihi
else na;

# true on the hihi bar
def ishi = if bn == 1 then 0
else if hihifirstbn == bn then 1
else 0;

# find lowest low
# price level of the lowest low
def lolo = if bn == 1 or IsNaN(close) then 0
# else if first then lowest(low[-(bars - 1)], (bars - 1))
else if first then Lowest(low[-(bars - 1)], (bars - 0))
else lolo[1];

# find bn of the first occurance of lolo
def lolofirstbn =
if lolo == 0 then 0
else if lolofirstbn[1] > 0 then lolofirstbn[1]
else if (lolo == low) then bn
else lolofirstbn[1];

# bars on and after the lolo
def lo_bars = (lolofirstbn > 0 and bn >= lolofirstbn);

# lolo price level from 1st lowest bar
def lolo_level = if bn == 1 or IsNaN(close) then na
# else if lolofirstbn > 0 and bn >= lolofirstbn then lolo
else if lo_bars then lolo
else na;

# true on the lolo bar
def islo = if bn == 1 then 0
else if lolofirstbn == bn then 1
else 0;



input hilo_arrows = no;

# buy put
def put_buy_hilo = if bn == 1 or IsNaN(close) then 0 else if ishi then low else put_buy_hilo[1];

# bp = buyput
def bp1 = if period and (!first) then (close[buyoff] crosses below put_buy_hilo) else 0;
def bp2 =
if bn == 1 then 0
else if bp2[1] then bp2[1]
else if bp1 then 1
else bp2[1];
def bp3 = if !bp2[1] and bp2 then 1 else 0;

# buy call
def call_buy_lohi = if bn == 1 or IsNaN(close) then 0 else if islo then high else call_buy_lohi[1];


def bc1 = if period and !first then (close[buyoff] crosses above call_buy_lohi) else 0;
def bc2 =
if bn == 1 then 0
else if bc2[1] then bc2[1]
else if bc1 then 1
else bc2[1];
def bc3 = if !bc2[1] and bc2 then 1 else 0;

input gain_stop_percent = 20;

def offx = 2;
def ref_bubble_x = (!IsNaN(close[offx]) and IsNaN(close[(offx - 1)]));

# puts
def putreflevel = put_buy_hilo - (put_buy_hilo * (gain_stop_percent / 100));


# calls
def callreflevel = call_buy_lohi + (call_buy_lohi * (gain_stop_percent / 100));

def h = hihi;
def l = lolo;
def range = h - l;

input show_labels = yes;
input show1HOUR = yes;
input avg_type = AverageType.Exponential;
input fastlen = 10;
input slowlen = 50;
input htf_lookback = 2;
input src = close;

def currentTimeFrame = GetAggregationPeriod();

## One Hour
def aH1 = if currentTimeFrame <= AggregationPeriod.HOUR then AggregationPeriod.HOUR else currentTimeFrame;
def availableH1 = currentTimeFrame <= AggregationPeriod.HOUR;
def fast1hr = MovingAverage(avg_type, close(period = aH1), fastlen);
def slow1hr = MovingAverage(avg_type, close(period = aH1), slowlen);

def crossup = fast1hr crosses above slow1hr;
def crossdn = fast1hr crosses below slow1hr;

## Signals
input show_arrows = yes;

AddChartBubble(buy_bubbles_on and bc3 and Sum(bp3, buffer) == 0, low * 0.9995, "Buy Call", if Sum(crossup, htf_lookback) > 0 then Color.GREEN else Color.GREEN, no);
AddChartBubble(buy_bubbles_on and bp3 and Sum(bc3, buffer) == 0, high * 1.0005, "Buy Put", if Sum(crossdn, htf_lookback) > 0 then Color.RED else Color.RED, yes);
 
I have read this whole thread and am so impressed with the cooperation and communication, this is just inspiring.

I have the Squeeze Pro as well as the EarlyInNOut candles from ST, and I will say the 5m works best for me, the 1m with your indicator @OGOptionSlayer is too noisy. And I see what you mentioned a while ago about how your indicator will alert before the squeeze does, but I need everything to work together for confidence.

There was just a beautiful 5m AAPL buy call that alerted at 10am PST which had a red squeeze with it and saw the 0DTE calls go +250%

I did have a question about OnDemand market replay, maybe it was on my end, but has anyone else gotten this indicator to load properly and work in OnDemand replay?
Hi @DanielModel3, that is what this community is all about. We learn together and everyone wants the other to be successful. It's one of the best trading communities I've been involved in and it's moderated better than any community I've been in.

I agree, if you are trying to use this on 1m, it will not be useful to most traders. The lowest timeframe I like to use it on currently is the 3m but 5m is very good as it gives it a little more time to get confluence.

Also, remember the point of Squeeze Pro or TTM Squeeze per Mastering the Trade is to be in the squeeze before it fires. That's why I love this indicator coupled with it because it does give you ample opportunity to get in the squeeze prior to it firing.

I also like how it forms those S/R levels that are active throughout the day and not really true S/R long-term levels, but ones being established, where the bears and bulls are agreeing to price.
 
FWIW, I back tested various timeframes and instruments (all were futures) across 10 years of data. If you back test, I will be curious if you find, as I did, that the indicator needs to be optimized to each instrument and timeframe to be profitable. My testing was done without filters such as the squeeze in order to evaluate entry based strictly on price action.

For me, the very best aspect of this indicator is the dynamically-adjusting levels of S/R that can be calculated from a higher timeframe and plotted on the lower. Like you, I prefer the 15 min timeframe but my tests showed that 5 min or 15 min didn't matter much except in determining the size of the range to consider. What surprised me was how much better confluence with the 30 min timeframe performed vs confluence with the hourly timeframe. I didn't expect that.

Anyhow, that's what I found testing this thing on futures. What you're looking for trading options may be different. I remain grateful that you shared your strategy because the constantly-updating S/R from the 30 min timeframe is immensely helpful in my trading. THANK YOU!

Best wishes and happy trading.
You now have me sold on the 30m, to be honest.

Also, I didn't comment on your optimization comment on the different markets. It definitely makes sense. I stick to the same markets so the ones I trade in, I pretty much had in mind prior to getting the indicator created. I find 20 bars are optimal for shorter time frames in my markets and 10 bars are optimal for 1hr and higher just because the indicator really doesn't care about past historical prices except most recent (in trading days, usually one but max two).

On a weekly, I will set it to 5 if I'm looking for a squeeze that is setting up and getting ready to fire. I rarely use it on swing plays and care more about my EMA's and SMA's with those but I'm a day trader by heart and it's what I get the most profitability from.

So for me, I've found that customizing it to the time frame you are in is highly important but since I trade in the same markets daily, I don't really have much parody as they are all pretty well correlated to one another also.
 
You now have me sold on the 30m, to be honest.

Also, I didn't comment on your optimization comment on the different markets. It definitely makes sense. I stick to the same markets so the ones I trade in, I pretty much had in mind prior to getting the indicator created. I find 20 bars are optimal for shorter time frames in my markets and 10 bars are optimal for 1hr and higher just because the indicator really doesn't care about past historical prices except most recent (in trading days, usually one but max two).

On a weekly, I will set it to 5 if I'm looking for a squeeze that is setting up and getting ready to fire. I rarely use it on swing plays and care more about my EMA's and SMA's with those but I'm a day trader by heart and it's what I get the most profitability from.

So for me, I've found that customizing it to the time frame you are in is highly important but since I trade in the same markets daily, I don't really have much parody as they are all pretty well correlated to one another also.
Quick question in settings for "buy type". Just curious the big difference between "Completed" and "Active" bar selections. Any benefit to one over the other? Thanks again.
 
FWIW, I back tested various timeframes and instruments (all were futures) across 10 years of data. If you back test, I will be curious if you find, as I did, that the indicator needs to be optimized to each instrument and timeframe to be profitable. My testing was done without filters such as the squeeze in order to evaluate entry based strictly on price action.

For me, the very best aspect of this indicator is the dynamically-adjusting levels of S/R that can be calculated from a higher timeframe and plotted on the lower. Like you, I prefer the 15 min timeframe but my tests showed that 5 min or 15 min didn't matter much except in determining the size of the range to consider. What surprised me was how much better confluence with the 30 min timeframe performed vs confluence with the hourly timeframe. I didn't expect that.

Anyhow, that's what I found testing this thing on futures. What you're looking for trading options may be different. I remain grateful that you shared your strategy because the constantly-updating S/R from the 30 min timeframe is immensely helpful in my trading. THANK YOU!

Best wishes and happy trading.
How did you backtest? Is it possible to share the code? Thanks
 
You now have me sold on the 30m, to be honest.

Please remember that I am NOT a fan of JC's Squeeze Pro (yes, I have it, don't use it). I am using a different filter to confirm my reading of the price action, therefore the 30 min may not work for you. We're trading different types of instruments too, so my preferred settings may not be so hot for you ... don't want anyone to lose money because of settings I prefer on the narrow range of instruments that I trade. My point is that good S/R levels seemed to come from making adjustments for each instrument.

@tradelex20, I didn't use TOS, so nothing to share, sorry.


Best wishes and happy trading!
 
Last edited:
Quick question in settings for "buy type". Just curious the big difference between "Completed" and "Active" bar selections. Any benefit to one over the other? Thanks again.
Completed bar will give a signal once the candle actually closes. Active bar will give a buy signal when the candle just crosses the trigger line. I always say to avoid fakeouts, and the original strategy calls for, the candle to be completed. But sometimes depending on other areas of confluence (SMA's cross, volume, 13/48 ema cross, symmetry, etc.), I will go ahead and take a position before the candle closes.
 
Please remember that I am NOT a fan of JC's Squeeze Pro (yes, I have it, don't use it). I am using a different filter to confirm my reading of the price action, therefore the 30 min may not work for you. We're trading different types of instruments too, so my preferred settings may not be so hot for you ... don't want anyone to lose money because of settings I prefer on the narrow range of instruments that I trade. My point is that good S/R levels seemed to come from making adjustments for each instrument.

@tradelex20, I didn't use TOS, so nothing to share, sorry.


Best wishes and happy trading!
I always do my own confirmations. I was just looking at it today and it's very clean like you said. I liked it a lot. I will keep looking and having a chart open with it to just check it out but I don't see any harm in using it. I think all higher timeframes are simple using the indicator, to be honest. Not many fakeouts and trends last much longer.

Thanks for backtesting. I really liked that someone did it.
 
So I use a very specific setup. It's kind of a mashup between what John Carter teaches with one of his in Mastering the Trade and TradingWarz Golden Indicator. I've used it for about 2 years now and it's extremely profitable. Honestly, I haven't backtested it but I would love to but I'm just not as technical as most in here. I know it brings me immense profit and on Friday, my port grew 11% using it. It's not a small port either. It's a reversal setup and it's solid with tight stop losses. I use it with a Darvas Box but TOS has a great Darvas Box study.

I'm looking to see if someone can create an indicator for it. To keep this post as short as possible, here is the setup:

1) Only using the last 20 candles on any timeframe.
2) Find the high and low of last 20 candles. As a new candle is created, it disregards anything not in the 20 candles.
3) On the high candle, place a "Priceline" that is the low of that candle (wicks included).
4) Once a candle closes a LL below that "Priceline", place a bubble called "Buy Puts" on that candle. It has to close below the low of the highest candle. It would be great if the candle could be painted a custom color. I use black in keeping with John Carter's concept.
5) A stop loss "Priceline" is drawn on the "High" of the highest candle. This is a great stop loss and keeps risk at a low with confirmation that the trend is not reversing but also keeps you from getting shaken out by MM's.
6) On the low candle, place a "Priceline" that is the high of that candle (wicks included).
7) Once a candle closes a HH above that "Priceline", place a bubble called "Buy Calls" on that candle. It has to close above the high of the lowest candle. It would be great to have this candle also painted a customer color. Again, default should be black.
8) A stop loss "Priceline" is drawn on the "Low" of the lowest candle. Again, another great stop loss to keep your risk at a minimum but also confirms that the trend reversal is not manifesting.

I use this with a Darvas box because I will take my option contracts where the Darvas Box low or high is respectfully. This setup works like a champ when I use it manually but I'm trying to share it with people that I trade with so they don't have to depend on me for their signals. I don't charge for signals nor do I have a discord. I just have a group of traders that I've traded with a long time that see how my port grows and theirs doesn't. I've tried to share this concept with them but many still don't get it and this would be great to share and I would love for you guys to use it too. It's a solid setup and it works very well.

Any help would be greatly appreciated!

Also, I would like the indicator to have a trailing stop loss. I forgot to include this important point.

Once it has moved 50% from current entry, I would like it to put a stop loss at the HH of the last two candles for puts and the LL of the last two candles for calls. This locks in profits to ensure you don't get greedy and lose your gains when the market starts to shift. I do take profits on important pivots like PMH and PML and this morning, it made me $3 on each share.
It's easy to trade 0dte's with this setup as well.
Hi @OGOptionSlayer - Great indicator and strategy and thanks to @halcyonguy for coding it.

Since the indicator repaints, how are you back testing it? We will never see the fake-out signals printed by the study - Is there something I am missing?

I wonder if we can add a “Day” filter so that all the lines are shown for each individual day and the count starts fresh on the next day.

Thanks again for sharing your indicator and strategy with us. Happy Trading!
 
Hi @OGOptionSlayer - Great indicator and strategy and thanks to @halcyonguy for coding it.

Since the indicator repaints, how are you back testing it? We will never see the fake-out signals printed by the study - Is there something I am missing?

I wonder if we can add a “Day” filter so that all the lines are shown for each individual day and the count starts fresh on the next day.

Thanks again for sharing your indicator and strategy with us. Happy Trading!
I don't do backtests. I honestly don't know how. I just use the indicator daily and know its effectiveness. @Trader Raider backtested it and found the most confluence on the 30m timeframe when I've always used it on the 1hr. He also stated that the 5m works well but the 1m causes too much noise. I would love for someone to figure out how to backtest this on TOS. If @Chemmy has to modify the code to make this possible, I'm sure he can.

Since @halcyonguy initially did the first few updates, @Chemmy has been doing the main updates since and it has really grown into a wonderful tool, especially when combined with areas of confluence. I believe you need this to ensure you aren't getting a false signal but wouldn't know how to code this into an effective backtesting strategy. Although I'm in IT, I'm not a developer and will never claim credit for the actual coding that went into this. It was all @halcyonguy and @Chemmy and they brought my concept to life. For that, I'm eternally grateful and consider them more important than myself in this endeavor. Now hopefully we can get a backtesting expert to perform that so we have a basis for what we can expect on the profit ratio.

You can limit the number of bars counted before it generates a signal with the Buffer. I think this could be utilized with the 'Day' suggestion as long as you start it when market opens and set it to 24 and the timeframe is 1hr? This would also be effective for other timeframes as well just dividing the day by those timeframes and set that to your buffer.
 
Reduce buffer and we get overlapping cloud due to current high of your buffer has not been broken....I would wait for hourly candle to cross above previous hourly for confirmation...this tend to reduce alot false bullish breakout..and you can price action with your fav pattern at that point..for me hl hl ..let me know what you think og?
 
Since the indicator repaints, how are you back testing it? We will never see the fake-out signals printed by the study - Is there something I am missing?

Hopefully this image of a 5 min chart shows how I back tested. A magenta signal candle forms when the rules posted by the OP for a short entry are met. Once the signal candle closes, it doesn't repaint. During the 5 minutes it is forming, it certainly can repaint, which is why I tested based on the closure of the signal candle. For testing purposes, a successful trade was defined as meeting a specific dollar amount profit target. A failed trade was stopped out for a specific dollar amount loss.

On this chart, you can see numerous magenta short signal candles. None were successful signals according to rules of the back test. Maybe they meet your definition for "fake-out signals?"

The good news is that trading in confluence with the 30 min chart would have prevented you from taking those short signals. On this chart, the 30 min levels (the low of the HH and high of the LL on the 30 min chart) are plotted in dotted lines. Only the first magenta signal candle on the 5 min chart had any follow through below the 30 min level. And that follow through was rather weak.

This chart shows why I find the 30 min levels so helpful. Sometimes the lower timeframe signals work out great. But as this chart shows, often they don't, which is why they need to be assessed through the lens of a filter (OP likes the squeeze) or higher time frame levels such as the 30 min shown here.

Short term options contracts might make some profit with slight downward price movement as seen on this chart, but for me as a futures trader, the money is in the price action related to the 30 min levels more than the signals per se. On this chart, there was no real follow through below the 30 min levels that would justify entering a short position based on the 5 min signals.

None of this is intended to be critical of the OP. The dynamic S/R created by the strategy playing out on a higher timeframe is extremely valuable!

 
just came across this indicator looks great, the question is there a way we can see past alerts or signals it has given on the 15min timeframe I loaded the script and only shows current signal. So I can’t go back and see how many signals it has given in that past to study the best results. Thanks in advance
 
just came across this indicator looks great, the question is there a way we can see past alerts or signals it has given on the 15min timeframe I loaded the script and only shows current signal. So I can’t go back and see how many signals it has given in that past to study the best results. Thanks in advance
It repaints. Therefore, it is not possible to see what the actual signals were.
 
So on the large bars, you want to modify your strategy slightly. The large bar is an outside bar (OB) and it's a good thing but you have to understand what it means. It means that the bulls/bears have not made up their mind yet. I look to see where the large bar closes. The next bar is going to be an inside bar (IB) obviously.

For this setup, I look to the next bar after the IB and wait for it to either make a HH or LL. That's the direction that's been decided. If you are in puts and it starts heading toward your stop loss, then you obviously don't want to take that play. But if you are in puts and price action starts going lower, wait until it closes below the IB and take your entry. The new HH or LL (whether it's calls or puts respectively) is the support/resistance of the short-term trend.
Your stop loss will be the opposite (either the high or the low of that bar of the opposite play you took). Eventually, we will make this indicator do this setup but these plays are extremely strong because the market has decided its direction.

So TLDR, strategy for this type of situation is:
1. OB (engulfs previous candle or candles), don't take play, have patience.
2. Next bar is an IB. Still practice patience and wait for the close. The next candle could still be an IB of the previous IB if you are squeezing. Still very good because the market is building up energy that it is going to release.
3. When the next candle closes above or below one of the IB's after an OB, you take that direction and put your stop loss at the opposite end of the candle.

I hope this helps. I will elaborate soon with better examples but this is one of my favorite setups. Also, combined with fib levels, if the tend is reversing, look to take profits at your Fib levels of 38.6% and higher. I scale out and leave runners almost every time on this trend because the runners can just keep running.
The entries are objective though depending on your trading style. I do not take every signal which is what a backtest would do. I would love to properly backtest this on the 15m as I think that is the most clean timeframe to trade these in. The hourly to get the signal but trading in the 15m or sometimes I just trade in 15m all day because it is literally very clean most of the time as long as the market is not just chopping everywhere.
Maybe @Chemmy can help with the backtesting of this. I would be interested to see the results.
Since the indicator repaint. Do you have
The entries are objective though depending on your trading style. I do not take every signal which is what a backtest would do. I would love to properly backtest this on the 15m as I think that is the most clean timeframe to trade these in. The hourly to get the signal but trading in the 15m or sometimes I just trade in 15m all day because it is literally very clean most of the time as long as the market is not just chopping everywhere.
Maybe @Chemmy can help with the backtesting of this. I would be interested to see the results.
since it is a repainting indicator, do you wait for the opposite signal to fire before you take a trade?
 
Pretty cool indicator here, I like it a lot honestly -- I've tried it a few time for pullbacks within a large trend and it works great. One of the things I dislike in indicators is mixed signals though, so I made my own edit on the code. My version suppresses signals of the opposite direction when a signal has already been fired within a "buffer" lookback period, i.e. if a put signal has fired then no call signals will fire within that timeframe.

I also added the option for clouds, which will disappear once the opposite signal has fired(good for exits if you haven't taken them already, shown below) and also added arrows as signals instead of labels by selecting "no" for the buy bubbles option:

Dg1y1HV.png


I can also look at adding fibs on the high-low range as well if Halcyon doesn't get it to it first. Here's the study link: http://tos.mx/2YOjikZ

edit on this: I added a quick fib retracement fix to set on the high-low range. Nothing crazy, just set colors for the low, high, and 50% retracement:
5Tpvyen.png


If that makes sense, y'all are welcome to use the fib portion of the code how you will: http://tos.mx/nCu3vBj
Ruby:
# High_Low_range_carter_00e
# Version 1.5 added fibs and clouds @Chemmy 12/29/22
#https://usethinkscript.com/threads/looking-to-setup-a-high-low-range.13750/
#Looking to Setup A High-Low Range
#OGOptionSlayer  12/19
#So I use a very specific setup. It's kind of a mashup between what John Carter teaches with one of his in Mastering the Trade and TradingWarz Golden Indicator. I've used it for about 2 years now and it's extremely profitable. Honestly, I haven't backtested it but I would love to but I'm just not as technical as most in here. I know it brings me immense profit and on Friday, my port grew 11% using it. It's not a small port either. It's a reversal setup and it's solid with tight stop losses. I use it with a Darvas Box but TOS has a great Darvas Box study.

#I'm looking to see if someone can create an indicator for it. To keep this post as short as possible, here is the setup:

#1) Only using the last 20 candles on any timeframe.
#2) Find the high and low of last 20 candles. As a new candle is created, it disregards anything not in the 20 candles.
#3) On the high candle, place a "Priceline" that is the low of that candle (wicks included).
#4) Once a candle closes a LL below that "Priceline", place a bubble called "Buy Puts" on that candle. It has to close below the low of the highest candle. It would be great if the candle could be painted a custom color. I use black in keeping with John Carter's concept.
#5) A stop loss "Priceline" is drawn on the "High" of the highest candle. This is a great stop loss and keeps risk at a low with confirmation that the trend is not reversing but also keeps you from getting shaken out by MM's.
#6) On the low candle, place a "Priceline" that is the high of that candle (wicks included).
#7) Once a candle closes a HH above that "Priceline", place a bubble called "Buy Calls" on that candle. It has to close above the high of the lowest candle. It would be great to have this candle also painted a customer color. Again, default should be black.
#8) A stop loss "Priceline" is drawn on the "Low" of the lowest candle. Again, another great stop loss to keep your risk at a minimum but also confirms that the trend reversal is not manifesting.


# 9  Also, I would like the indicator to have a trailing stop loss. I forgot to include this important point.

# 10  Once it has moved 50% from current entry,
#   for puts, put a stop loss at the HH of the last two candles
#   for calls, put a stop loss at the LL of the last two candles
#     to lock in profits


#=======================================

input add_cloud = yes;
input show_stop = no;
input buffer = 10;

def bn = BarNumber();
def na = Double.NaN;

input buy_bubbles_on = yes;

input buy_type = { default completed_bar , active_bar };
def buyoff;
switch (buy_type) {
case completed_bar:
    buyoff = 1;
case active_bar:
    buyoff = 0;
}
# used in #4  buy puts , #7 calls


#---------------------------
# choose_wick_body01
#input plot_type = {default SMA, "Red EMA", "Green EMA", WMA};
input candle_levels = {default "wick" , "body" };
def highx;
def lowx;
switch (candle_levels) {
case "wick":
    highx = high;
    lowx = low;
case "body":
    highx = Max( open, close);
    lowx = Min( open, close);
}



#1) Only using the last 20 candles on any timeframe.
input bars = 20;
def period = (!IsNaN(close) and IsNaN(close[-bars]));
#addverticalline(x,"-");



#2) Find the high and low of last 20 candles. As a new candle is created, it disregards anything not in the 20 candles.

# define group of x bars
def first = (!IsNaN(close[-(bars - 1)]) and IsNaN(close[-bars]));
AddVerticalLine(first, "-", Color.WHITE);

#----------------------------

# price level of the highest high
def hihi = if bn == 1 or isnan(close) then 0
#  else if first then Highest(high[-(bars - 1)], (bars - 1))
  else if first then Highest(high[-(bars - 1)], (bars - 0))
  else hihi[1];

# find bn of just the first occurance of hihi
def hihifirstbn =
  if hihi == 0 then 0
  else if hihifirstbn[1] > 0 then hihifirstbn[1]
  else if (hihi == high) then bn
  else hihifirstbn[1];

# bars after the hihi
def hi_bars = (hihifirstbn > 0 and bn >= hihifirstbn);

# hihi price level from 1st highest bar
def hihi_level = if bn == 1 or isnan(close) then na
#  else if hihifirstbn > 0 and bn >= hihifirstbn then hihi
  else if hi_bars then hihi
  else na;

# true on the hihi bar
def ishi = if bn == 1 then 0
  else if hihifirstbn == bn then 1
  else 0;


addchartbubble(0, low,
bn + "\n" +
hihifirstbn
, color.yellow, no);

#-------------------------------------

# find lowest low
# price level of the lowest low
def lolo = if bn == 1 or isnan(close) then 0
#  else if first then lowest(low[-(bars - 1)], (bars - 1))
  else if first then lowest(low[-(bars - 1)], (bars - 0))
  else lolo[1];

# find bn of the first occurance of lolo
def lolofirstbn =
  if lolo == 0 then 0
  else if lolofirstbn[1] > 0 then lolofirstbn[1]
  else if (lolo == low) then bn
  else lolofirstbn[1];

# bars on and after the lolo
def lo_bars = (lolofirstbn > 0 and bn >= lolofirstbn);

# lolo price level from 1st lowest bar
def lolo_level = if bn == 1 or isnan(close) then na
#  else if lolofirstbn > 0 and bn >= lolofirstbn then lolo
  else if lo_bars then lolo
  else na;

# true on the lolo bar
def islo = if bn == 1 then 0
  else if lolofirstbn == bn then 1
  else 0;



input hilo_arrows = no;

plot z1 = if hilo_arrows and ishi then high else na;
z1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
z1.SetDefaultColor(Color.CYAN);
z1.SetLineWeight(3);
z1.HideBubble();

plot z2 = if hilo_arrows and islo then low else na;
z2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z2.SetDefaultColor(Color.CYAN);
z2.SetLineWeight(3);
z2.HideBubble();


#3) On the high candle, place a "Priceline" that is the low of that candle (wicks included).

# buy put
def put_buy_hilo = if bn == 1 or isnan(close) then 0 else if ishi then low else put_buy_hilo[1];
plot z3 = if put_buy_hilo > 0 then put_buy_hilo else na;
z3.SetDefaultColor(Color.RED);


#4) Once a candle closes a LL below that "Priceline", place a bubble called "Buy Puts" on that candle. It has to close below the low of the highest candle. It would be great if the candle could be painted a custom color. I use black in keeping with John Carter's concept.

# bp = buyput
def bp1 = if period and !first then (close[buyoff] crosses below put_buy_hilo) else 0;
def bp2 =
  if bn == 1 then 0
  else if bp2[1] then bp2[1]
  else if bp1 then 1
  else bp2[1];
def bp3 = if !bp2[1] and bp2 then 1 else 0;

AddChartBubble(buy_bubbles_on and bp3, high * 1.0005, "Buy Put", Color.RED, yes);

addchartbubble(0,low*.997,
 close[buyoff] + "\n" +
 put_buy_hilo + "\n" +
 bp1 + "\n" +
 bp2 + "\n" +
 bp3
, color.yellow, no);


AddChartBubble(0, low * 0.997,
period + " p\n" +
#buyput + " bp\n" +
close[buyoff] + " cls\n" +
put_buy_hilo + " hl"
, Color.YELLOW, no);


#5) A stop loss "Priceline" is drawn on the "High" of the highest candle. This is a great stop loss and keeps risk at a low with confirmation that the trend is not reversing but also keeps you from getting shaken out by MM's.

plot z4 = hihi_level;
z4.SetDefaultColor(Color.RED);
z4.SetStyle(Curve.MEDIUM_DASH);



#6) On the low candle, place a "Priceline" that is the high of that candle (wicks included).

# buy call
def call_buy_lohi = if bn == 1 or isnan(close) then 0 else if islo then high else call_buy_lohi[1];
plot z5 = if  call_buy_lohi > 0 then call_buy_lohi else na;
z5.SetDefaultColor(Color.GREEN);

#7) Once a candle closes a HH above that "Priceline", place a bubble called "Buy Calls" on that candle. It has to close above the high of the lowest candle. It would be great to have this candle also painted a customer color. Again, default should be black.

# use offset so first bar of call_buy_lohi  checked is after the buy signal. so its not trying to cross above a na
#def bc1 = if period and !isnan(call_buy_lohi[1]) then (close[buyoff] crosses above call_buy_lohi) else 0;

def bc1 = if period and !first then (close[buyoff] crosses above call_buy_lohi) else 0;
def bc2 =
  if bn == 1 then 0
  else if bc2[1] then bc2[1]
  else if bc1 then 1
  else bc2[1];
def bc3 = if !bc2[1] and bc2 then 1 else 0;

AddChartBubble(buy_bubbles_on and bc3, low * 0.9995, "Buy Call", Color.GREEN, no);

addchartbubble(0,low*.997,
 close[buyoff] + "\n" +
 call_buy_lohi + "\n" +
 bc1 + "\n" +
 bc2 + "\n" +
 bc3
, color.yellow, no);


#8) A stop loss "Priceline" is drawn on the "Low" of the lowest candle. Again, another great stop loss to keep your risk at a minimum but also confirms that the trend reversal is not manifesting.

#  call stop , long stop
#def call_sell_lolo = if bn == 1 then na else if islo then low else call_sell_lolo[1];
#plot z6 = call_sell_lolo;
plot z6 = lolo_level;
z6.SetDefaultColor(Color.GREEN);
z6.SetStyle(Curve.MEDIUM_DASH);



#9) Also, I would like the indicator to have a trailing stop loss. I forgot to include this important point.


# 10  Once it has moved 50% from current entry,
#   for puts, put a stop loss at the HH of the last two candles
#   for calls, put a stop loss at the LL of the last two candles

#input gain_stop_percent = 50;
input gain_stop_percent = 20;

def offx = 2;
def ref_bubble_x = (!IsNaN(close[offx]) and IsNaN(close[(offx-1)]));


# puts
def putreflevel = put_buy_hilo - (put_buy_hilo * (gain_stop_percent/100));

plot z23 = if put_buy_hilo > 0 then  putreflevel else na;
z23.SetDefaultColor(Color.light_red);
z23.SetStyle(Curve.medium_DASH);

plot z24 = z23;
z24.SetDefaultColor(Color.light_gray);


addchartbubble(ref_bubble_x and show_stop, z23[offx],
gain_stop_percent + "%  put stop ref"
, color.yellow, yes);

addchartbubble(0, low,
  put_buy_hilo + "\n" +
 putreflevel + "\n" +
 z23
, color.yellow, no);


# calls
def callreflevel = call_buy_lohi + (call_buy_lohi * (gain_stop_percent/100));
# dashed line for stop , gray/red. draw dash line first
plot z25 = if call_buy_lohi > 0 then callreflevel else na;
z25.SetDefaultColor(Color.green);
z25.SetStyle(Curve.medium_DASH);

plot z26 = z25;
z26.SetDefaultColor(Color.blue);

z23.sethiding(!show_stop);
z24.sethiding(!show_stop);
z25.sethiding(!show_stop);
z26.sethiding(!show_stop);


addchartbubble(ref_bubble_x and show_stop, z25[offx],
gain_stop_percent + "%  call stop ref"
, color.yellow, no);


## Signals
addcloud(if add_cloud and (sum(bc3, buffer)==0) then z3 else na, z4, color.red, color.red);
addcloud(if add_cloud and (sum(bp3, buffer)==0) then z5 else na, z6, color.green, color.green);

plot down = !buy_bubbles_on and bp3 and ( sum(bc3, buffer)==0);
down.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
down.setdefaultcolor(color.red);
down.setlineweight(3);

plot up = !buy_bubbles_on and bc3 and (sum(bp3, buffer)==0 );
up.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
up.setdefaultcolor(color.green);
up.setlineweight(3);


## Fibs
input showfibs = yes;

def h = hihi;
def l = lolo;
def range = h - l;

plot high = if showfibs then h else double.nan;
plot fib113 = if showfibs then h-(range*.113) else double.nan;
plot fib236 = if showfibs then h-(range*.236) else double.nan;
plot fib382 = if showfibs then h-(range*.382) else double.nan;
plot fib50 = if showfibs then h-(range*.5) else double.nan;
plot fib618 = if showfibs then h-(range*.618) else double.nan;
plot fib764 = if showfibs then h-(range*.764) else double.nan;
plot fib887 = if showfibs then h-(range*.887) else double.nan;
plot low = if showfibs then l else double.nan;


high.setdefaultcolor(color.red);
fib113.setdefaultcolor(color.yellow);
fib236.setdefaultcolor(color.yellow);
fib382.setdefaultcolor(color.yellow);
fib50.setdefaultcolor(color.white);
fib618.setdefaultcolor(color.yellow);
fib764.setdefaultcolor(color.yellow);
fib887.setdefaultcolor(color.yellow);
low.setdefaultcolor(color.green);


high.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib113.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib236.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib382.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib50.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib618.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib764.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib887.setPaintingStrategy(paintingStrategy.HORIZONTAL);
low.setPaintingStrategy(paintingStrategy.HORIZONTAL);

#
Hello, i use your code but a few issues arrise.
1. the chart will not let me zoom out without the price lines becoming very very small.
2. i have to have the extended hours turned off.
3. if i view the previous day, the line is very small.
Can you help me with understanding what i am doing wrong?
 
Hello, i use your code but a few issues arrise.
1. the chart will not let me zoom out without the price lines becoming very very small.
2. i have to have the extended hours turned off.
3. if i view the previous day, the line is very small.
Can you help me with understanding what i am doing wrong?
The lines only go back as far as your look back period. The default look back is 20 candles.
 
Hello, i use your code but a few issues arrise.
1. the chart will not let me zoom out without the price lines becoming very very small.
2. i have to have the extended hours turned off.
3. if i view the previous day, the line is very small.
Can you help me with understanding what i am doing wrong?
1. You can adjust the size of the lines by going into the settings of the indicator if they are too small.
2. I would never turn the extended hours off. I keep them on all the time and the indicator works fine. You may need to look in your settings on the specific chart you are using.
3. I don't think you should have any lines from the indicator on the previous day if your candles are set to 20 and using anything below 30 minutes. But the lines may be running equal to other lines and that may be causing the issue.

Hope this helps!
 
Status
Not open for further replies.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
255 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top