(ask) how to 1 trade only per day

 

hi i am having a difficulty on code this,

option 1 :

it trade

if (Eq == -1) Eq = AccountEquity();

if (AccountEquity()>= (Over*XFactor)+Eq ){
for(int TO=OrdersTotal()-1;TO>=0;TO--)
{
OrderSelect(TO,SELECT_BY_POS);
deleteAgain();

Eq = AccountEquity();
}} else

if (AccountEquity()<= Eq-(Under*XFactor) ){
for(int eq=OrdersTotal()-1;eq>=0;eq--)
{
OrderSelect(eq,SELECT_BY_POS);
deleteAgain();

Eq = AccountEquity();
}} else

{

if (TotalOrders()==0){
if (Hour()>=1 && Hour()<2) ......... only trade in hour =1

{

if (Minute()>=0 && Minute()<4) ......... only trade in minute 0-3 ......................so on 01:00 to 01:03

{

RefreshRates();
ask=MarketInfo(Symbol(),MODE_ASK);
bid=MarketInfo(Symbol(),MODE_BID);
double priceS=NormalizeDouble(bid,Digits);
double priceB=NormalizeDouble(ask,Digits);

//....................Middle.....................................

// v end order 0, dont delete this
}}}

all i want is ONLY 1 trade per day and continue tomorrow

but in the proses it trade 2-3 per trade in that range time.


Option 2 :

i used

if (TotalMOrders()==0&& OrdersHistoryTotal()==0)
{
{
RefreshRates();
ask=MarketInfo(Symbol(),MODE_ASK);
bid=MarketInfo(Symbol(),MODE_BID);
double price=NormalizeDouble(ask,Digits);
double priceS=NormalizeDouble(bid,Digits);

//....................Middle.....................................

}}


the trade is 1, great, but it doesn't trade again tomorrow.

sorry for the long code.

what should i do? help is greatly needed


thank you

E

 
kieruwin:

how to 1 trade only per day


  1. int start(){
       bool openNew = ... // decide
       static datetime delay;
       if (openNew && TimeCurrent() > delay){
          int ticket = OrderSend(...);
          if (ticket < 0) Alert("OrderSend failed: ", GetLastError());
          else{
             datetime now = TimeCurrent(),     // 86400=24*60*60
                      bod = now - now % 86400; // Beginning of the day
                      tom = bod + 86400;       // Tomorrow
              delay = tom;
             // If you want a 24 hour delay, not once per day, use:
             // delay = now + 86400;
          }
       }
    }

  2. if (TotalOrders()==0){
    This makes the EA incompatible with another EA (including itself on other charts) and manual trading.
    int count=0;
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol() ){              // and my pair.
            count++;
        }
    if (count == 0 ...
 

thanks for fast response WHRoeder, i will try it on my EA.

thank you.

E

Reason: