need help - page 2

 
TeeZai:

Your issue lies in the following line:

You call CheckForOpen every tick, your time_waiting resets upon each call. Maybe you should add a while-loop to wait for the time to pass.

Since you are using TimeLocal in your code, which uses the current computer time, I think you will not be able to backtest the code correctly. 

it doesn't work too

updated code

#property version   "1.00"
#property strict
input string comEAsettings="[EA settings]";//~
input int MagicNumber=55545;
input string EA_Comment="";
input double DecreaseFactor=3;
input int    MovingPeriod  =1;
input int    MovingShift   =0;
bool UseFixedLot=FALSE;
double lots=0.1;
double _point=1;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
//Get Symbol digit
   string _sym=Symbol();
   double _digits=MarketInfo(_sym,MODE_DIGITS);
   if(_digits==5||_digits==3) _point=1/MathPow(10,(_digits-1));
   if(_digits==4||_digits==2) _point=1/MathPow(10,(_digits));
   if(_digits==1) _point=0.1;
//
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
if(Volume[0]>1) return;
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   int maxDuration = 5 * 60; 
   for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)            // Only my orders w/
&&  OrderSymbol()== Symbol()){               // and period and symbol
    int duration = TimeCurrent() - OrderOpenTime();
    if (duration >= maxDuration)
         OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(),
                     3*Point);
}  

  
    
  }
  
void CheckForOpen()
  {
  string TradeStartTime = "10:30";
  string TradeStopTime = "23:00";

//--- get Moving Average  
   //BB
   double BandsTopCurrM5=iBands(Symbol(),PERIOD_M5,20,2,0,PRICE_CLOSE,MODE_UPPER,1);
   double BandsLowCurrM5=iBands(Symbol(),PERIOD_M5,20,2,0,PRICE_CLOSE,MODE_LOWER,1);
   double BandsTopCurrM15=iBands(Symbol(),PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_UPPER,1);
   double BandsLowCurrM15=iBands(Symbol(),PERIOD_M15,20,2,0,PRICE_CLOSE,MODE_LOWER,1);
   
   //OPEN CLOSE
   double openM5=iOpen(Symbol(), PERIOD_M5, 1);
   double closeM5=iClose(Symbol(), PERIOD_M5, 1);
   double openM15=iOpen(Symbol(), PERIOD_M15, 1);
   double closeM15=iClose(Symbol(), PERIOD_M15, 1);
   
   //HIGH LOW
   double highM5=iHigh(Symbol(), PERIOD_M5, 1);
   double lowM5=iLow(Symbol(), PERIOD_M5, 1);
   double highM15=iHigh(Symbol(), PERIOD_M15, 1);
   double lowM15=iLow(Symbol(), PERIOD_M15, 1);
   double ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_EMA,PRICE_WEIGHTED,1);
   
   static int _time_waiting=0;
// ...SELL

   
   datetime Date=TimeLocal();
   int i=0;
   _time_waiting = Date + 300; // the pause ends in 10 seconds after the current local time
   
   if ( openM15>BandsLowCurrM15 && closeM15<BandsLowCurrM15 && closeM15-lowM15!=0 && highM15-openM15>=closeM15-lowM15 ){ // condition that requires to hold a pause
   while (Date < _time_waiting) {  Alert("Mandeha:",i++); Date++;  } //Create a while loop to wait before execute next line
   if ( Date >= _time_waiting )
   { 
      if(OrdersTotalT(OP_SELL)==0 && TimeCurrent()>StrToTime(TradeStartTime) && TimeCurrent()<StrToTime(TradeStopTime) && closeM5-lowM5!=0 && openM5>BandsLowCurrM5 && closeM5<BandsLowCurrM5){
     
         double _sl= MathRound(ma-closeM5)/_point;
         SendOrder(OP_SELL,_sl);
          }
   }}
// program block to be executed at every tick, not related to waiting for the end of the pause
// ...
     
// ...BUY
   if ( openM15<BandsTopCurrM15 && closeM15>BandsTopCurrM15 && highM15-closeM15!=0 && highM15-closeM15<=openM15-lowM15 ){ // condition that requires to hold a pause
      while (Date < _time_waiting) { Alert("Mandeha:",i++); Date++; } //Create a while loop to wait before execute next line  
      if ( Date >= _time_waiting )
         { 
            if(highM5-closeM5!=0 && openM5<BandsTopCurrM5 && closeM5>BandsTopCurrM5 && OrdersTotalT(OP_BUY)==0 && TimeCurrent()>StrToTime(TradeStartTime) && TimeCurrent()<StrToTime(TradeStopTime)){
            double _sl = MathRound(closeM5-ma)/_point;//
            SendOrder(OP_BUY,_sl);
         }
      }}
//---
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---

  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---

  }
//+------------------------------------------------------------------+
// function to send order
bool SendOrder(int type,double _sl)
  {
   while(IsTradeContextBusy());
   int ticket=-1;
   double SL,TP;
   double lots=0;
   double Lots;
   if(type==OP_BUY)
     {
      if(_sl==0){SL=0;}else{SL=Ask-3*_sl*_point;}
      if(_sl==0){TP=0;}else{TP=Ask+2*_sl*_point;}
      Lots=(AccountBalance() * 2.6 / 100) / (SL * Point);
      lots=Lots;
      ticket=OrderSend(Symbol(),OP_BUY,NormalizeLots(lots,Symbol()),Ask,3,SL,TP,EA_Comment,MagicNumber,0);
     }
   if(type==OP_SELL)
     {
      if(_sl==0){SL=0;}else{SL=Bid+3*_sl*_point;}
      if(_sl==0){TP=0;}else{TP=Bid-2*_sl*_point;}
      Lots=(AccountBalance() * 2.6 / 100) / (SL * Point);
      lots=Lots;
      ticket=OrderSend(Symbol(),OP_SELL,NormalizeLots(lots,Symbol()),Bid,3,SL,TP,EA_Comment,MagicNumber,0);
     }
   if(ticket<0)
     {
      Print("OrderSend  failed with error #",GetLastError());
      return(false);
     }
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//make lots to right format
double NormalizeLots(double _lots,string pair="")
  {
   if(pair=="") pair=Symbol();
   double  lotStep=MarketInfo(pair,MODE_LOTSTEP),
   minLot=MarketInfo(pair,MODE_MINLOT);
   _lots=MathRound(_lots/lotStep)*lotStep;
   if(_lots<MarketInfo(pair,MODE_MINLOT)) _lots=MarketInfo(pair,MODE_MINLOT);
   if(_lots>MarketInfo(pair,MODE_MAXLOT)) _lots=MarketInfo(pair,MODE_MAXLOT);
   return(_lots);
  }

//+------------------------------------------------------------------+

int OrdersTotalT(int _type)
  {
   int _total=0;
   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
     {

      bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderType()==_type)
        {
         _total++;
        }
     }
   return(_total);
  }
  
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) continue;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//--- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

Files:
m15.PNG  42 kb
m5.PNG  51 kb
 
Comments that do not relate to this topic, have been moved to "Off Topic Posts".
 
Keith Watford:
Comments that do not relate to this topic, have been moved to "Off Topic Posts".
No one reply here pffffffffffffffff
I am here to get help but none help here 
Have a good day all :-(
 
Dany William:
No one reply here pffffffffffffffff
I am here to get help but none help here 
Have a good day all :-(

You have had a number of replies!

Nobody is obligated to help you.

I saw William's reply concerning

{if(Volume[0]>1) return;

and I see in your updated code that you have completely ignored him.

When I see good advice get ignored, it makes me less inclined to waste my time helping that person as I will expect any advice that I give will also be ignored.

 
Keith Watford:

You have had a number of replies!

Nobody is obligated to help you.

I saw William's reply concerning

and I see in your updated code that you have completely ignored him.

When I see good advice get ignored, it makes me less inclined to waste my time helping that person as I will expect any advice that I give will also be ignored.

sorry for that then

I am terribly sorry

To tell the truth, I did not understand what he mean but terribly sorry all

 

Checking for a new bar is very simple

  static datetime barTime=0;
  bool newBar=false;
  datetime thisBarTime=Time[0];
  if(barTime!=thisBarTime)
   {
    barTime=thisBarTime;
    newBar=true;
   }

  if(newBar)
   {
    //Code to be executed only on a new bar here 
   }
Reason: