TradingView
RwTrades
30 Dis 2020 pukul 22.33

Repeating Plot/Alerts Workaround 

SUSHI / TetherUS PERPETUAL CONTRACTBinance

Huraian



Here we have 2 simple conditions for long and short.
Once a condition is met, it ignores the same signal until the other condition is met and vice versa.

Had this issue in a script of mine, but couldn't find any published idea regarding this.

Cheers.
Komen
fareidzulkifli
Good work! since this script is intended as workaround sample, may i suggest something?

1. long_count/short_count -> unnecessary code that doesn't do anything
2. longvar1/shortvar1 -> redundant with long/short
3. since u are comparing barsince, following code should suffice:
long = close > ma2 and close > ma1 short = close < ma1 and close < ma2 barslong = barssince(long)[1] barsshort = barssince(short)[1] long_condition = 0 if(long and barslong > barsshort) long_condition := 1 short_condition = 0 if(short and barsshort > barslong) short_condition := 1 ee= long_condition > 0 qq= short_condition > 0
fareidzulkifli
another way if you don't want to use the barsince:
long = close > ma2 and close > ma1 short = close < ma1 and close < ma2 var lastsignal = 0 long_condition = 0 if(long and lastsignal !=1) long_condition := 1 lastsignal := 1 short_condition = 0 if(short and lastsignal != -1) short_condition := 1 lastsignal := -1 ee= long_condition > 0 qq= short_condition > 0
gauravstocks
@fareidzulkifli, it is giving the same problem. If a buy signal is generated at earlier day, then new buy signal in any further day will not come untile sell is generated
RwTrades
@gauravstocks, Well, that's the whole point of the script.
RwTrades
@fareidzulkifli,

Thank You. Appreciate it. Hope that people find it useful.

There is another way to do it without bars since.

long = close > ma2 and close > ma1 short = close < ma1 and close < ma2 z = long == true x = short == true zx = 0 zx := z ? 1 : x ? 2 : nz(zx[1]) longvar = zx != zx[1] and long == true shortvar = zx != zx[1] and short == true
Ankit99772
@fareidzulkifli, can you help with code if I want to show the signal after every 5 bars?
FlyAngler
Hi guys.
This helped me a lot on my 1st script, but I have a problem remaining.

How I can limit the number of candles back to plot the result of the indicator? In other words, I don't want my chart full of circles and just see if the condition was triggered in during the last 20 or 50 candles.
Thanks!
FlyAngler
@FlyAngler, already solved with 'show_last'
CompoundBot
Thank you!
Lebih