Strategy Tester MT4

 

Please refer me to a link for an existing EA that will let me enter a buy or sell with a take profit and a stop loss. Nothing more. No method required. I just need to run on the Tester with different history periods, different currency pairs, different lots.

Thanks,

 
boristabby5:

Please refer me to a link for an existing EA that will let me enter a buy or sell with a take profit and a stop loss. Nothing more. No method required. I just need to run on the Tester with different history periods, different currency pairs, different lots.

Thanks,

What you have asked for is probably actually harder than a normal EA. How are you planning on entering the order in the strategy tester?

It would be easy to enter the order as soon as the test starts with a long or short value set by an extern variable, but entering a trade manually during a test is harder. Perhaps reading a keypress?

 
dabbler:

What you have asked for is probably actually harder than a normal EA. How are you planning on entering the order in the strategy tester?

It would be easy to enter the order as soon as the test starts with a long or short value set by an extern variable, but entering a trade manually during a test is harder. Perhaps reading a keypress?


Hi Dabbler, I am thinking of an EA with parameters: Buy = True or false, Sell = True or false, TakeProfit = XXXX, StopLoss = XXXX, Lots = XXXX.

The Strategy Tester itself calls for a Symbol (currency pair), a Period, a Model (ticks or control points or open prices), and a date range of history prices.

My sense of this usage is that the Trade would be opened at the start and just run until either the TakeProfit or the StopLoss value is hit. I need to get a feel for long trends as a trading method instead of the Reversal method that my own EA now uses. I would select at least a week for the Period or more likely, a month. The EA would not enter more than one trade per test run.

As you know, clicking on Expert Properties brings up the Testing and Inputs tabs for account amount/currency, and for entering the parameters (above) to be used when the Tester starts.

The end date of the Period would stop the Tester when reached if neither the T/P or the S/L is hit before the end. Kind of open ended trade. Simple when trading live, but how to do it with the Tester? Only an EA can run on the Tester?

 
boristabby5:


Hi Dabbler, I am thinking of an EA with parameters: Buy = True or false, Sell = True or false, TakeProfit = XXXX, StopLoss = XXXX, Lots = XXXX.

The Strategy Tester itself calls for a Symbol (currency pair), a Period, a Model (ticks or control points or open prices), and a date range of history prices.

My sense of this usage is that the Trade would be opened at the start and just run until either the TakeProfit or the StopLoss value is hit. I need to get a feel for long trends as a trading method instead of the Reversal method that my own EA now uses. I would select at least a week for the Period or more likely, a month.

Highest timeframe you can test with the Strategy Tester is D1
 

I am, I think, confusing the Chart Time frame, with the History price time range. Coincidently, I run my Reversal EA on a daily chart, but the test will run during any date range so long as the end date of the History price range is not reached (or it runs out of margin).

Thanks for the heads-up, Raptor.

 

Try this ...

#include <WinUser32.mqh>

extern string _="These values are in points";
extern int stopLoss=1000;
extern int takeProfit = 1000;

extern string __="Use 0 for SHORT and 1 for LONG";
extern int direction=0;

#define LOTSIZE 0.1

bool started = false;
bool stopTrading= false;

//------------------------------------------------------------------------
int init(){

   if( direction != 0 && direction != 1 ){
      stopTrading=true;
      Print( "** RTFM ** . Set direction correctly" );
   }
   
   if( stopLoss < 20 || takeProfit < 20 ){
      stopTrading=true;
      Print( "Give me a break. Set a sensible stopLoss or takeProfit" );
   }
   
   return(0);
}
//------------------------------------------------------------------------
int start(){
   if( stopTrading )
      return(0);

   if( OrdersTotal()==0 ){
      if( started ){
         //job done
         stopTrading= true;
         return( 0 );
      }
      
      int ticket=-1;
      if( direction==0 )  // SHORT position requested
         ticket= OrderSend( Symbol(), OP_SELL, LOTSIZE, Bid, 10, Bid+stopLoss*Point, Bid-takeProfit*Point );
      else                // LONG position requested
         ticket= OrderSend( Symbol(), OP_BUY, LOTSIZE, Ask, 10, Ask-stopLoss*Point, Ask+takeProfit*Point );
      
      if( ticket < 0 ){
         Print("Trade failed: Error Code " + GetLastError() );
         stopTrading=true;
         return( 0 );
      }
       
      started=true;
   }

   return(0);
}
Reason: