EA didn't do anything this morning

 

My EA didn't create any pending orders this morning.

Kt ha sbeen working finr in the strategy tester. However, this morning nothing, no errors.

I have EAs enabled and live trading setup.

Any ideas?

Maybe I should change the hours, minutes, and seconds checks to just check the hour and minute and then return if any orders with magic order number 1 exist?


Some sample code:

double StartHour = 20;
   double EndHour = 7;
   if (DayOfYear()>=88) {StartHour=StartHour+1;EndHour=EndHour+1;} //IE monitoring 1900 to 0600, CET is always 1hr ahead apart from in summer when it's +2
   /////////////////////////////////////
  
   double diff = (EndHour-0)+(24-StartHour)+1;
   
   //5 decimal systems like Alpari
   if (Point==0.00001)
   {
      TradeTargetPrice=TradeTargetPrice*10;
      TradeStopLoss=TradeStopLoss*10;
      TrailingStop=TrailingStop*10;
      MovetoBreakEven=MovetoBreakEven*10;
   }

//////////////////////////////////////////////////////////
//It is now the start of the overnight monitoring, delete any existing pending orders
//////////////////////////////////////////////////////////
bool is_timetodelete=false;
if(Hour()==StartHour && Minute()==0 && Seconds()==0) {is_timetodelete = true; }

if (is_timetodelete == true)
{      
      int total = OrdersTotal();
      for(int i=total-1;i>=0;i--) //if no orders then it won't run through this again
      {
         OrderSelect(i, SELECT_BY_POS);
         int type   = OrderType();
         bool result = false;
         if(type>1)result = OrderDelete( OrderTicket() );
    
         if(result == false)
         {
            Alert("Order " , OrderTicket() , " Error:" , GetLastError() );
            Sleep(3000);
         }  
         
         actionedflag = 0;
         int movedflag=0;
      }
}

//////////////////////////////////////////////////////////
//It is now morning time so, set up the pending orders
//////////////////////////////////////////////////////////
bool is_timetocreatependingorders = false;
int ticket; 

if(Hour()==EndHour && Minute()==0 && Seconds()==0) 
{
   //If the pair is trending strongly then don't take the trade
   if (checktrending==true)
   {
      if(iADX(NULL,PERIOD_H4,14,PRICE_HIGH,MODE_MAIN,0) > checktrending_val) {return;}
      Print("Trending too great, no orders today");
   }
   
   is_timetocreatependingorders = true;
   double OvernightHigh = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,diff,0)];
   double OvernightLow = Low[iLowest(NULL,PERIOD_H1,MODE_LOW,diff,0)];  
   double HighTime = TimeHour(Time[iHighest(NULL,PERIOD_H1,MODE_HIGH,diff,0)]);
   double LowTime = TimeHour(Time[iLowest(NULL,PERIOD_H1,MODE_LOW,diff,0)]);  

   //Extra buffer for if price is too close to ask/bid, give it an extra 5
   if (MathAbs(OvernightHigh-Ask) <=0.0005) {BufferLong=BufferLong+0.005;}
   if (MathAbs(OvernightLow-Bid) <=0.0005) {BufferShort=BufferShort+0.005;}
   
   double LongSL = (OvernightHigh+BufferLong)-(TradeStopLoss*Point);
   double LongTP = (OvernightHigh+BufferLong)+(TradeTargetPrice*Point);
   double ShortSL = (OvernightLow-BufferShort)+(TradeStopLoss*Point);
   double ShortTP = (OvernightLow-BufferShort)-(TradeTargetPrice*Point);

   if (OrdersTotal() == 0 && is_timetocreatependingorders == true)
      {
         //LONG
         RefreshRates();
         ticket=OrderSend(Symbol(),OP_BUYSTOP,Lotsize,OvernightHigh+BufferLong,NULL,LongSL,LongTP,"LONG",1,0,Green);
      
         if(!ticket)
            {
               int errorCode = GetLastError();
               if(errorCode != ERR_NO_RESULT ) 
                  logError("OrderSend", "Error", errorCode);
            }
   
         //SHORT
         RefreshRates();
         ticket=OrderSend(Symbol(),OP_SELLSTOP,Lotsize,OvernightLow-BufferShort,NULL,ShortSL,ShortTP,"SHORT",1,0,Red);
   
         if(!ticket)
            {
               errorCode = GetLastError();
               if(errorCode != ERR_NO_RESULT ) 
                  logError("OrderSend", "Error", errorCode);
            }
      }
}
 

SM

You dont say what pair (I'd guess a euro cross from the logic and hours?)

Most likely cause is in here

//Extra buffer for if price is too close to ask/bid, give it an extra 5

Spread varies in live trading, especially when the market is quiet, so spread-sensitive trading (which in effect yours is here) will be affected and will not show one-to-one results with back-testing

So Bid and Ask can go in different directions with no net movement
Far greater Asian-session spread variation is seen on ECN-like brokers, see this page to work out a couple of them ;)

Even if spread doesnt vary much, it is often greater in live forward than backtesting, just a pip can make a trade happen in a test but not in live...

I'm not saying the approach above is wrong at all, just dont expect live trading to be 'as simple' as backtesting!

BTW - maybe the ADX on H4 is a bit... laggy for this?

Maybe H1 would be better, and/or StdDev M15?

FWIW

-BB-

 
BarrowBoy:

SM

You dont say what pair (I'd guess a euro cross from the logic and hours?)

Most likely cause is in here

//Extra buffer for if price is too close to ask/bid, give it an extra 5

Spread varies in live trading, especially when the market is quiet, so spread-sensitive trading (which in effect yours is here) will be affected and will not show one-to-one results with back-testing

So Bid and Ask can go in different directions with no net movement
Far greater Asian-session spread variation is seen on ECN-like brokers, see this page to work out a couple of them ;)

Even if spread doesnt vary much, it is often greater in live forward than backtesting, just a pip can make a trade happen in a test but not in live...

I'm not saying the approach above is wrong at all, just dont expect live trading to be 'as simple' as backtesting!

BTW - maybe the ADX on H4 is a bit... laggy for this?

Maybe H1 would be better, and/or StdDev M15?

FWIW

-BB-

It's GBPUSD but it's not the spread otherwise I would have got an error in the Journal. There are no errors.

Seems likely it didn't hit it's tick time?

 
It would be useful to put a few more Print() at strategic points so you know where it got up to, or not got up to. Which would cut down on the guessing.
 
blogzr3:
It would be useful to put a few more Print() at strategic points so you know where it got up to, or not got up to. Which would cut down on the guessing.

True, I'll do that but do you see a problem with this in live running:

if(Hour()==EndHour && Minute()==0 && Seconds()==0) 
 
SanMiguel:

True, I'll do that but do you see a problem with this in live running:

if(Hour()==EndHour && Minute()==0 && Seconds()==0) 

If within this second no tick arrives then your code in this if statement won't be executed.

 

I will rather write something like (checking that if you want this to end at midnight you may want to look at the day too). As said previously if the =EndHour is not executed your line will never be executed!


if(Hour()>=EndHour && Minute()==0 && Seconds()==0)
 
yona22:

I will rather write something like (checking that if you want this to end at midnight you may want to look at the day too). As said previously if the =EndHour is not executed your line will never be executed!


The end hour is always 2100GMT though.

So If I check the end hour and the minutes then it has 60 ticks where it will check that loop on each tick.

If I add the seconds and the price doesn't change for 3 seconds then no ticks come through - is that right?

Maybe I could check the hour only but add a flag? or check if magic number orders exist.

 

Working now but the journal says this:

2009.07.01 18:59:58 DLVBO GBPUSD,H1: creating orders

It was supposed to start at 1900.



?????

Reason: