Multi Supertrend with no-repaint HTF option strategy

This is the strategy version of the multi supertrend indicator.
The RoMDD looks good :)
Checked in ETHUSDT 1hour with auto HTF ON.
Have a look :)
Script de código aberto

No verdadeiro espírito TradingView, o autor deste script o publicou com código aberto, para que os traders possam compreendê-lo e verificá-lo. Um brinde ao autor! Você pode usá-lo gratuitamente, mas a reutilização deste código em uma publicação é regida pelas Regras da Casa. Você pode favoritá-lo para utilizá-lo em um gráfico.

Quer usar esse script no gráfico?
Jack and Jill, went up the hill.

Consider showing your appreciation through comments

You can also buy us a healthy snack
Wallet address for USDT :

TRC20 on Tron Blockchain


why have you used " lookahead = barmerge.lookahead_on " it will lead repaint and show desirable results that when applied in real time would act and work differently.
Please don't mislead people here.
+4 Resposta
ramki_simple Aditya_Jaiswal05
@Aditya_Jaiswal05, Apologies for the late reply bro, actually, this is a trick to get a stable non-repaint output.

Add this code on a 1 min chart,

study("My Script", overlay=true)
f_Security(_symbol, _res, _src) => security(_symbol, _res, _src, lookahead = barmerge.lookahead_on)
plot(f_Security(syminfo.tickerid,'5',close),color=color.navy) //stable output without repaint
plot(security(syminfo.tickerid,'5',close),color=color.black) //instable output and repainting to old
plot(security(syminfo.tickerid,'5',close, lookahead = barmerge.lookahead_on),color=color.silver) //instable output and repainting to future

For every curve we try to describe, we need to keep track of few things:

- A : 5 min candle close(HTF)
- B : 1 min candle close
- C : curve output in 1 min timeframe

We will refer to them as A, B and C to simplify things.
"A(12:10)" means close of 5 min candle at 12:10. This is representing time from 12:10:00 to 12:14:59

Let us study each curve. First, we will look at the black curve
security(syminfo.tickerid,'5',close)// we will call this C

When you plot this, you will immediately see a curve plotting the last closed candle in 5 min, our HTF.
It is flat at this value, till, we see a new close in HTF.

If you notice carefully, after the indicator is plotted, you are seeing an unstable output, wiggly end points.
It trying to approximate the latest close, even before it has closed.

Once the HTF candle has closed. For example, C(12:14) aligns with A(12:10) . We will see the black line latching on the close.
Also, the wiggly line is now flat. Means, it has repainted. If it has not, just refresh your chart and you will get a perfect curve.
For example, 1 min timeframe 12:12 candle black curve, C(12:12) is repainted to A(12:05), that we already know as B(12:09).
If you notice, C(12:12) repainted to a value we knew at 12:10.

Now we will consider the silver curve
security(syminfo.tickerid,'5',close, lookahead = barmerge.lookahead_on)//we will call this D

If you notice, carefully, in a few 1 min candles, you will see that, the wiggly values of the black and the silver curve is the same.
When the HTF candle is closed, it is repainted to be looking ahead, in the sense that, we repaint D(12:10) through D(12:14) to A(2:10).
Note that, B(12:14) is same as A(12:10), this value is used for D(12:12). This data was not available at 12:12

So, we have seen 2 kinds of repainting at 12:12 candle. Black curve is repainting to known value, while silver curve is repainting to values unavailable at that time.

Ideally, we want to be as close as possible to the repainted black curve, latest data, but, without the repainting.

Here comes in the blue curve,
security(_symbol, _res, _src, lookahead = barmerge.lookahead_on)

Notice, the output is delayed from black curve by a 1 min candle, but, output is stable.
To put it tersely, "it is repainting to same known value".
Please, work that out as an exercise.
ramki_simple ramki_simple
@ramki_simple, There is a typo.
Read "we repaint D(12:10) through D(12:14) to A(2:10)."
as "we repaint D(12:10) through D(12:14) to A(12:10)."

Typed the wrong time
ramki_simple ramki_simple
@ramki_simple, oh my god, the security function is printed wrong, even the blue curve is typed wrong.
ramki_simple ramki_simple
@ramki_simple, somehow, the comment field is skipping, \square_bracket 1 \square_bracket_close in the source field, please refer to the published code for correct f_Security function. Square bracket is not working.
allanster Aditya_Jaiswal05
@Aditya_Jaiswal05, the author's custom function for security is correct and does not repaint because it calls the PREVIOUS bar's source AND uses barmerge.lookahead_on:

repaint   = security(syminfo.tickerid, "D", close)
noRepaint = security(syminfo.tickerid, "D", close‎‎BRACKET 1 BRACKET, lookahead = barmerge.lookahead_on)

I would encourage you to see the following scripts for further info: