1. Insert code properly, please.
2. Your code are big enough so It would be better if you attached your code.
3. Attach all includes too.
- 2010.02.25
- MetaQuotes Software Corp.
- www.mql5.com
1. Insert your code properly.
2. Your code are big enough so It would be better if you attached your code.
3. Attach all includes
There it is. Maybe I'm missing something....
Pat.
There it is. Maybe I'm missing something....
Pat.
Most likely execution doesn't reach the lines where you set new values for them, so they have values which they were assigned to them during declaration.
Are you sure that variables have their values assigned before?
Most likely execution doesn't reach the lines where you set new values for them, so they have values which they were assigned to them during declaration.
Well it works and returns the correct values when i attach the EA to a chart; but somehow the strategy tester doesn't run the function : Filter_swings() enterely, therefore the variables are not assigned any values.
Why would the strategy tester doesn't reach the lines of assignement ?
I even tried to insert the lines, where i assign the values, directly in the program (OnTick()), same result works well in normal execution but not in strategy tester. ??
Pat....
Well it works and returns the correct values when i attach the EA to a chart; but somehow the strategy tester doesn't run the function : Filter_swings() enterely, therefore the variables are not assigned any values.
Why would the strategy tester doesn't reach the lines of assignement ?
I even tried to insert the lines, where i assign the values, directly in the program (OnTick()), same result works well in normal execution but not in strategy tester. ??
Pat....
Yes. You are right.
It has been already fixed. Wait for updates.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello there,
I found an error with the strategy tester, which occurs only when testing. There are no error when operating live (demo).
It seems that the values of global variables are reset to 0 when exiting functions.
Below is the EA: The variables: Current_res & Current_sup have their values assigned when calling the function Filter_swings(); , with the next line I checked their values Alert(Current_res," ",Current_sup);
There are no error when the EA is attached to a chart, those variables return the correct values, but not with Strategy tester, here is a part of the log:
GN 0 Core 1 07:49:45 2010.07.01 00:00:12 Error
KO 0 Core 1 07:49:45 2010.07.01 00:00:12 0 0
EJ 0 Core 1 07:49:45 2010.07.01 01:00:00 Error
IS 0 Core 1 07:49:45 2010.07.01 01:00:00 0 0
PF 0 Core 1 07:49:45 2010.07.01 02:00:00 Error
DG 0 Core 1 07:49:45 2010.07.01 02:00:00 0 0
Thanks to look into it. Pat
Here is my EA:
//+------------------------------------------------------------------+
//| Tester.mq5 |
//| Copyright 2010, -----------------. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, ---------------------."
#property link "http://www.mql5.com"
#property version "1.00"
#include <PrintComment.mqh>
#include <SendOrder.mqh>
#include <ModifyPosition.mqh>
#include <ModifyOrder.mqh>
#include <CloseOrder.mqh>
#include <DeleteOrder.mqh>
input int Delta=10;
int ZigZaghandle;
double ZizZagbuffer[],ZizZagbufferhighs[],ZizZagbufferlows[];
double lows[5][2];
double highs[5][2];
double Current_res, Current_sup, stp, tgt;
int Pos_res, Pos_sup, delta;
bool newbar;
datetime time0[1];
static datetime oldtime;
string text;
MqlTick CurrentPrice;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
ZigZaghandle=iCustom(_Symbol,0,"Examples\\ZigZag",12,5,3);
if(ZigZaghandle==INVALID_HANDLE) Alert("Cannot call indicator");
ArraySetAsSeries(ZizZagbuffer,true);ArraySetAsSeries(ZizZagbufferhighs,true);ArraySetAsSeries(ZizZagbufferlows,true);
//---
delta=Delta;
if(_Digits==3 || _Digits==5) {delta=Delta*10;}
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
IndicatorRelease(ZigZaghandle);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- detect new bar
newbar=false;
int copied=CopyTime(_Symbol,PERIOD_H1,0,1,time0);
if(copied<0){StringConcatenate(text,"Error copying time0, #",GetLastError());PrintComment(text);ResetLastError();}
if(oldtime!=time0[0])
{
oldtime=time0[0];
newbar=true;
}
if(newbar==true)
{
Filter_swings();
Alert(Current_res," ",Current_sup);
if(PositionSelect(_Symbol)==0)
{
SymbolInfoTick(_Symbol,CurrentPrice);
if(CurrentPrice.ask > Current_res+delta*_Point && CurrentPrice.ask < Current_res+500*_Point)
{
stp=Current_sup;
tgt=Current_res+(Current_res-Current_sup);
SEND(_Symbol,"BUY",11111,0.2,CurrentPrice.ask,stp,tgt,"");
}
if(CurrentPrice.bid < Current_sup-delta*_Point && CurrentPrice.bid > Current_sup-500*_Point)
{
stp=Current_res;
tgt=Current_sup-(Current_res-Current_sup);
SEND(_Symbol,"SELL",22222,0.2,CurrentPrice.bid,stp,tgt,"");
}
}
}
}
//+------------------------------------------------------------------+
bool Filter_swings()
{
if(CopyBuffer(ZigZaghandle,0,0,Bars(_Symbol,0)-2,ZizZagbuffer)<0) {Alert("Error");ResetLastError();return(0);}
if(CopyBuffer(ZigZaghandle,1,0,Bars(_Symbol,0)-2,ZizZagbufferhighs)<0) {Alert("Error");ResetLastError();return(0);}
if(CopyBuffer(ZigZaghandle,2,0,Bars(_Symbol,0)-2,ZizZagbufferlows)<0) {Alert("Error");ResetLastError();return(0);}
int x; int l=0; int h=0;
for(x=0 ; x<100 ; x++)
{
if(ZizZagbufferhighs[x]!=0 && ZizZagbuffer[x]!=0) {if(h<5){highs[h][0]=x;highs[h][1]=ZizZagbufferhighs[x];h++;}}
if(ZizZagbufferlows[x]!=0 && ZizZagbuffer[x]!=0) {if(l<5){lows[l][0]=x;lows[l][1]=ZizZagbufferlows[x];l++;}}
if(h>=5 && l>=5)break;
}
//Searching for last resistance
for(x=0;x<5;x++)
{
if(highs[x][0]>4)
{
Current_res=highs[x][1];
Pos_res=highs[x][0];
break;
}
}
//Searching for last support
for(x=0;x<5;x++)
{
if(lows[x][0]>4)
{
Current_sup=lows[x][1];
Pos_sup=lows[x][0];
break;
}
}
//Alert("Res: ",Pos_res," ",Current_res," Sup: ",Pos_sup," ",Current_sup);
return(1);
}