static bool lastCondition=false; bool result=(Condition1 && Condition2 && Condition3 && Condition4 && Condition5 && Condition6) if(lastCondition && result) result=false; else lastCondition=result;
This assumes that you only want to action when the result changes from false to true.
Hello again,
Thanks,
that looks a lot better than this.
for(result=false;result!=true;ON_NEW--) { OFF_NEW=0; if(ON_NEW==1)Alert("new input"); break; } for(result=true;result!=false;OFF_NEW--) { ON_NEW=0; if(OFF_NEW==1) Alert("new output"); break;
GrumpyDuckMan:
Hello again,
Thanks,
that looks a lot better than this.
I'm not sure what those loops are trying to do... Assuming you want to "toggle" on fresh conditions you'll want to use a static int so you can initialize it with a sentinel value.
void OnStart() { while(!IsStopped()){ alert_on_change(TimeLocal() % 2 == 0); Sleep(1); } } void alert_on_change(bool condition) { static int state = WRONG_VALUE; if(state == WRONG_VALUE) state = condition; if(state != condition) { Print("Condition changed to ", condition); state = condition; } }
Hello again,
Thank you,
both on you helped a lot. I have never used static variables before. I am still reading over the use of them in the MQL4 reference manual atm.
Hello again,
How about this,
static bool lastCondition=result; bool result=(Condition1 && Condition2 && Condition3 && Condition4 && Condition5 && Condition6) if(lastCondition && result) result=result; else lastCondition=result;
static bool signalCur=false; bool signalPre = signalCur; signalCur = Condition1 && Condition2 && Condition3 && Condition4 && Condition5 && Condition6; if(signalCur && !signalPre) DoIt();
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello everyone,
I have this statement in OnTick(). I'm trying to work out a way to only alert if result changes. atm it triggers an alert everytime even if there isn't a change to result.
How is it possible to make it trigger the alert only if condition changes state?