Download MetaTrader 5

My EA is just trading some days, why could it be?

To add comments, please log in or register
Henry Latourrette
6466
Henry Latourrette  

I have an EA trading on the Daily time frame, however, somedays - like today - it doesn't trade and I don't know why.

I tried to solve it by taking out the following part of the code:

--------- 

//--- go trading only for first tiks of new bar

   if(Volume[0]>1) return;

 --------------

 But it started to open new Stop Orders on each tick. How do I make sure it opens a stop order each day. I mean, that's the objective of the EA, to open Stop Orders each day according the the trend direction.

Thanks in advanced! 

Stuart Browne
6043
Stuart Browne  

If you only want to open a new order when a new bar appears then it's best not to do it by volume. The volume is too unpredictable. And the way that code is written, if the first tick has a volume > 1 (which is possible) then it won't trade at all. If you remove that line completely then it will trade on every single tick (as you have discovered).

It would be better to have either a static or a global variable that holds the time of the last bar, compares the time of bar 0 and if it's greater, then you're on a new bar. So something like:

Nikolaos Pantzos
12419
Nikolaos Pantzos  
henlatourrette:

I have an EA trading on the Daily time frame, however, somedays - like today - it doesn't trade and I don't know why.

I tried to solve it by taking out the following part of the code:

--------- 

//--- go trading only for first tiks of new bar

   if(Volume[0]>1) return;

 --------------

 But it started to open new Stop Orders on each tick. How do I make sure it opens a stop order each day. I mean, that's the objective of the EA, to open Stop Orders each day according the the trend direction.

Thanks in advanced! 

You can to try this

int TradeBar=0;

int OpenTicketNo=0; 

 

void OnTick()

{

if(TradeBar==iBars(Symbol(),PERIOD_D1)) return;

.............................................. 

OpenTicketNo=OrderSend( ......................... )

if(OpenTicketNo>0) TradeBar=iBars(Symbol(),PERIOD_D1);

...........................................


Pasi Hakamaki
5493
Pasi Hakamaki  
henlatourrette:

I have an EA trading on the Daily time frame, however, somedays - like today - it doesn't trade and I don't know why.

I tried to solve it by taking out the following part of the code:

--------- 

//--- go trading only for first tiks of new bar

   if(Volume[0]>1) return;

 --------------

 But it started to open new Stop Orders on each tick. How do I make sure it opens a stop order each day. I mean, that's the objective of the EA, to open Stop Orders each day according the the trend direction.

Thanks in advanced! 

One option is to use the CIsNewBar class here and only trade when it returns true.

Hope it helps, good luck!

Henry Latourrette
6466
Henry Latourrette  

Thank you guys. I appreciate your feedback. I tried to code by the different methods you mentioned but I couldn't make it work properly, perhaps I didn't do something correctly.

 However, I kept looking on the forums and I found the following code which worked fine on backtestings:

//-------------- define variable

datetime now;

//--------------- Check for open order conditions   

void CheckForOpen()

if( now != Time[0] )

   {

   now = Time[0];

//--- sell conditions

   if(Open[0]<ma)

     {

      StopLoss=(Bid-400*Point);

      TakeProfit=(Bid-2000*Point);

      OrderSend(.................);

      return;

     } 

  } 

///////// etc... 

 

Now I'm about to test it in live demo trading, too bad it's Friday night already so I'll have to wait 'till the market opens on Monday. I'll try to share wether it works or not.

Thanks! 

Henry Latourrette
6466
Henry Latourrette  
henlatourrette:

Thank you guys. I appreciate your feedback. I tried to code by the different methods you mentioned but I couldn't make it work properly, perhaps I didn't do something correctly.

 However, I kept looking on the forums and I found the following code which worked fine on backtestings:

//-------------- define variable

datetime now;

//--------------- Check for open order conditions   

void CheckForOpen()

if( now != Time[0] )

   {

   now = Time[0];

//--- sell conditions

   if(Open[0]<ma)

     {

      StopLoss=(Bid-400*Point);

      TakeProfit=(Bid-2000*Point);

      OrderSend(.................);

      return;

     } 

  } 

///////// etc... 

 

Now I'm about to test it in live demo trading, too bad it's Friday night already so I'll have to wait 'till the market opens on Monday. I'll try to share wether it works or not.

Thanks! 

Hi everyone... just for the records, it is Friday again and my EA traded the whole week without a problem, this piece of code actually solved the problem:

 

datetime now;

if( now != Time[0] )

   {

   now = Time[0]; 

To add comments, please log in or register