0

I am looking for pine script coding with condition when pivot line here blue color of price 179.85 when any candle cross with green (close>open) then give signal, but only once. If in case again same situation come then avoid repeating signal.

Thanks in advance...

enter image description here

rr1050
  • 3
  • 3

1 Answers1

0

You should use the crossover function from pinescript (v5):

alreadycrossed = false
numberofalert = 0
numbermaxofalert = 1

if ta.crossover(close, pivotline)
    alreadycrossed := true

if alreadycrossed and numberofalert < numbermaxofalert
    alert("my alert")
    numberofalert := numberofalert + 1

This way, you will have an alert only the first time the price cross above your pivotline.
Be carefull, in this code, the pivotline must be a serie of float (cf the pinescript manual : https://www.tradingview.com/pine-script-reference/v5/#fun_ta{dot}crossover)

G.Lebret
  • 2,826
  • 2
  • 16
  • 27
  • Hi, I tried your suggestion but not working, reason crossover situation repeats again and again signal appeared on chart. I want only once. That reason, Pivot value to be "na" after alert till get new Pivot or any other solution to get rid of repetitions. – rr1050 Nov 19 '22 at 06:35
  • @rr1050 okay but when should you receive the second signal? – vitruvius Nov 19 '22 at 08:49
  • when new pivotline is created and again cross with green candle. – rr1050 Nov 19 '22 at 09:23
  • @rt1050 I edit my code, now you will have only 1 alert... – G.Lebret Nov 20 '22 at 02:23
  • @rr1050, if you find the answer usefull, please accept it . – G.Lebret Nov 22 '22 at 02:41