View Single Post
Unexpected result in Strategy Tester
  #1 (permalink)  
Old 08-23-2007, 09:01 PM
Alvo Alvo is offline
Freshman
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Alvo is on a distinguished road
Default Unexpected result in Strategy Tester

Hi,

I'm just starting to learn MQL4.

I want to make the classic example of looking for EMA crosses:

Code:
//+------------------------------------------------------------------+ //| cross_alert.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" //---- input parameters extern int ShortPeriod=5; extern int LongPeriod=10; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- double MA_short_cur=iMA(Symbol(),0,ShortPeriod,0,MODE_EMA,PRICE_CLOSE,0); double MA_long_cur=iMA(Symbol(),0,LongPeriod,0,MODE_EMA,PRICE_CLOSE,0); double MA_short_prev=iMA(Symbol(),0,ShortPeriod,0,MODE_EMA,PRICE_CLOSE,1); double MA_long_prev=iMA(Symbol(),0,LongPeriod,0,MODE_EMA,PRICE_CLOSE,1); // check cross up if (MA_short_prev<MA_long_prev && MA_short_cur>MA_long_cur) { Print("Cross UP"); } // check cross down if (MA_short_prev>MA_long_prev && MA_short_cur<MA_long_cur) { Print("Cross DOWN"); } //---- return(0); } //+------------------------------------------------------------------+
I run it on GBPUSD on the daily chart and it detects the crosses well but the output in the Journal tab is pretty weird. For example there is a cross on 2007.07.27 and this is what I see in the Journal (it is the same at any other cross as well):

Code:
2007.08.23 22:04:04 2007.07.27 23:59 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 22:40 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 22:00 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 21:20 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 20:40 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 20:00 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 19:59 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 18:40 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 18:00 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 17:20 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 16:40 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 16:00 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 15:59 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 14:40 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 14:00 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 13:20 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 12:00 cross_alert GBPUSD,Daily: Cross DOWN 2007.08.23 22:04:04 2007.07.27 10:00 cross_alert GBPUSD,Daily: Cross DOWN
I have no intention to use this code to execute any order but if I did would it execute 18 orders???

How can I fix this to have only one single entry for each cross?

Thanks for your help!

Alvo
Reply With Quote
ProFX Powerful Trading System

Registered members have access to special online forex currency trading tools, software, mt4 expert advisors and indicators. Register now

Main Menu

Economic Forecast