Open trade at Tuesday, close at Friday

 
Hello,
I am beginner at coding, and i dont know how to make this:

Open one trade at Tuesday at 10:00h, and close it at Friday at 22:00, if still open?

Buy or Sell are based on some indicators.

Can somebody help me?
 
  1. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help 2017.04.21

  2. Get the current time. Check for Tuesday. Check for past 10. Check for open order. Open. What's the problem?
              Find bar of the same time one day ago - MQL4 programming forum 2017.10.06

 
Vladislav Sashkov Vasilev:
Hello,
I am beginner at coding, and i dont know how to make this:

Open one trade at Tuesday at 10:00h, and close it at Friday at 22:00, if still open?

Buy or Sell are based on some indicators.

Can somebody help me?

It will buy or sell according to what indicator. the other is very easy to turn on and off.

 
Mehmet Bastem:

It will buy or sell according to what indicator. the other is very easy to turn on and off.

Hello, sry for late respond, now i see ur message, here is the code i create, its RSI indicator

Files:
RSI_EA_V1.mq4  3 kb
 
Vladislav Sashkov Vasilev:

Hello, sry for late respond, now i see ur message, here is the code i create, its RSI indicator

//+------------------------------------------------------------------+
//|                                                   RSI Weekly.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

input int rsiPeriod = 500;
input int topLevel = 55;
input int bottomLevel = 45;
input int takeProfit = 60;
input int stopLoss = 60;
input double lotSize = 0.01;
input int  EAStartTime=10;
input int  EAStopTime=22;

datetime nowTime;
// Open one trade at Tuesday at 10:00h, and close it at Friday at 22:00, if still open?


int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason)
{ 
}

void OnTick()
{
   if(nowTime !=iTime(Symbol(), PERIOD_CURRENT, 0)
    &&
    (DayOfWeek()==2 && TimeHour(TimeLocal())>=EAStartTime)
   )
    {
      
      onBar();
      nowTime = iTime(Symbol(), PERIOD_CURRENT, 0);
   }
   //
   // Close
   if(DayOfWeek()==5 && TimeHour(TimeLocal())>=EAStopTime) CloseAllTrades();
   
}

int getTradeCount(){
   int count = 0;
   for(int i=0; i<OrdersTotal(); i++){
      if(OrderSelect(i, SELECT_BY_POS)){
         if(OrderSymbol() == Symbol()){
            count++;
          }
       }
    }
   return count;  
}

void onBar(){
   bool rst;
   if(getTradeCount() == 0){
       if(iRSI(Symbol(), PERIOD_CURRENT, rsiPeriod, PRICE_MEDIAN, 1) < topLevel && iRSI(Symbol(), PERIOD_CURRENT, rsiPeriod, PRICE_MEDIAN, 2) > topLevel){
       // sell signal
       rst=OrderSend(Symbol(), OP_SELL, lotSize, Bid, 3, Bid + stopLoss/MathPow(10, Digits()), Bid - takeProfit/MathPow(10, Digits()));
      } else if(iRSI(Symbol(), PERIOD_CURRENT, rsiPeriod, PRICE_MEDIAN, 1) > bottomLevel && iRSI(Symbol(), PERIOD_CURRENT, rsiPeriod, PRICE_MEDIAN, 2) < bottomLevel ){
       //buy signal
       rst=OrderSend(Symbol(), OP_BUY, lotSize, Ask, 3, Ask - stopLoss/MathPow(10, Digits()), Ask + takeProfit/MathPow(10, Digits()));
      }
   }
}
  
int CloseAllTrades()
{
  int total = OrdersTotal();
  for(int i=total-1;i>=0;i--)
  {
    bool asdsa=OrderSelect(i, SELECT_BY_POS);
    int type   = OrderType();

    bool result = false;
    
    switch(type)
    {
      //Close opened long positions
      case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE );
                          break;
      
      //Close opened short positions
      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE );
                          break;

      //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP   :
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
    }
    
    if(result == false)
    {
       if (GetLastError()>0) Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      Sleep(3000);
    }  
  }
  
  return(0);
}