We have an existing pine script for alerts for buy and sell using 2 MAs (moving averages) crossing over and under.
Problem: A buy order is sometimes followed by another buy order.
We believe this happens because sometimes the faster MA goes above the slower MA but the candle closes below the slower MA in one candle, bringing the faster MA below the slower MA again without a sell alert as we can only have one alert per bar.
Solution: We want you to modify our script so every buy alert to be followed by a sell alert based on the MAs crossing over or under in real time and not per bar close.
Script:
//@version=2
study("MA Alert 2")
src = input(close)
ma_1 = sma(src, 3)
ma_2 = sma(src, 30)
c = crossover(ma_1, ma_2)
d = crossover(ma_2, ma_1)
alertcondition(c, title='Red crosses blue', message='BUY_BITTREX_BTC-')
alertcondition(d, title='Blue crosses red', message='SELL_BITTREX_BTC-')
plot(ma_1, color=red)
plot(ma_2, color=blue)
plot(crossover(ma_2, ma_1) ? ma_2 : na, style = cross, linewidth = 7)
plot(crossover(ma_1, ma_2) ? ma_1 : na, style = circles, linewidth = 7)