title: Need support with one time alertcondition after trend switch
body: <p>I am new in pine script and wants to have an one time alert in case of an trend switch (green to red and red to green).</p>
  
  <p>Who can help me to have alerts for this script?</p>
  
  <pre><code>//@version=4
  study("Hilo script with alert",overlay=true)
  period=input(10,"Period")
  shift=input(1,"Shift")
  exp=input(false,"EMA")
  max=exp?ema(high[shift],period):sma(high[shift],period)
  min=exp?ema(low[shift],period):sma(low[shift],period)
  pos=close&gt;max?-1:close&lt;min?1:0
  pos:=pos==0?nz(pos[1]):pos
  hilo=pos==1?max:min
  plotbar(hilo,hilo,hilo,hilo,color=pos==1?color.red:color.green)
  </code></pre>
  
  <p>Thanks a lot for all your help in advance</p>
  
  <p>My idea was this:</p>
  
  <pre><code>sell = pos:=1
  buy = pos==1
  alertcondition(sell,title='sell', message='sell')
  alertcondition(buy,title='buy', message='buy')
  </code></pre>
  
  <p>but I get every candle an alert. And this isnt that what i want.</p>
  
  <p>After and research in the internet I was able to find this:</p>
  
  <pre><code>// Deternine if we are currently LONG
  isLong = false
  isLong := nz(isLong[1], false)
  // Determine if we are currently SHORT
  isShort = false
  isShort := nz(isShort[1], false)
  // Buy if the buy signal is triggered and we are not already long
  buySignal = not isLong
  // Sell if the sell signal is triggered and we are not already short
  sellSignal= not isShort
  if (buySignal)
      isLong := true
      isShort := false
  if (sellSignal)
      isLong := false
      isShort := true
  alertcondition(buySignal,title='buy',message='buy')
  alertcondition(sellSignal,title='sell', message='sell')
  </code></pre>
  
  <p>But Iam getting some errors in Tradingview:</p>
  
  <pre><code>//@version=4
  study("Hilo script with alertr",overlay=true)
  period=input(8,"Period")
  shift=input(1,"Shift")
  exp=input(false,"Exponential moving average")
  max=exp?ema(high[shift],period):sma(high[shift],period)
  min=exp?ema(low[shift],period):sma(low[shift],period)
  pos=close&gt;max?-1:close&lt;min?1:0
  isLong:=pos==0?nz(pos[1]):pos
  isShort=pos==1?max:min
  plotbar(isShort,isShort,isShort,isShort,color=pos==1?color.red:color.green)
  
  // Deternine if we are currently LONG
  isLong = false
  isLong := nz(isLong[1], false)
  
  // Determine if we are currently SHORT
  isShort = false
  isShort := nz(isShort[1], false)
  
  // Buy only if the buy signal is triggered and we are not already long
  buySignal = not isLong
  
  // Sell only if the sell signal is triggered and we are not already short
  sellSignal= not isShort
  
  if (buySignal)
      isLong := true
      isShort := false
  
  if (sellSignal)
      isLong := false
      isShort := true
  
  alertcondition(sellSignal,title='sell', message='sell')
  alertcondition(buySignal,title='buy', message='buy')
  </code></pre>
  
  <p>after your valueable feedback I adapt this lines:</p>
  
  <pre><code>isLong=pos==0?nz(pos[1]):pos
  isShort=pos==1?max:min
  plotbar(isShort,isShort,isShort,isShort,color=pos==1?color.red:color.green)
  
  // Deternine if we are currently LONG
  isLong = false
  isLong := nz(isLong[1], false)
  
  // Determine if we are currently SHORT
  isShort = false
  isShort := nz(isShort[1], false)
  </code></pre>
  
  <p>Now Iam getting in Line 14 an error marked with >>>>:</p>
  
  <pre><code>// Deternine if we are currently LONG
  &gt;&gt;&gt;&gt;isLong = false
  isLong := nz(isLong[1], false)
  </code></pre>