Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.
NB! Very important! DO NOT create a new post. EDIT your original post.
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. - Unmatched data errors have nothing to do with your code. You need to download all timeframes below your test timeframe. Next time, use this.
this code won't place any orders as an expert advisor in the mt4 strategy tester and it's returning the following error in the journal, i don't know what the problem can be, can someone help?
error: "TestGenerator: unmatched data error (volume limit 2431 at 2023.01.26 13:00 exceeded)"
bool isDowntrend21MA() { if (iMA(NULL,NULL,21,0,MODE_SMA,PRICE_CLOSE,0) < iMA(NULL,NULL,21,0,MODE_SMA,PRICE_CLOSE,10)) return true; else return false; } bool isUptrend21MA() { if (iMA(NULL,NULL,21,0,MODE_SMA,PRICE_CLOSE,0) > iMA(NULL,NULL,21,0,MODE_SMA,PRICE_CLOSE,10)) return true; else return false; } void OnTick() { if(Bid==iMA(NULL,NULL,200,0,MODE_SMMA,PRICE_CLOSE,0) && iClose(NULL,NULL,2) isUptrend21MA()) {int ticketbuy1 = OrderSend(NULL,OP_BUY,0.1,Ask,1,Bid-0.0005,Ask+0.0005,NULL,0,0,clrLimeGreen);} if(Bid==iMA(NULL,NULL,200,0,MODE_SMMA,PRICE_CLOSE,0) && iClose(NULL,NULL,2)>iMA(NULL,NULL,200,0,MODE_SMMA,PRICE_CLOSE,0) && isDowntrend21MA()) {int ticketsell1 = OrderSend(NULL,OP_SELL,0.1,Bid,1,Ask+0.0005,Bid-0.0005,NULL,0,0,clrRed);} }probably not a good strategy so i don't suggest anyone uses it even if it seems to work in the strategy tester after any problems have been solved. just trying to learn mql4
That is not the error actually , consult the attached code .
You had 2 boolean functions without a result and it worked so i assume your #property strict was missing , and also the Bid being equal to the SMMA200 is very rare 😊
Other than that you were some tweaks away
#property strict int OnInit() { return(INIT_SUCCEEDED); } bool isDowntrend21MA() { if(iMA(NULL,NULL,21,0,MODE_SMA,PRICE_CLOSE,0)<iMA(NULL,NULL,21,0,MODE_SMA,PRICE_CLOSE,10)) return true; return false; } bool isUptrend21MA() { if(iMA(NULL,NULL,21,0,MODE_SMA,PRICE_CLOSE,0)>iMA(NULL,NULL,21,0,MODE_SMA,PRICE_CLOSE,10)) return true; return false; } /* if(Bid==iMA(NULL,NULL,200,0,MODE_SMMA,PRICE_CLOSE,0) this is actually very rare , but if you change it it will trade on every tick :) So you can do it in a slightly different way You can maintain a variable with the alignment of the price to the SMMA 200 for instance , let's take a small variable type the char. Let's call it "TheCompass" In coding you can make your own rules so ,you can do whatever you want so we will say that the compass is 0 if its sitting on the SMMA 200 is 1 if its above the SMMA 200 is -1 if its below the SMMA 200 is -2 if its not set yet So the compass , default value -2 */ char TheCompass=-2; /* and another value to remember the previous alignment */ char previousCompass=-2; void OnTick() { /* so now the first thing you do is manage the compass You get the price for the 200 smma once */ double smma200=iMA(NULL,NULL,200,0,MODE_SMMA,PRICE_CLOSE,0); /* and you enforce your rule but before you do that you get a snapshot of the compass just to remember its previous state You only store it if its not zero , you will see why */ //if the compass is not zero , set the value as the compass , otherwise keep the previous value previousCompass=(TheCompass!=0)?TheCompass:previousCompass; //if above if(Bid>smma200){TheCompass=1;} else if(Bid==smma200){TheCompass=0;} else if(Bid<smma200){TheCompass=-1;} //if one of the 3 ifs above fires it will ignore the other 2 /* now you know the current alignment to the smma200 (TheCompass) and the previous alignment (previousCompass) So your signal becomes : Cross above , the compass is 1 (above) and the previous compass is -1 (thats why we ignore 0) */ if(TheCompass==1&&previousCompass==-1){ //buy if uptrend if(isUptrend21MA()){ int ticketbuy1 = OrderSend(NULL,OP_BUY,0.1,Ask,1,Bid-0.0005,Ask+0.0005,NULL,0,0,clrLimeGreen); } } //cross below , the compass is -1 (below) and the previous compass is 1 if(TheCompass==-1&&previousCompass==1){ //sell if downtrend if(isDowntrend21MA()){ int ticketsell1 = OrderSend(NULL,OP_SELL,0.1,Bid,1,Ask+0.0005,Bid-0.0005,NULL,0,0,clrRed); } } //Let's print the compasses to keep an eye on the system Comment("Compass : "+IntegerToString(TheCompass)+"\nPrevious : "+IntegerToString(previousCompass)); }
Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.
NB! Very important! DO NOT create a new post. EDIT your original post.
thank you sm! fixed it
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. - Unmatched data errors have nothing to do with your code. You need to download all timeframes below your test timeframe. Next time, use this.
That is not the error actually , consult the attached code .
You had 2 boolean functions without a result and it worked so i assume your #property strict was missing , and also the Bid being equal to the SMMA200 is very rare 😊
Other than that you were some tweaks away
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
this code won't place any orders as an expert advisor in the mt4 strategy tester and it's returning the following error in the journal, i don't know what the problem can be, can someone help?
error: "TestGenerator: unmatched data error (volume limit 2431 at 2023.01.26 13:00 exceeded)"
probably not a good strategy so i don't suggest anyone uses it even if it seems to work in the strategy tester after any problems have been solved. just trying to learn mql4