-2

so im trying to write a script which can alert me when the sma of the williams%r crosses above -20 or bellow -80, for the first time in 1 month for example. is this possible with pinescript?.

thanks in advance.

AnyDozer
  • 2,236
  • 2
  • 5
  • 22

1 Answers1

0

Although i understood what you wanted to designed , so i have done the same thing to moving average crossover ,you can see the red background which shows the first crossover in that given timeframe.

you can change time in the setting input below are the codes.

"isTimeChanged" is the variable which is constantly tracking the change.

enter image description here

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © badshah_e_alam

//@version=4
study("1st time crossover alert in given time",overlay=true)

fastMA = sma(close, 10)
slowMA = sma(close, 50)

plot(fastMA,color=color.red)
plot(slowMA)

time_input=input("W",type=input.resolution)

isTimeChanged = false
isTimeChanged := nz(isTimeChanged[1], false)

if(change(time(time_input)) and not nz(isTimeChanged[1]))
    isTimeChanged := true
if crossover(fastMA,slowMA) and nz(isTimeChanged[1])
    isTimeChanged := false

bgcolor(not isTimeChanged and isTimeChanged[1]?color.red:na,transp=10)
alertcondition(not isTimeChanged and isTimeChanged[1],title = "crossover happened first time")
TJalam
  • 308
  • 4
  • 16