Multiple Alerts

lndshrk

Member
Joined
Jun 13, 2019
Posts
13
Likes
2
I have the following code in which I set the Signal flag to True after an alert condition is met. However, I'm still occasionally getting multiple alerts when real time updates are enabled.

Any ideas why the flag doesn't stay "True" and allows the alert to fire again?

if( crossedAbove(series, i, Val.SMI1, smiThresUP)
&& !series.getBoolean(i, Signals.smiPullback, false)) //checks to see if a signal has already fired.
{
series.setBoolean(i, Signals.smiPullback, true); //set the Signal to true

Double bottom = round(series.getHigh(i));
Coordinate c = new Coordinate(series.getStartTime(i), bottom);
MarkerInfo marker = getSettings().getMarker(smi_PULLBACK_MARKER);
String msg = get("SMI Pullback", series.getLow(i), format(series.getClose(i)));
if (marker.isEnabled()) addFigure(new Marker(c, Enums.Position.TOP, marker, msg));
ctx.signal(i, Signals.smiPullback, msg, round(series.getLow(i)));
}
 

Spin

Well-known member
Joined
May 22, 2019
Posts
478
Likes
191
In connection to my 'Calculate' and 'CalculateValues'-thread: did you put this in a piece of the code that gets 'overruled' afterwards in another method ?
 

lndshrk

Member
Joined
Jun 13, 2019
Posts
13
Likes
2
So - these little issues really caused me a ton of headaches.. but I finally figured it out. I tend to build a lot of methods (functions) in my studies.. but Java, being multi-threaded, will try to create different threads for the different function calls - and I was seeing in the debugger that it was actually making some calculations out of order.. The fix was to essentially force it go single thread for anything that would change the state of a variable..

This is done by adding the word "synchronized" to the method.. like

public synchronized void Foo(ctx, i) {}
 

Spin

Well-known member
Joined
May 22, 2019
Posts
478
Likes
191
Ha! Glad you figured that out :)
I actually read about 'synchronized' somewhere when I had trouble with something similar in my studies. The problem was solved back then, but I had no idea of the workings 'behind the curtain'. Good to know, as this will surely help us all in future MW-coding-endeavours ! (y)
 
Top