V5
V5
If you want, I can also show you a super-clean version with dynamic TP/SL hiding (optional)? 🚀
Would you like that as bonus?
4o
You said:
and also no repaints add with buy sell and ma and tp and sl
ChatGPT said:
Understood! To avoid repainting for the Buy/Sell signals, Moving Averages (MA), TP/SL levels, and
other elements, we need to make sure that the calculations are not redrawn after the bar closes.
The key is to ensure that signals are only generated after a bar has fully closed, and the TP/SL levels
are set at the point of entry (no recalculations after that).
Key fixes:
1. Buy/Sell signals: These are only drawn once a bar is closed and the signal is confirmed.
2. Moving Averages (MA): The cloud or line indicators for MAs won't repaint as we calculate
them based on the closed bar.
3. TP/SL levels: These lines are only drawn when the position is taken, and they are not
recalculated.
4. No repeated labels or lines: Avoid creating new labels and lines for every bar; rather, update
them only when the position changes.
pinescript
CopyEdit
//@version=5
indicator("Trend Signals with TP & SL [UAlgo] MTF (No Repaint)", shorttitle="Trend Signals MTF",
overlay=true, max_lines_count=100, max_labels_count=100)
momm1 = ta.change(src1)
momm2 = ta.change(src2)
m1 = math.max(momm1 - momm2, 0)
m2 = math.max(momm2 - momm1, 0)
rsiCalc = ta.rsi(close_htf, 9)
hh = ta.highest(high_htf, 2)
ll = ta.lowest(low_htf, 2)
hpivot = ta.dev(hh, 2) ? na : hh
lpivot = ta.dev(ll, 2) ? na : ll
atr_basic = ta.atr(atrPeriods)
atr_sma = ta.sma(ta.tr, atrPeriods)
trend := na(trend[1]) ? 1 : (trend[1] == -1 and close_htf > dn1 ? 1 : trend[1] == 1 and close_htf < up1 ?
-1 : trend[1])
entryPrice := close_htf
position := 1
line.delete(entryLine)
line.delete(stopLine)
line.delete(tp1Line)
line.delete(tp2Line)
line.delete(tp3Line)
label.delete(buySellLabel)
// Draw lines
entryPrice := close_htf
position := -1
line.delete(entryLine)
line.delete(stopLine)
line.delete(tp1Line)
line.delete(tp2Line)
line.delete(tp3Line)
label.delete(buySellLabel)
// Draw lines
if not na(entryPrice)
label.delete(slPriceLabel)
label.delete(tp1PriceLabel)
label.delete(tp2PriceLabel)
label.delete(tp3PriceLabel)
Key changes:
1. Repainting Prevention: Signals, lines, and labels only get drawn once after a bar closes.
2. Entry Price & SL/TP: These values are set once at entry and not recalculated.
3. Memory Management: No lines or labels are repeatedly drawn every bar; they're updated
only when a new position is triggered.
This ensures that Buy/Sell signals, Moving Averages, and TP/SL levels are stable and do not repaint.
4o mini
You said:
it didnt work well like buy sell signals and tp and sl line
ChatGPT said:
It sounds like the issue still isn't fully resolved. Let’s break this down and fix it in smaller steps to
ensure the buy/sell signals and TP/SL lines display correctly without repainting or errors.
Problem Recap:
1. Buy/Sell Signals: Need to be plotted correctly and stable once confirmed, with no repainting.
2. TP and SL lines: These should be fixed once the entry is made and shouldn’t change after
that.
3. No repeated labels/lines: We need to manage the memory properly and not repeatedly
create new lines or labels every bar.