'How can I stop alarms triggering inside max pyramid argument?
I have some PineScript codes executin, the alarms are sent out to my MT4 account to execute trades, alarms should only go off when a trade gets executed in tradingview. The problem is that they keep getting executed even though max pyramid has been reached and I have that condition set. Any idea on how to stop this from happening? here's some of the code:
//Strategy
maxPyramid = input.int(title="Max Pyramiding", defval=3)
Long = high > h1[1] and close > regime and rangehl > 4 and strategy.opentrades <= maxPyramid
Short = close < l1[1] and rangehl > 5 and strategy.opentrades <= maxPyramid
m_check_l = close > mid[1] and close[5] > mid[5] and close[6] > mid[6]
if Long and m_check_l and time > startDate and time < endDate
strategy.entry('Long', strategy.long)
if ta.crossunder(close, mid)
strategy.close('Long')
alert(message = "close UKSUGAR long", freq = alert.freq_once_per_bar)
if Short and time > startDate and time < endDate
strategy.entry('Short', strategy.short)
if ta.crossover(close, mid)
strategy.close('Short')
alert(message = "close UKSUGAR short", freq = alert.freq_once_per_bar)
//Alerts
if Long and strategy.opentrades <= maxPyramid
alert(message = "buy UKSUGAR q=1", freq = alert.freq_once_per_bar)
if Short and strategy.opentrades <= maxPyramid
alert(message = "sell UKSUGAR q=1", freq = alert.freq_once_per_bar)
Solution 1:[1]
Use the alert_message parameter of strategy.x calls.
if ta.crossunder(close, mid)
strategy.close('Long')
alert(message = "close UKSUGAR long", freq = alert.freq_once_per_bar)
You have an alert() call inside an if block. What's gonna happen is, if that if condition is true, it will execute that strategy.close() and alert() call. Those are two different calls. strategy() calls will depend on your strategy settings but the alert() call will be executed anyway.
if ta.crossunder(close, mid)
strategy.close('Long', alert_message="close UKSUGAR long")
If you use the alert_message parameter, alert message will be triggered if that strategy call is executed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vitruvius |
