Expert Advisor not returning any results in Strategy Tester | MT4

 

Hi lovely community :)

I'm having some issues with Strategy Tester and really need a hand.

I did have a look around and I've tried a few solutions but to no avail.


When I run a EA that I've made I get no results at all. Completely blank. I'm trying to figure out where I'm going wrong. I've check everything obvious;

the code does definitely work and should be buying, I've downloaded data using history center, could it be because I'm using OrderSend?


Am I missing something? What are the requirements of code that works with the strategy tester that I could have missed?


Thanks so much in advance. I'm fairly new to this and of course backtesting is something I really need to work...


Charlie

 

You have probably started an optimization. Either there weren't any runs at all, or the results were all zero or below.

Right-click on the optimization results and uncheck the setting to skip useless results.



If you didn't intend to run an optimization, uncheck the Optimization checkbox in the tester's Settings dialogue.

 
lippmaje:

You have probably started an optimization. Either there weren't any runs at all, or the results were all zero or below.

Right-click on the optimization results and uncheck the setting to skip useless results.



If you didn't intend to run an optimization, uncheck the Optimization checkbox in the tester's Settings dialogue.

Thanks for your response - I can see in ST that optimisation isn't ticked 


Charlie

Files:
ST.PNG  19 kb
 
charlie.cooper:

Hi lovely community :)

I'm having some issues with Strategy Tester and really need a hand.

I did have a look around and I've tried a few solutions but to no avail.


When I run a EA that I've made I get no results at all. Completely blank. I'm trying to figure out where I'm going wrong. I've check everything obvious;

the code does definitely work and should be buying, I've downloaded data using history center, could it be because I'm using OrderSend?


Am I missing something? What are the requirements of code that works with the strategy tester that I could have missed?


Thanks so much in advance. I'm fairly new to this and of course backtesting is something I really need to work...


Charlie

How do you know your code work? did you test it on demo account and watched it taken some trades? If you didn't do 'this optimization' mistake you might want to start looking at your code once again and check your OrderSend() functions ....or even better, post the code here and maybe someone in the forum helps you out finding the problem for you

 
Kenneth Parling:

How do you know your code work? did you test it on demo account and watched it taken some trades? If you didn't do 'this optimization' mistake you might want to start looking at your code once again and check your OrderSend() functions ....or even better, post the code here and maybe in the forum helps you out finding the problem for you

That's a good shout - at this stage I dont want to use it with my demo account because it's not finished,

I have been using comments as a way to debug and check functions are working because all I want to do right now is test with a takeprofit instead of programming a sell which I will do eventually.


The OrderSend is programmed as follows:

int ticket=OrderSend(Symbol(),OP_BUYSTOP,0.1,Ask,3,10,Ask+TakeProfit,"Hammer",1,0,Green);

Thanks for your assistance

Charlie

 
charlie.cooper:

That's a good shout - at this stage I dont want to use it with my demo account because it's not finished,

I have been using comments as a way to debug and check functions are working because all I want to do right now is test with a takeprofit instead of programming a sell which I will do eventually.


The OrderSend is programmed as follows:

Thanks for your assistance

Charlie

For your buy stop you need a distance from price set, else it wont work and also check stop loss and take profit


input int Distance = XXX;
input int TakeProfit = XXX;
input int StopLoss =XXX;
//--
double _price,_stop,_take;
//--
_price = Ask + Distance * Point;
_stop  = _price - StopLoss * Point;
_take  = _price + TakeProfit * Point;
//--
int ticket=OrderSend(Symbol(),OP_BUYSTOP,0.1,_price,3,_stop,_take,"Hammer",1,0,Green);
 
_price = Ask + Distance * Point;
_stop  = _price - StopLoss * Point;
_take  = _price + TakeProfit * Point;
You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer. Don't you want the same/specified amount for either direction?
  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)
 

Hi - Thanks for your help.

There was a few issues going on at once...

The first, which was revealed buy using GetLastError, was that auto trading was disabled. I didn't realise it had an impact on strategy tester, maybe that was dumb but I thought they were separate.

After I fixed that I started getting error #130, which means you were bang on. 


I made some fixes based on what you said but they're not working; this is still returning Error #130

OrderSend(Symbol(),OP_BUYSTOP, 0.1,Ask,3,Bid-StopLoss*Point,Bid+TakeProfit*Point);

SL & TP set to: 20

I feel like I'm really close - What am I doing wrong?


Thanks again all for the wise words :)

 
charlie.cooper:

Hi - Thanks for your help.

There was a few issues going on at once...

The first, which was revealed buy using GetLastError, was that auto trading was disabled. I didn't realise it had an impact on strategy tester, maybe that was dumb but I thought they were separate.

After I fixed that I started getting error #130, which means you were bang on. 


I made some fixes based on what you said but they're not working; this is still returning Error #130

SL & TP set to: 20

I feel like I'm really close - What am I doing wrong?


Thanks again all for the wise words :)

Hello, i also faced the same issue.. did many research but nothing on the net helps me.

i tried playing with the coding and finally solved the problem

extern int    TakeProfit = 50;
extern int    StopLoss = 50;

//Global Variable
int SLevel;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
   SLevel =( int ) MathMax(MarketInfo( Symbol(), MODE_FREEZELEVEL )+MarketInfo(Symbol(), MODE_SPREAD), MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD));

return ( 0 );
}
//+------------------------------------------------------------------+
//| Expert Start Function                                            |
//+------------------------------------------------------------------+
int start() {  
   double askPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
   double bidPrice = SymbolInfoDouble(Symbol(),SYMBOL_BID);
   double SL,TP,BTP=0,STP=0,BSL=0,SSL=0;

//buy
   if(TakeProfit>0)BTP =askPrice + TakeProfit * Point;
   else
   if(TakeProfit < SLevel) TP = SLevel + BTP;
   RefreshRates();
   if(StopLoss>0)BSL = bidPrice - StopLoss * Point;
   else
   if(StopLoss < SLevel) SL = SLevel- BSL;
   RefreshRates();
//sell
   if(TakeProfit>0)STP =bidPrice - TakeProfit * Point;
   else
   if(TakeProfit < SLevel) TP = SLevel- STP;
   RefreshRates();
   if(StopLoss>0)SSL = askPrice + StopLoss * Point;
   else
   if(StopLoss < SLevel) SL = SLevel+ SSL;
   RefreshRates();
//order buy
ticket = OrderSend( Symbol(), OP_BUYSTOP, lotSize(), Ask + ( totalBuyStop + 1.0 ) * ( Point * Flex_L ), Slippage,BSL,BTP,"",OrderID,0,Blue);

//order sell
ticket = OrderSend(Symbol(), OP_SELLSTOP, lotSize(), Bid - ( totalSellStop + 1.0 ) * ( Point * Flex_L ), Slippage,SSL,STP,"",OrderID,0,Red);


you will never get error 130 again

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors
  • www.mql5.com
Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors - Reference on algorithmic/automated trading language for MetaTrader 5
 
Abubakar Saidu:

Hello, i also faced the same issue.. did many research but nothing on the net helps me.

i tried playing with the coding and finally solved the problem

you will never get error 130 again

Thanks - I will give this a try!

Please can you explain how it works - What is SLevel and how will affect the way my trades are executed?


:)

 
charlie.cooper:

Thanks - I will give this a try!

Please can you explain how it works - What is SLevel and how will affect the way my trades are executed?


:)

Slevel= brokers stoplevel+freeze+spreads

if you use 10 points as stoploss and the stoplevel or spread is 30+

then the stoploss will be placed after the stoplevel or spread

spreads=20+stoploss10

or

stoplevel=30+stoploss10

Reason: