I changed the Alert to Print so I could see it in the tester
There is NO CloseOrders
However, when the tester starts I get numerous line items in the journal which says this:
2011.09.01 20:03:24 TestGenerator: unmatched data error (volume limit 99 at 2011.08.25 20:15 exceeded)
I don’t recall it saying this before.
Anyhow here is the code now:
//---- input parameters
extern double TakeProfit=300.0;
extern double Lots=0.1;
extern double StopLoss=20.0;
extern int MagicNumber=12345;
//++++ These are adjusted for 5 digit brokers.
int pips2points; // slippage 3 pips 3=points 30=points
double pips2dbl; // Stoploss 15 pips 0.0015 0.00150
int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips)
// OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//±-----------------------------------------------------------------+
//| expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
if (Digits == 5 || Digits == 3)
{ // Adjust for five (5) digit brokers.
pips2dbl = Point*10; pips2points = 10; Digits.pips = 1;
}
else
{
pips2dbl = Point; pips2points = 1; Digits.pips = 0;
}
// OrderSend(… Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//----
//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if(line1>line2)current_direction = 1; //up //might need to add here for second macd agreement
if(line1<line2)current_direction = 2; //down
if(current_direction != last_direction) //changed
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
}
int Crossed_2 (double line1 , double line2) //i’ll use this later for macd agreement on 2 timeframes
{
static int last_direction_2 = 0;
static int current_direction_2 = 0;
if(line1>line2)current_direction_2 = 1; //up
if(line1<line2)current_direction_2 = 2; //down
if(current_direction_2 != last_direction_2) //changed
{
last_direction_2 = current_direction_2;
return (last_direction_2);
}
else
{
return (0);
}
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
//----
int cnt, ticket, total, mrmagic, pos, result;
double faster, slower, faster_2, slower_2;
if(Bars<100)
{
Print(“bars less than 100”);
return(0);
}
if(TakeProfit<10)
{
Print(“TakeProfit less than 10”);
return(0); // check TakeProfit
}
faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1); //MODE_MAIN
slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL
faster_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_MAIN,1); //MODE_MAIN
slower_2 = iMACD(NULL,PERIOD_H4,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL
int isCrossed = Crossed (faster,slower);
int isCrossed_2 = Crossed_2 (faster_2,slower_2); // i’ll use this later for macd agreement on separate timeframes
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1){ // I want to add && isCrossed_2 == 1) but 0 trades occur with the note below
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3pips2points,Ask-StopLosspips2dbl,Ask+TakeProfitpips2dbl,“Agent86”,12345,0,Green);
if(ticket>0){
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
}
if(isCrossed == 2){ // I want to add && isCrossed_2 == 2) but 0 trades occur with the note above
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3pips2points,Bid+StopLosspips2dbl,Bid-TakeProfitpips2dbl,“Agent86”,12345,0,Red);
if(ticket>0){
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
}
for(cnt=0; cnt<total; cnt++){
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()== Symbol()){
if(OrderType()==OP_BUY
&& isCrossed == 2)
result = OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
if(result == false){
Print(“Order”,OrderTicket(),“failed to close Error”,GetLastError());
return(0);
}
if(OrderType()== OP_SELL
&& isCrossed == 1)
result = OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
if(result == false){
Print("Order",OrderTicket(),"failed to close Error",GetLastError());
return(0); // exit
}
}
}
}
return(0);
}
//±-----------------------------------------------------------------+[/QUOTE]