TTM Squeeze Oscillator code

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #198001 quote
    Jodal
    Participant
    New

    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

    DEFPARAM CumulateOrders = False
    
    // TTM Squeeze indicator
    
    //---Settings
    //length=20
    //mult=2
    //lengthKC=20
    //multKC=1.5
    //squeezeDotsOffset=0
    //candlesticksSqueeze=0 //boolean variable
    //---End of settings
    
    //BB
    basis = average[length](close)
    dev = mult * Std[length](close)
    upperBB = basis + dev
    lowerBB = basis - dev
    
    //KC
    ma = average[lengthKC](close)
    myrange = range[lengthKC]
    rangema = average[lengthKC](myrange)
    upperKC = ma+rangema * multKC
    lowerKC = ma-rangema * multKC
    
    Timeframe (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 long
    IF NOT LongOnMarket AND c1 AND c3 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    // Conditions to exit a buy position
    If LongOnMarket AND c4 THEN
    SELL AT MARKET
    ENDIF
    // Conditions to enter short
    IF NOT ShortOnMarket AND c2 AND c4 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    // Conditions to exit a sell position
    IF ShortOnMarket AND c3 THEN
    EXITSHORT AT MARKET
    ENDIF
    #198003 quote
    JS
    Participant
    Senior

    Hi @jodal

    I have organised your code a bit so that the “calculations” are under the relevant time frames…

     

    // TTM Squeeze TS
    
    //---Settings
    length=20
    mult=2
    lengthKC=20
    multKC=1.5
    
    Timeframe (30 minutes, UpdateOnClose)
    //BB
    HTFbasis = average[length](close)
    HTFdev = mult * Std[length](close)
    HTFupperBB = HTFbasis + HTFdev
    HTFlowerBB = HTFbasis - HTFdev
     
    //KC
    HTFma = average[lengthKC](close)
    HTFmyrange = range[lengthKC]
    HTFrangema = average[lengthKC](HTFmyrange)
    HTFupperKC = HTFma+HTFrangema * multKC
    HTFlowerKC = HTFma-HTFrangema * multKC
     
    HTFsqzOn = (HTFlowerBB>HTFlowerKC) AND (HTFupperBB<HTFupperKC)
    
    c1 = (HTFsqzOn=1)
    c2 = (HTFsqzOn=0)
    
    Timeframe (1 minute, UpdateOnClose)
    //BB
    LTFbasis = average[length](close)
    LTFdev = mult * Std[length](close)
    LTFupperBB = LTFbasis + LTFdev
    LTFlowerBB = LTFbasis - LTFdev
     
    //KC
    LTFma = average[lengthKC](close)
    LTFmyrange = range[lengthKC]
    LTFrangema = average[lengthKC](LTFmyrange)
    LTFupperKC = LTFma+LTFrangema * multKC
    LTFlowerKC = LTFma-LTFrangema * multKC
     
    LTFsqzOn = (LTFlowerBB>LTFlowerKC) AND (LTFupperBB<LTFupperKC)
    
    c3 = (LTFsqzOn=1)
    c4 = (LTFsqzOn=0)
    
    // Conditions to enter long
    IF NOT LongOnMarket AND c1 AND c3 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    // Conditions to exit a buy position
    If LongOnMarket AND c4 THEN
    SELL AT MARKET
    ENDIF
    // Conditions to enter short
    IF NOT ShortOnMarket AND c2 AND c4 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    // Conditions to exit a sell position
    IF ShortOnMarket AND c3 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    Jodal thanked this post
    #198024 quote
    Jodal
    Participant
    New

    Hi @JS

    Thanks a lot for your reply and reactivity.
    I have 3 questions:
    1.  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).
    2. 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?
    3. 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

    #198049 quote
    JS
    Participant
    Senior
    Hi @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)
    #198050 quote
    Jodal
    Participant
    New
    Hi @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?
    #198051 quote
    JS
    Participant
    Senior
    Hi @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?)

    Jodal thanked this post
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

TTM Squeeze Oscillator code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Jodal @jodal Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by JS
3 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/27/2022
Status: Active
Attachments: No files
Logo Logo
Loading...