need help with closing stategy

 

Hello,

I have downloaded a free code, it makes good trades, but does not colse in time

the buying is

  ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(Lots),ND(Ask),3,NDTP(Bid-Stop_Loss*pips),NDTP(Bid+Take_Profit*pips),"Long 1",MagicNumber,0,PaleGreen);



  ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized(Lots),ND(Bid),3,NDTP(Ask+Stop_Loss*pips),NDTP(Ask-Take_Profit*pips),"Short 1",MagicNumber,0,Red);


I have included this as a closing strategy but it still does not close when the conditions are met

can you please  help me?

 double main   = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0);

 double signal = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);

 bool res;

  int cnt=0;   

   if ((signal<main )&& OrdersTotal()>0)

   { 

     res=OrderClose(ticket, OrderLots(), OP_BUY,10);

      if(res == false) 

      {Print("Buy Exit Condition error :   ");

      }                      

     else 

      {Print("Buy Exit Condition met :   ", main);}

     }

  

  

   if((signal>main) ) && OrdersTotal()>0)

     {

      res=OrderClose(ticket, OrderLots(), OP_SELL,10);

      if(res == false) 

      {Print("Sell Exit Condition error :   ");

      }                      

     else 

      {Print("Sell Exit Condition met :   ", main);}

    

     }

 
Please edit your post and

use the code button (Alt+S) when pasting code

I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.