Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 18155

How to stop alert triggering continuously in an mql4 indicator

$
0
0

The alert seems to triggering on every tick, when the condition is met, it continues to trigger instead of triggering only once and wait for when the condition is met again before triggering. The alert is supposed to be triggered when ConsecutiveTrends is met. The numbers of trends in a symbol to trigger the alert. It should loop through all the symbols and when the condition is met in the any of the symbols the alert is triggered on that symbol.

extern int ConsecutiveTrends = 3;// Declare trends and pairName as global variablesstring pairName;int trends[9];// Declare lastAlertState as a global variableint lastAlertState[];// Then check for ConsecutiveTrends consecutive up or down trends    int trendsArraySize = ArraySize(trends);    ArrayResize(lastAlertState, trendsArraySize);    for (int k = 0; k < trendsArraySize; k++) {        int upTrendCount = 0;        int downTrendCount = 0;        // Check for ConsecutiveTrends in the sequence starting from k        for (int j = k; j < trendsArraySize && j < k + ConsecutiveTrends; j++) {            if (trends[j] == 1) {                upTrendCount++;            } else if (trends[j] == -1) {                downTrendCount++;            }        }        // If there are ConsecutiveTrends, trigger the alert and update lastAlertState        if (upTrendCount == ConsecutiveTrends && lastAlertState[k] != upTrendCount) {            if (EnableAlerts)                Alert(pairName, " shows a buy signal on ", TimeFramesToString(k, ConsecutiveTrends), ".");            if (EnablePushNotifications)                SendNotification(pairName +" shows a buy signal on " + TimeFramesToString(k, ConsecutiveTrends) +".");            lastAlertState[k] = upTrendCount;  // Update lastAlertState when ConsecutiveTrends condition is met        } else if (downTrendCount == ConsecutiveTrends && lastAlertState[k] != -downTrendCount) {            if (EnableAlerts)                Alert(pairName, " shows a sell signal on ", TimeFramesToString(k, ConsecutiveTrends), ".");            if (EnablePushNotifications)                SendNotification(pairName +" shows a sell signal on " + TimeFramesToString(k, ConsecutiveTrends) +".");            lastAlertState[k] = -downTrendCount;  // Update lastAlertState when ConsecutiveTrends condition is met        }    }

I tried to use the lastAlertState, but seems not be working.


Viewing all articles
Browse latest Browse all 18155

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>