Daveatt

BEST Supertrend Strategy

Hello traders

Sharing a sample Supertrend strategy to illustrate how to calculate a convergence and using it in a strategy

I based the setup as follow:

- Entries on Supertrend MTF breakout + moving average cross. Entering whenever there is a convergence
- exit whenever a Simple Moving Averages cross in the opposite direction happen
- possibility to filter only Longs/Shorts or both


All the best
Dave
Skrip sumber terbuka

Dalam semangat TradingView yang sebenar, penulis skrip ini telah menerbitkannya dengan menggunakan sumber terbuka supaya pedagang-pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda dapat menggunakannya secara percuma tetapi penggunaan semula kod ini dalam penerbitan adalah dikawalselia oleh Peraturan Rumah. Anda boleh menyukai skrip ini untuk menggunakannya pada carta.

Ingin menggunakan skrip ini pada carta?
šŸ’° Results/Blogs: https://bit.ly/2ULUtjo

ā© Signals/Pricing: https://best-trading-indicator.com/pages/pricing

šŸ¦ Twitter: https://twitter.com/bti_trading

šŸ‘‰ Get a $30 discount on TradingView: https://bit.ly/2UM5OA0

šŸ“ŗ Youtube: https://bit.ly/3bKvnZu

Komen

great! Is it possible to configure surendrend in hours or minutes timeframes?
+4 Balas
Daveatt zorak2d
@zorak2d, you mean having an hourly supertrend on a different chart timeframe?
Balas
hi @Daveatt, I tried to change the code to insert supertrend in 30, 60 and 120 minutes, however I failed. Do you have any clue or even give a hand on that try?
Balas
Daveatt leonardoabad
@leonardoabad, probably too many things to change for that
Better to start from a strategy template from scratch, and implement the supertrend function without the security function AND just adding resolution="" in the strategy(....) function
Balas
Coolbeans !
+4 Balas
Tried this script and the entries on real time got repainted after refreshing and moved to an earlier time. This is because of presence of "lookahead=true" argument in the security function. To get realistic results during back testing, one should change the specific arguments to " lookahead =false". However this script has good educational value. Thanks
+1 Balas
Daveatt bandy99
@bandy99, excellent comment
this is an old script
To avoid repainting with live data, we can use security functions as explained here:

// ā€”ā€”ā€”ā€”ā€” SILVER (BEST): Uses only one `security()` call but allows repainting control.
//          - Cannot be used when the source is a tuple-returning function (use the following method then).
//          The first three parameters are the same as those of `security()`. 
//          The last one: `_rep`, must be a boolean (true/false) value. It indicates if you want repainting (true) or not (false).
//ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼ā–¼
f_security(_sym, _res, _src, _rep) => security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
//ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²ā–²
c1 = f_security(ticker, i_timeframe, i_source, i_repaint)
plot(c1, "c1: šŸ‘ `f_security()`", color.silver, 14)

// ā€”ā€”ā€”ā€”ā€” SILVER (BEST for tuples): Technique providing the functional equivalent of `f_security()` for use with functions returning a tuple.
f_oc(_offset) => 
    // int _offset: the first half of the offset calcs required to achieve repainting/non-repainting.
    //              The second half will be handled post `security()` call, by indexing the received tuple values in a variable reassignment.
    _o = open[_offset]
    _c = close[_offset]
    [_o, _c]
[o_, c_] = security(ticker, i_timeframe, f_oc(not i_repaint and barstate.isrealtime ? 1 : 0))
o = o_[i_repaint or barstate.isrealtime ? 0 : 1]
c = c_[i_repaint or barstate.isrealtime ? 0 : 1]
c2 = c
plot(c2, "c2: šŸ‘ Tuple form", color.fuchsia, 8)
Balas