TTM Squeeze Oscillator code
Forums › ProRealTime English forum › ProOrder support › TTM Squeeze Oscillator code
- This topic has 5 replies, 2 voices, and was last updated 2 years ago by
JS.
-
-
07/27/2022 at 8:42 PM #198001
Hello hello,
I would like to integrate the TTM Squeeze Oscillator in my trading strategy.
Here is the link of the indicator coded by Nicolas : https://www.prorealcode.com/prorealtime-indicators/ttm-squeeze-oscillator-price-version/.
To make things easier :), I would like to use 2 timeframes.
For example, I want to place a buy order when the trend is bullish on the 30min chart and bullish on the 1min chart.
I tried something below but I am not sure/convinced this is correct, can someone have a look please?
I basically want to understand which elements in the indicator I should use to apply it to my strategy.Thank you in adcance!
Best, Jo
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152DEFPARAM CumulateOrders = False// TTM Squeeze indicator//---Settings//length=20//mult=2//lengthKC=20//multKC=1.5//squeezeDotsOffset=0//candlesticksSqueeze=0 //boolean variable//---End of settings//BBbasis = average[length](close)dev = mult * Std[length](close)upperBB = basis + devlowerBB = basis - dev//KCma = average[lengthKC](close)myrange = range[lengthKC]rangema = average[lengthKC](myrange)upperKC = ma+rangema * multKClowerKC = ma-rangema * multKCTimeframe (30 minutes, updateonclose)sqzOn15 = (lowerBB>lowerKC) AND (upperBB<upperKC)c1 = (sqzOn15=1)c2 = (sqzOn15=0)//Timeframe (1 minute,UpdateOnClose)sqzOn1 = (lowerBB>lowerKC) AND (upperBB<upperKC)c3 = (sqzOn1=1)c4 = (sqzOn1=0)// Conditions to enter longIF NOT LongOnMarket AND c1 AND c3 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit a buy positionIf LongOnMarket AND c4 THENSELL AT MARKETENDIF// Conditions to enter shortIF NOT ShortOnMarket AND c2 AND c4 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit a sell positionIF ShortOnMarket AND c3 THENEXITSHORT AT MARKETENDIF07/27/2022 at 10:35 PM #198003Hi @jodal
I have organised your code a bit so that the “calculations” are under the relevant time frames…TTM Squeeze TS1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// TTM Squeeze TS//---Settingslength=20mult=2lengthKC=20multKC=1.5Timeframe (30 minutes, UpdateOnClose)//BBHTFbasis = average[length](close)HTFdev = mult * Std[length](close)HTFupperBB = HTFbasis + HTFdevHTFlowerBB = HTFbasis - HTFdev//KCHTFma = average[lengthKC](close)HTFmyrange = range[lengthKC]HTFrangema = average[lengthKC](HTFmyrange)HTFupperKC = HTFma+HTFrangema * multKCHTFlowerKC = HTFma-HTFrangema * multKCHTFsqzOn = (HTFlowerBB>HTFlowerKC) AND (HTFupperBB<HTFupperKC)c1 = (HTFsqzOn=1)c2 = (HTFsqzOn=0)Timeframe (1 minute, UpdateOnClose)//BBLTFbasis = average[length](close)LTFdev = mult * Std[length](close)LTFupperBB = LTFbasis + LTFdevLTFlowerBB = LTFbasis - LTFdev//KCLTFma = average[lengthKC](close)LTFmyrange = range[lengthKC]LTFrangema = average[lengthKC](LTFmyrange)LTFupperKC = LTFma+LTFrangema * multKCLTFlowerKC = LTFma-LTFrangema * multKCLTFsqzOn = (LTFlowerBB>LTFlowerKC) AND (LTFupperBB<LTFupperKC)c3 = (LTFsqzOn=1)c4 = (LTFsqzOn=0)// Conditions to enter longIF NOT LongOnMarket AND c1 AND c3 THENBUY 1 CONTRACT AT MARKETENDIF// Conditions to exit a buy positionIf LongOnMarket AND c4 THENSELL AT MARKETENDIF// Conditions to enter shortIF NOT ShortOnMarket AND c2 AND c4 THENSELLSHORT 1 CONTRACT AT MARKETENDIF// Conditions to exit a sell positionIF ShortOnMarket AND c3 THENEXITSHORT AT MARKETENDIF1 user thanked author for this post.
07/28/2022 at 9:32 AM #198024Hi @JS
Thanks a lot for your reply and reactivity.I have 3 questions:- Is it possible to take into account the momentum squeeze (green/red dots in the indicator)? So that one condition to execute the trade is that the market is trending (green dot).
- I would also like to consider ONLY when the trend is not decreasing( the light blue and red candle)
I guess I need to include the “val” and “value” elements in the code? - Do you confirm that with your code above, the update will be done at the end of each candle? For example, if the M30 candle at 15:00 meets all conditions, then every time a M1 candle meets the conditions between 15:30 and 16:00, an order will be executed?
Have a nice day!
Jo
07/28/2022 at 8:01 PM #198049Hi @jodal
I think it should first be clear what all those beautiful colours stand for 😉
In the original indicator it is described that when there is a consolidation going on that the points in the oscillator turn red and when the market is in a trend that the points turn green.
When I look at the corresponding chart, I think it is the other way around, when there is a consolidation, the points turn green and when the market is in a trend the points turn red.
When the BB falls within the KC then the volatility is low and there is a consolidation (points are green) and when the BB outside the KC then the volatility is high, and the market is in a trend (points are red).
What I think are the best signals:
Trend rising: red points + rising light blue (momentum increases in the rising trend)
Trend downwards: red points + falling red (momentum increases in a downward trend)
In code:
Trend rising: sqzOn = 0 (red) and val > 0 and val > val[1] (light blue)
Trend downwards: sqzOn = 0 (red) and val < 0 and val < val[1] (red)
07/28/2022 at 8:31 PM #198050Hi @JS,
Thank you for your feedback and for thinking along with me!
Actually there was a mistake from Nicolas in the original code (you can check the comments below the indicator code).
So the trend is rising when : green points + rising light blue (momentum increases in the rising trend)
and the trend is going downwards when : green points + falling red (momentum increases in a downward trend)
Red points mean that we are in a consolidation.
Or maybe I am mistaken?
Does the code you proposed remain the same?
07/28/2022 at 8:53 PM #198051Hi @jodal,
What I see in the original chart and in the original code is that a trend goes hand in hand with red dots and a consolidation with green dots…
The code can be adapted to the conditions I have indicated:
Trend rising: sqzOn = 0 (red) and val > 0 and val > val[1] (light blue)
Trend downwards: sqzOn = 0 (red) and val < 0 and val < val[1] (red)
(or do you want me to change the code?)
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on