Reputation: 23
i tried my best to make it work but i get errors every time:(.. i just want to create a simple alert once the price start crossing up and crossing Down the Horizon Line by 2% will trigger the alert.. so far this is my code but i know that i missed up if you can please guide me to make it right (Breakup and Breakdown is a Horizon Lines that i renamed)
//@version=3
study(title="Alert", overlay=true)
up = Breakup(close, 2%)
down = Breakdown(close, 2%)
alertcondition(condition=crossover(close, up), title="Cross Up", message="Breakup")
alertcondition(condition=crossunder(close, down), title="Cross Down", message="Breakdown")
Upvotes: 0
Views: 456
Reputation: 21199
Just calculate price + 2%
and price - 2%
and use those values in your cross conditions.
Say your target price is 100:
target_price = 100
per = 0.02 // 2%
target_up = target_price * (1 + per)
target_down = target_price * (1 - per)
is_cross_up = crossover(close, target_up)
is_cross_dwn = crossunder(close, target_down)
alertcondition(is_cross_up, "Cross Up")
alertconditino(is_cross_dwn, "Cross Down")
Upvotes: 1