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
สคริปต์โอเพนซอร์ซ

จากใจ TradingView ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้ผู้ค้าสามารถเข้าใจและตรวจสอบได้ ยินดีด้วย! คุณสามารถใช้มันได้ฟรี แต่การใช้โค๊ดนี้ซ้ำเพื่อการเผยเเพร่ อยู่ภายใต้ กฎของเรา คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้กับชาร์ตได้

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?

ความคิดเห็น

great! Is it possible to configure surendrend in hours or minutes timeframes?
+4 ตอบกลับ
Daveatt zorak2d
@zorak2d, you mean having an hourly supertrend on a different chart timeframe?
ตอบกลับ
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?
ตอบกลับ
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
ตอบกลับ
Coolbeans !
+4 ตอบกลับ
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 ตอบกลับ
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)
ตอบกลับ