Help a newbie - Day and Time functions - page 3

 

Sorry abstract_mind


The format of the code doesn't show it the right way in here as you described above.

 
EagleEye:

So how should the code look like?

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()

// oneliner start
bool sunday_cond = (TimeDayOfWeek(TimeCurrent())==0) && (Hour()>=23);
bool monday_cond = (TimeDayOfWeek(TimeCurrent())==1) && (Hour()<=15);
bool mytradeallowed = false;
if   (
       (OrdersTotal()==0)
        &&
       (sunday_cond || monday_cond )
     )
      {
       mytradeallowed = true;  
      }


if (Bars<100 || IsTradeAllowed()==false || mytradeallowed==false){ return;}
// oneliner end

if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();

try this. i hope i haevnt missed something late at night.

i know that the conditions can be packed in one line, but i wanted to let the other members also do some posts LOL

indeed in this way (more separate lines) it its more understandable, at least for a newbie.

// oneliner start
if (
     (Bars<100 || IsTradeAllowed()==false)
     || 
     (
      ( 
       (TimeDayOfWeek(TimeCurrent())==0) && (Hour()>=23)
       ||
       (TimeDayOfWeek(TimeCurrent())==1) && (Hour()<=15)
      )
      (OrdersTotal()==0)  
     )
    ) 
   { return;}
// oneliner end

//now in one line, i coulndt resist LOL
if ((Bars<100 || IsTradeAllowed()==false)||(((TimeDayOfWeek(TimeCurrent())==0) && (Hour()>=23)|| (TimeDayOfWeek(TimeCurrent())==1) && (Hour()<=15))(OrdersTotal()==0))){ return;}
 
meikel:

try this. i hope i haevnt missed something late at night.

i know that the conditions can be packed in one line, but i wanted to let the other members also do some posts LOL

Thanks meikel.


I still get the errors:


'bool' - semicolon expected Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (86, 1)
'(' - initialization expected Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (86, 20)
'TimeDayOfWeek' - comma or semicolon expected Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (86, 21)
')' - unbalanced right parenthesis Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (86, 52)
')' - unbalanced right parenthesis Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (86, 68)
'(' - initialization expected Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (87, 20)
'TimeDayOfWeek' - comma or semicolon expected Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (87, 21)
')' - unbalanced right parenthesis Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (87, 48)
')' - unbalanced right parenthesis Z:\ForexTrading\GabEA_From Mike\GAPeaOnlySunday.mq4 (87, 52)
and then it continues with the ')' - unbalanced right parenthesis

 
without the full code there is nothing more to do for us.
 
meikel:
without the full code there is nothing more to do for us.

The full code is here:



//+------------------------------------------------------------------+
//|                                                        GAPea.mq4 |
//+------------------------------------------------------------------+

extern double    Lots = 1;
extern int       iTakeProfit=10000;
extern int       iStopLoss=1000;
extern int       iTrailingStop=100;
extern int       min_gapsize=20;
extern int       MagicNumber=13;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----
   
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }  

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }

   if(buys>0) return(buys);
   else       return(-sells);
  } 


//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {

   double current_openprice=iOpen(Symbol(), PERIOD_M15, 0);
   double previous_highprice=iHigh(Symbol(), PERIOD_M15, 1);
   double previous_lowprice=iLow(Symbol(), PERIOD_M15, 1);
   double point_gap=MarketInfo(Symbol(), MODE_POINT);
   int spread_gap=MarketInfo(Symbol(), MODE_SPREAD);
   datetime current_time=iTime(Symbol(), PERIOD_M15, 0);
   

   if(current_openprice > previous_highprice + (min_gapsize + spread_gap)*point_gap )
      {
      OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+iStopLoss*Point,Bid-iTakeProfit*Point,"Sell#",MagicNumber,0,Red);
      }

    if(current_openprice < previous_lowprice - (min_gapsize + spread_gap)*point_gap )
      {
      OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-iStopLoss*Point,Ask+iTakeProfit*Point,"Buy#",MagicNumber,0,Green);
      }
   return;
}

Continues below (text to long)
 
EagleEye:

The full code is here:



The rest of the code:


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()

bool sunday_cond = (TimeDayOfWeek(TimeCurrent())==0) && (Hour()>=23);
bool monday_cond = (TimeDayOfWeek(TimeCurrent())==1) && (Hour()<=15);
bool mytradeallowed = false;
if (
     (Bars<100 || IsTradeAllowed()==false)
     || 
     (
      ( 
       (TimeDayOfWeek(TimeCurrent())==0) && (Hour()>=23)
       ||
       (TimeDayOfWeek(TimeCurrent())==1) && (Hour()<=15)
      )
      (OrdersTotal()==0)  
     )
    ) 
   { return;}

   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   
   if (CalculateCurrentOrders(Symbol()) != 0)
   {
      if(OrderType()==OP_BUY)
      {
         if(Bid-OrderOpenPrice()>Point*iTrailingStop)
         {
            if(OrderStopLoss()<Bid-Point*iTrailingStop)
            {
               OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*iTrailingStop,OrderTakeProfit(),0,Blue);
            }
         }
      }
      if(OrderType()==OP_SELL)
      {
         if(OrderOpenPrice()-Ask > Point*iTrailingStop)
         {
            if(OrderStopLoss() > Ask+Point*iTrailingStop)
            {
               OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*iTrailingStop,OrderTakeProfit(),0,Blue);
            }
         }
      }
   }

//----
    Comment("GAPea v1\n",
            ".................................\n",
            "FX Acc Server:",AccountServer(),"\n",
            "Date: ",Month(),"-",Day(),"-",Year()," Server Time: ",Hour(),":",Minute(),":",Seconds(),"\n",
            "Minimum Lot Sizing: ",MarketInfo(Symbol(),MODE_MINLOT),"\n",
            "Account Balance:  $",AccountBalance(),"\n",
            "Symbol: ", Symbol(),"\n",
            "Price:  ",NormalizeDouble(Bid,4),"\n",
            "Pip Spread:  ",MarketInfo("EURUSD",MODE_SPREAD),"\n",
            "...............................","\n",
            "Lots=" + Lots,"\n",
            "TakeProfit=" + iTakeProfit,"\n",
            "StopLoss=" + iStopLoss,"\n",
            "TrailingStop=" + iTrailingStop,"\n",
            "MagicNumber=" + MagicNumber,"\n");
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

solved

first error, missing bracket

int start()
{ // <- this one, i have overseen this in the first posts
bool


second, missing && (my code LOL

if (
     (Bars<100 || IsTradeAllowed()==false)
     || 
     (
      ( 
       (TimeDayOfWeek(TimeCurrent())==0) && (Hour()>=23)
       ||
       (TimeDayOfWeek(TimeCurrent())==1) && (Hour()<=15)
      )
      && /// <- i have forgot this
      (OrdersTotal()==0)  
     )
    ) 
   { return;}

no errors, no warning

i dont do this much often, but the TV today is awful and so i used this thread and riddle as entertainment

Files:
debug.mq4  5 kb
 
meikel:

solved

first error, missing bracket


second, missing && (my code LOL

no errors, no warning



meikel..... It works!! I'm mean "no errors" :)


Now i need to test it Sunday to see if it works.


Thank u for your help.


Keep you posted after Sunday.

 
EagleEye:

meikel..... It works!! I'm mean "no errors" :)


Now i need to test it Sunday to see if it works.


Thank u for your help.


Keep you posted after Sunday.

you can test it now or tomorrow, simply change the day and time values ...

 
meikel:

you can test it now or tomorrow, simply change the day and time values ...

The only thing i can test right now is that the EA is not trading during the week like it used to do b 4.


And then wait for the Sunday gap and see it trade as it should do.

Reason: