[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 459

 
Maximov7:

Here is another question .... i have an open order like this:

OrderSend("EURUSD",OP_BUY,0.1,C1,10,Bid-0.0017-0.0017,Ask+0.0017);

how to open another order if this one closes at takeprofit????


did you readthe book ? (at least for fun)
 
Reread it 3 times..... and yet?
 
Maximov7:
I've read..... 3 times and yet?


In the loop on the history of closed orders, find "this" order, then check whether it closed on TP, if so, then open a "different". That is all.

See here for more details - select the fi ries you need, plug them into your software and that's it.

 
Thank you very much!
 
Maximov7:
Thank you very much!

Enjoy it.
 

Good evening!

Please take a look at the code:

for(i=1;i<=OrdersTotal();i++) // retrieve orders for trawl

{

if(OrderSelect(i-1,SELECT_BY_POS)==true)

{

if (OrderSymbol()!=Instr)

continue;

if(OrderType()==0)

{

if ((Bid-(OrderOpenPrice()+TralingStop*Point))>0)

return(55);}

if(OrderType()==1)

{

if ((Ask-(OrderOpenPrice()-TralingStop*Point))<0)

return(55);

}

}

I don't understand what the problem is, I'm testing with an Alert inside, it doesn't work anywhere else after Instr

 
demlin:

Good evening!

Please take a look at the code:

for(i=1;i<=OrdersTotal();i++) // retrieve orders for trawl

{

if (OrderSelect(i-1,SELECT_BY_POS)==true)

{

if (OrderSymbol()!=Instr)

continue;

if(OrderType()==0)

{

if ((Bid-(OrderOpenPrice()+TralingStop*Point))>0)

return(55);}

if(OrderType()==1)

{

if ((Ask-(OrderOpenPrice()-TralingStop*Point))<0)

return(55);

}

}

I don't understand what the problem is, I'm testing with an Alert inside, it doesn't work anywhere else after Instr


Is there a line like this above the code?
string Instr;
Insert the code properly - via SRC in the editor... :-)))
 
Roman.:

Is there a line like this above the code? Insert the code properly - via SRC in the editor... :-)))
Yes Instr is, sorry don't know what SRC is
 
demlin:
Yes Instr is, sorry don't know what SRC is

When you paste the code into your post press CTRL+ALT+M - then put the code there (through the buffer CTRL+C - copy, CTRL+V - paste), then press the "paste" button at the bottom of the window.
 
demlin:

Good evening!

Please take a look at the code:

for(i=1;i<=OrdersTotal();i++) // retrieve orders for trawl

{

if (OrderSelect(i-1,SELECT_BY_POS)==true)

{

if (OrderSymbol()!=Instr)

continue;

if(OrderType()==0)

{

if ((Bid-(OrderOpenPrice()+TralingStop*Point))>0)

return(55);}

if(OrderType()==1)

{

if ((Ask-(OrderOpenPrice()-TralingStop*Point))<0)

return(55);

}

}

I don't understand what the problem is, I'm testing with an Alert inside, it doesn't work anywhere else after Instr


Try this option - this is how I have a similar design organised.


// ------------------------------------------------Ищем наш ордер---------------------------------

int orderType;
   for (int orderIndex = (OrdersTotal() - 1); orderIndex >= 0; orderIndex--)
   {
      if (!OrderSelect(orderIndex, SELECT_BY_POS))
      {
         continue;
      }

      if ((OrderSymbol() != Symbol()) || (OrderMagicNumber() != MagicNumber))
      {
         continue;
      }

      orderType = OrderType();
      if ((orderType != OP_BUY) && (orderType != OP_SELL))
      {
         continue;
      }
          ticket = OrderTicket( );                         // Номер ордера
          orderLots = OrderLots();                         // Lots   
          orderProfit = OrderProfit() + OrderSwap();       // Profit
          Price = OrderOpenPrice();                        // Цена открытия рыночного ордера
          SL =  OrderStopLoss();                           // Значение StopLoss ордера
          TP = OrderTakeProfit();                          // Значение TakeProfit ордера
          
             if (ticket>0)                                               // Если позиция открылась
                    {
                             while(OrderSelect(ticket,SELECT_BY_TICKET)==false)       // Если ордер выбран
                                 {
                                   Sleep(100);
                                 }
                                  double OpenPrice=OrderOpenPrice();
                                      
                                  
                    
                                if (orderType == OP_BUY) 
                                     {
                                       //здесь трал покупки
                                     }
            
                                if (orderType == OP_SELL) 
                                      {
                                        //здесь трал продажи
                                      }   
                            
                    }
        
   }
Reason: