orderselect

 

Hello. i have a problem with OrderSelect()

this i the code a made but ther orderclose never carry out. so if someone could help i´d be very grateful.

 input double Lots=0.01;


input double macd_rapido=12;

input double macd_lento=26;

input int macd_signal=9;  

input int slippage=3;

input int magic=12345;

//--------------




int init()

  {

//---


//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void deinit()

  {

//---

   return;

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//--- definimos variables a usar

   double MacdCurrent,MacdPrevious;

double SignalCurrent,SignalPrevious;

bool cerrar;


int    i,ticket,total;

//----------------

double SL=Ask-50*Point;

double TP=Ask+100*Point;


MacdCurrent=iMACD(Symbol(),0,macd_rapido,macd_lento,macd_signal,PRICE_CLOSE,MODE_MAIN,0);

MacdPrevious=iMACD(Symbol(),0,macd_rapido,macd_lento,macd_signal,PRICE_CLOSE,MODE_MAIN,1);

SignalCurrent=iMACD(Symbol(),0,macd_rapido,macd_lento,macd_signal,PRICE_CLOSE,MODE_SIGNAL,0);

SignalPrevious=iMACD(Symbol(),0,macd_rapido,macd_lento,macd_signal,PRICE_CLOSE,MODE_SIGNAL,1);


total=OrdersTotal();

//-------------------------------

   if (total<1)

      {

       if(MacdCurrent>MacdPrevious)

         {

          ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,SL,TP,NULL,magic,0,clrGreen);

         

          for (i=0;i<total;i++)

              {

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

                    {

                     if((OrderType()==OP_BUY)&& (OrderSymbol()==Symbol())) continue;

         

                    if (MacdCurrent<MacdPrevious)

             {

             cerrar=OrderClose(ticket,Lots,Bid,slippage,clrRed);

                 

                     }

                     }

                     }

                     return;

                     }

                     } 

                     }

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

thankss in advance
 

Hi!


Try to debug your code.

You enter your code only if you have no order. What shall be closed?

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. What eddie said.
  3. Your order select loop finds the order. You test if it matches a Buy on Symbol and you reject it.
      if((OrderType()==OP_BUY)&& (OrderSymbol()==Symbol())) continue;
  4. You must count down when closing/deleting in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
Reason: