need help to close an order at the closing of a bar

To add comments, please log in or register
chim
16
chim  

hello. i have an Ea that i need to add code so that when it opens a trade, that thade is closed at the closing of that bar.

i have used diffent codes but none is working. i need help.

int fOrderOpenBuy(){
   RefreshRates();
   double lts=fGetLotsSimple(OP_BUY);
  // int SIGNAL_CLOSEBUY,Order;
      if(lts>0){      
         if(!IsTradeContextBusy()){
            double slts=ND(Ask-Point*StopLoss);
            if(StopLoss==0)slts=0;
            double tpts=ND(Ask+Point*TakeProfit);
            if(TakeProfit==0)tpts=0;
             
            int irv=OrderSend(Symbol(),OP_BUY,lts,ND(Ask),Slippage,slts,tpts,NULL,Magic_N,0,CLR_NONE);
               if(irv>0)
               {
                  
                  LastBuyTime=iTime(NULL,TimeFrame,0);
                  if(
                  Time[0]>OrderOpenTime()&&Close[0]==OrderOpenPrice());
                   OrderClose(OrderTicket(),OrderLots(),Ask,0,CLR_NONE);
                  if(CancelSleeping)LastSellTime=0;
                  return(irv);
                  
               }
               else{
                  Print ("Error open BUY. "+fMyErDesc(GetLastError())); 
                  return(-1);
               }
         }
         else{
            static int lt2=0;
               if(lt2!=iTime(NULL,TimeFrame,0)){
                  lt2=iTime(NULL,TimeFrame,0);
                  Print("Need open buy. Trade Context Busy");
               }            
            return(-2);
         }
chim
16
chim  
chim:

hello. i have an Ea that i need to add code so that when it opens a trade, that thade is closed at the closing of that bar.

i have used diffent codes but none is working. i need help.

@Jeffrey Irick
To add comments, please log in or register