Pine Script alertcondition() requires const string (no variables allowed)
Switched to alert() function which supports series string (dynamic values)
Changes:
- Removed alertcondition(), added if barstate.isconfirmed + alert()
- Build JSON message with all metrics dynamically
- alert.freq_once_per_bar ensures one alert per candle close
- Now includes all required fields: atr, adx, rsi, volumeRatio, pricePosition, maGap
Alert setup in TradingView:
1. Add indicator to 1-minute chart
2. Create alert on indicator
3. Condition: 'alert() function calls' (not alertcondition)
4. Frequency: Once Per Bar Close
5. Message: Use {{strategy.order.alert_message}} or leave blank
46 lines
1.8 KiB
Plaintext
46 lines
1.8 KiB
Plaintext
//@version=6
|
|
indicator("Money Line - 1min Data Feed", overlay=false)
|
|
|
|
// ==========================================
|
|
// PURPOSE: Send market data every 1 minute
|
|
// USAGE: Create alert on indicator with "alert() function calls"
|
|
// WEBHOOK: https://flow.egonetix.de/webhook/tradingview-bot-v4
|
|
// ==========================================
|
|
|
|
// Calculate indicators (same as v9 for consistency)
|
|
atr = ta.atr(14)
|
|
[diPlus, diMinus, adx] = ta.dmi(14, 14) // ADX returns tuple in Pine v5+
|
|
rsi = ta.rsi(close, 14)
|
|
volumeRatio = volume / ta.sma(volume, 20)
|
|
pricePosition = (close - ta.lowest(low, 100)) / (ta.highest(high, 100) - ta.lowest(low, 100)) * 100
|
|
|
|
// Moving averages for MA gap analysis
|
|
ma50 = ta.sma(close, 50)
|
|
ma200 = ta.sma(close, 200)
|
|
maGap = math.abs((ma50 - ma200) / ma200 * 100)
|
|
|
|
// Display values (optional - for visual confirmation)
|
|
plot(adx, "ADX", color=color.blue, linewidth=2)
|
|
hline(20, "ADX 20", color=color.gray, linestyle=hline.style_dashed)
|
|
hline(25, "ADX 25", color=color.orange, linestyle=hline.style_dashed)
|
|
|
|
// Build JSON message dynamically
|
|
// alert() function allows series string (dynamic values)
|
|
jsonMessage = '{"action":"market_data_1min"' +
|
|
',"symbol":"' + syminfo.ticker + '"' +
|
|
',"timeframe":"1"' +
|
|
',"atr":' + str.tostring(atr) +
|
|
',"adx":' + str.tostring(adx) +
|
|
',"rsi":' + str.tostring(rsi) +
|
|
',"volumeRatio":' + str.tostring(volumeRatio) +
|
|
',"pricePosition":' + str.tostring(pricePosition) +
|
|
',"currentPrice":' + str.tostring(close) +
|
|
',"maGap":' + str.tostring(maGap) +
|
|
',"timestamp":' + str.tostring(time) +
|
|
',"indicatorVersion":"v9"}'
|
|
|
|
// Send alert every bar close
|
|
// Use alert() instead of alertcondition() to allow dynamic message
|
|
if barstate.isconfirmed
|
|
alert(jsonMessage, alert.freq_once_per_bar)
|