Newbie Programming Question, Is it possible to make a condition only occur once until it appears again?
You have answered your own question...
static bool CheckMa = false; if(ma - ma2 < 0){ // ma2 is greater than ma CheckMa = true; } if(ma - ma2 > 0 && CheckMa ){ // ma is greater than ma2 and check is confirmed // Do your stuff here CheckMa = false; // don't forget to disable after your done }Code isn't checked or compiled
Sometimes you just stare at a problem so long you lose sight of the simple answers...LOL
Good point, I could just use a toggle that way!
Thank you!
if(Volume[0]>1) return;
Volume is unreliable (skipped ticks.) Bars is unreliable (stops changing at max bars in chart) Always use Time
static datetime Time0; bool newBar = Time0 < Time[0]; if (!newBar) return(0); Time0 = Time[0];
- every time ma - ma2 is greater then 0 this condition occurs, then resets and doesn't check again until ma - ma2 is less then 0?Alternative would be only trade when ma crosses ma2.
ma =iMA(NULL,0,7,0,MODE_SMA,PRICE_CLOSE,1); maPrev =iMA(NULL,0,7,0,MODE_SMA,PRICE_CLOSE,2); ma2 =iMA(NULL,0,25,0,MODE_SMA,PRICE_CLOSE,1); ma2Prev=iMA(NULL,0,25,0,MODE_SMA,PRICE_CLOSE,2); if (ma > ma2 && maPrev <= ma2Prev) { // Do your stuff here
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
Hi! So I am using what's below for buying or selling. It's a little messy because I am still experimenting, but I was wondering if anyone knew a way to program it so every time ma - ma2 is greater then 0 this condition occurs, then resets and doesn't check again until ma - ma2 is less then 0? If I can solve this issue the then i can finish the rest of my program!
Any help would be extremely appreciated!!!