trade only one time a day - page 2

 
GumRai:

deVries,

that is excellent. I see what you mean, that closed trades only have to be scanned in init.

Just a couple of points. If an OrderSelect fails, the code will exit the loop and will discontinue the checking.

I must admit, that I am pretty useless at error handling and often see in peoples code

if(OrderSelect() ) but usually this error is ignored and continues with the next order position. I really don't know what to do when OrderSelect() fails as I would be concerned that simply restarting the loop would repeat the failure and the program will be stuck.

That can't be good, but then again, exiting the loop or just using the data from the loop when OrderSelect() doesn't fail can't be particularly good either.

The other point

Unlikely, I know, but it is possible that at the same time that the EA is opening a trade a different trade is being closed.

That would mean that at the next tick, EATrades would still == OrdersTotal(), so opentimelastmarket would not be updated and another trade will be opened.

Would it be a good idea to check that the OrderSend is successful and if it is, then update opentimelastmarket there?

that is a point if you go further explaining how to do

it can be done checking with ticket = Ordersend(.... checking ticket >0

but you can also make EATrades a size you never will have after opening a trade and check next tick your Trades

  if(Open[0] > 1.35)OrderSend(Symbol(),OP_BUY,0.1,Ask,Slippage.Pips * pips2points,0,0,"ExampleTwoBuy",MagicNumber,0,Blue);
  if(Open[0] < 1.35)OrderSend(Symbol(),OP_SELL,0.1,Bid,Slippage.Pips * pips2points,0,0,"ExampleTwoSell",MagicNumber,0,Red);

  EATrades = 10000;
   
//----
   return(0);

i don't think someone will have so much trades open then EATrades != OrdersTotal()

 
deVries:

that is a point if you go further explaining how to do

it can be done checking with ticket = Ordersend(.... checking ticket >0

but you can also make EATrades a size you never will have after opening a trade and check next tick your Trades

i don't think someone will have so much trades open then EATrades != OrdersTotal()


Then I don't see the point of having EATrades != OrdersTotal() as a condition if you make sure that it will always be true.

How about

int start()
  {
  now = Time[0];
  bod = now - now % 86400;  // Beginning of the day  
  static datetime opentimelastmarket = 0;  
  
//----
  if(opentimelastmarket >= bod)return(0);
    
    BUYTrades = 0;
    SELLTrades = 0;
    for(int i= OrdersTotal()-1; i>=0 ; i--) //count down if you check trades !!!
        {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)break;
        if(OrderSymbol()!=Symbol() ||OrderMagicNumber()!= MagicNumber ||OrderType()>1) continue;
        if(OrderOpenTime() > opentimelastmarket)opentimelastmarket = OrderOpenTime();
        if(OrderType()==OP_BUY)
          {
          BUYTrades++;         
          }
        if(OrderType()==OP_SELL)
          {
          SELLTrades++;
          }    
        } 
      
//---- end closing check open trades
   Comment("BUYTRADES  ",BUYTrades,"    SELLTRADES  ",SELLTrades);
   //if(opentimelastmarket >= Time[0])return(0); //one time each Bar
   if(opentimelastmarket >= bod)return(0);       //one time each Day

   if(Open[0] > 1.35)
     {
     int ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,Slippage.Pips * pips2points,0,0,"ExampleTwoBuy",MagicNumber,0,Blue);
     if( ticket>0)
       {
       if(OrderSelect(ticket,SELECT_BY_TICKET) )
         opentimelastmarket=OrderOpenTime();
       }
     }
   if(Open[0] < 1.35)
     {
     ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,Slippage.Pips * pips2points,0,0,"ExampleTwoSell",MagicNumber,0,Red);
     if( ticket>0)
       {
       if(OrderSelect(ticket,SELECT_BY_TICKET) )
         opentimelastmarket=OrderOpenTime();
       }
     }


   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
GumRai:


Then I don't see the point of having EATrades != OrdersTotal() as a condition if you make sure that it will always be true.

How about


I use the orderloop also for trailing, setting sl,tp, and orderclose while i run the loop

a condition for checking opentrades is for me when the OrdersTotal() is changing

with placing

if(opentimelastmarket >= bod)return(0);

before the loop you can't do it inside this loop

 
GumRai and deVries,both of your advices are very helpful,I modified my EA and it works well. Thanks
 

Hello Everybody...

could someone help me ? I d like to add a feature on this EA.

Could it be possible to choose a particular day to trade... For example, On monday/tuesday/... 

Hope tmy message is clear... :) 

Files:
 
selgtrader:

Hello Everybody...

could someone help me ? I d like to add a feature on this EA.

Could it be possible to choose a particular day to trade... For example, On monday/tuesday/... 

Hope tmy message is clear... :) 

Yes. You can check day using DayOfWeek() function.

Returns the current zero-based day of the week (0-Sunday,1,2,3,4,5,6) of the last known server time.

 
selgtrader:

Hello Everybody...

could someone help me ? I d like to add a feature on this EA.

Could it be possible to choose a particular day to trade... For example, On monday/tuesday/... 

Hope tmy message is clear... :) 

make a simple bool function to check if it's ok to trade on a certain weekday

extern bool mon = true;
extern bool tue = true;
extern bool wed = true;
extern bool thu = true;
extern bool fri = true;

//---
void OnTick()
  {
   if(Checkday)
     {
      //...do your stuff here
     }
   return;
  }
//++++++++++++++++++++++++++++
bool CheckDay()
  {
   if(mon&&DayOfWeek()==1)
      return(true);
   if(tue&&DayOfWeek()==2)
      return(true);
   if(wed&&DayOfWeek()==3)
      return(true);
   if(thu&&DayOfWeek()==4)
      return(true);
   if(fri&&DayOfWeek()==5)
      return(true);
   return(false);
  }
//+------------------------------------------------------------------+

 

Thank you so much for your reply..

You know I dont know how to code... :( 

could someone integrate this into the code ? I would be very thankful... :)

Have nice trades !!

:)

Reason: