my Ea it's no working problem with OrderModifly

 

The boys,

my EA doesn't work anymore after entering OrderModifly. I share the code

I'll wait for an answer

thank you very much

void OnTick()

  {





 if(NewBar()){

 EseguiOrdineLong();



}

  

  }

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

  void EseguiOrdineLong(){

  

   if ( iOpen(Symbol(),PERIOD_CURRENT,1)-iClose(Symbol(),PERIOD_CURRENT,1)>AmpiezzaMinimaCandele*10*Point)

   {

    OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES);

               

                 if(OrderCloseTime()==0 && OrderType()==OP_SELL){

                 

                    OrderClose(Ticket,OrderLots(),Ask,0,0);

                    

                    Ticket=OrderSend(Symbol(),OP_BUY,Lotti,Ask,0,Ask-10*SL*Point,Ask+TP*Point,0,0,0,0);

                 }

                 

                 else if (OrderCloseTime()!=0){

                 

                      Ticket=OrderSend(Symbol(),OP_BUY,Lotti,Ask,0,Ask-10*SL*Point,Ask+TP*Point,0,0,0,0);

                 

                 }}

 

  do{

  Sleep(500000);

  i=TP-10;

  if(Ask>i)

  {

  if (OrderSelect(Ticket,SELECT_BY_TICKET)==True)

{

 OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-40*Point,OrderOpenPrice()+40*Point,0,Yellow);

 

 RefreshRates();

  

  }}

  }

  while(Ticket==0);

  }

  

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

  

  

  

bool NewBar(){



   static datetime lastbar;

   datetime curbar = Time[0];

   

     if(lastbar!=curbar){

     

         lastbar=curbar;

         return (true);    

     }

     else{

     

       return(false);

     }

}     
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES);
    OrderClose(Ticket,OrderLots(),Ask,0,0);
    Ticket=OrderSend(S…);
    OrderModify(…);
    You would know why, if you Check your return codes for errors, and report them including GLE/LE. Don't look at GLE/LE. unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  3. while(Ticket==0);
    
    Possible infinite loop.

  4. Sleep(500000);
    After Sleep and between server calls the market will have changed. You must update your variables before using any Predefined Variables or series arrays — you must call RefreshRates.

  5. Ticket=OrderSend(Symbol(),OP_BUY,Lotti,Ask,0,Ask-10*SL*Point,Ask+TP*Point,0,0,0,0);
    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)

  6. Use the debugger or print out your variables, including _LastError and find out why.
 

Excuse me, so it should go.

I shared the wrong code.

this is the correct one.

thanks for the very quick and fulfilling ans

void EseguiOrdineLong(){
     if(iMA(Symbol(),PERIOD_M30,10,0,MODE_SMA,PRICE_CLOSE,2)<iMA(Symbol(),PERIOD_M30,30,75,MODE_SMA,PRICE_CLOSE,2) && 
        iMA (Symbol(),PERIOD_M30,10,0,MODE_SMA,PRICE_CLOSE,0)>iMA(Symbol(),PERIOD_M30,30,75,MODE_SMA,PRICE_CLOSE,0)){
        printf("aprire posizione in buy");
       Alert("tick new"); 
        OrderSelect(Ticket1,SELECT_BY_TICKET,MODE_TRADES);
               
                 if(OrderCloseTime()==0 && OrderType()==OP_SELL){
                 
                    OrderClose(Ticket1,OrderLots(),Ask,0,0);
                    
                    Ticket1=OrderSend(Symbol(),OP_BUY,LottiH4,Ask,0,Ask-10*SL*Point,Ask+10*TP*Point,0,0,0,0);
                 }
                 
                 else if (OrderCloseTime()!=0){
                 
                      Ticket1=OrderSend(Symbol(),OP_BUY,LottiH4,Ask,0,Ask-10*SL*Point,Ask+10*TP*Point,0,0,0,0);
                 
               }}    
         
      if(Ask>TP*Point)
  {
  if (OrderSelect(Ticket1,SELECT_BY_TICKET)==True)
{
 OrderModify(OrderTicket(),Ask,Ask-SL*10*Point,Ask+TP*10*Point,0,Yellow);
 
 RefreshRates();
  }}}