Open a new order

 

Hi all,

I'm try to get a new order open when the the difference between Bid and last order open price equals or is above ta certain distance.

The code that I want to use  is as follow;

 

void OpenNextOrder()
    {//0     
     int Op; 
      
     for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--)     
      {//1
      if(!OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES))continue;          
         {//2
         if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)           
            {//3
             Op = OrderType();            
             if (Op == OP_BUY && (Bid - OrderOpenPrice()) >= Distance*pips2dbl)
               {//4                             
                  RefreshRates();                             
                  BuyTicket = OrderSend(Symbol(), OP_BUY, MLots, Ask, Slippage*pips2points, 0, 0, "Next Buy Order", MagicNumber, 0, Red);
                  if(BuyTicket > -1)                   
                   {//5                                                                                                                                          
                     Print(" Next Buy Order Placed: ","Order Ticket: ",BuyTicket," Spread: ",DoubleToStr(Spread,Digits)," Open Price: ",DoubleToStr(OrderOpenPrice(),Digits));                 
                  return;
                   }//5              

 

The issue is as one could seen the code do not work. Could you shown me where I'm wrong ?

Thank you in advance for any support provided.

Luis 

 
luisneves:

Hi all,

I'm try to get a new order open when the the difference between Bid and last order open price equals or is above ta certain distance.

It's a 2 stage process,  within the loop identify the last Order by comparing OrederOpenTime() the Order with the highest value is the last one opened,and make note of it's OrderOpenPrice() . . .   outside the loop compare this value with Bid,  if appropriate place the new Order.

What about OP_SELL ?   and your code is meant to work only with currently open Orders ?

 
RaptorUK:

It's a 2 stage process,  within the loop identify the last Order by comparing OrederOpenTime() the Order with the highest value is the last one opened,and make note of it's OrderOpenPrice() . . .   outside the loop compare this value with Bid,  if appropriate place the new Order.

What about OP_SELL ?   and your code is meant to work only with currently open Orders ?


Hi RaptorUK,

Thank you for keeping attention to my issue. 

So, let me show you what I'm looking for in more detail.

I'm looking to get buy multiple buy orders when price is going up by a distance value say for every 5 pips and all the same if price goes down. Is the process the same or am I far away from the right way to get it ? 

Thank you in advance.

Luis 

Reason: