pine-scriptpine-script-v5pine-script-v4

Pass alert from one script to another


I have alerts two indicators first over candles and second at lower pane. I want to pass the alert value Sell1 of first indicator to another (It can be either one from first to second or second to first ) so that I can create a new alert SellMix when Sell1 and Sell2 is true. Is it a possibility?

E.g: I want to create an alert BuyMix if Buy1 and Buy2 is true OR alert SellMix if Sell1 and Sell2 is true at same time via script.

My alert code is as follow:

//From Indicator 1

alertcondition(buy, title='Buy1', message='Buy1 Label!')
alertcondition(sell, title='Sell1', message='Sell1 Label!')

//From Indicator 2

alertcondition(MacNorm > MacNorm[1], title='Buy2', message='Buy2 Label!')
alertcondition(MacNorm < MacNorm[1], title='Sell2', message='Sell2 Label!')

I tried to set two alerts on each indicator, but given that one script returns Sell1 and other Buy2 at any time, it was not giving clear conclusion call and is not easily maintainable.


Solution

  • Two possiblities:

    1. You would write the same code (except the plotting part) within the other indicator and use the alert variables directly.

    2. You use a plot() for the alerts and in the other indicator, use input.source() to get that value.