[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 395

 
KostelloArtua:

Thanks so much for the tips!!! Got my issue sorted out. It turned out that the broker I was looking for, when placing a market order, i.e. according to the conditions, does not allow me to place stop levels at the same time. Now the orders are placed without any stop levels and I set stop levels immediately after each order. I have a problem with this: Only a very small part of orders are modified, while most of the orders show the following results in the "Expert Advisors" section:

2011.05.19 09:46:55 Spacenewcomer-Svecha CLM1,M15: open #30906670 sell 0.01 CLM1 at 99.79 ok
2011.05.19 09:46:55 Spacenewcomer-Svecha CLM1,M15: invalid ticket for OrderModify function
2011.05.19 09:55:40 Spacenewcomer-Svecha ESM1,M5: open #30906787 buy 0.01 ESM1 at 1337.50 ok

2011.05.19 10:00:03 Spacenewcomer-Svecha EURUSD,M15: Invalid ticket for OrderModify function

Here is the code text:

{
res=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,0,0, "basic",_MagicNumber,0,Red);


OrderModify(OrderTicket(),OrderOpenPrice(),Ask+StopLoss*Point,Ask-TakeProfit*Point,0,Red);
return(0);

}

Besides, it's the first order that is modified after the Expert Advisor is started!

Obviously, I've set the wrong modification of orders in the code... Please, help me!

res=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,0,0, "basic",_MagicNumber,0,Red);

OrderSelect(res, SELECT_BY_TICKET);
OrderModify(OrderTicket(), OrderOpenPrice(),NormalizeDouble(Ask+StopLoss*Point, Digits),NormalizeDouble( Ask-TakeProfit*Point, Digits),0,Red);
 
ilunga:
res=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,0,0, "basic",_MagicNumber,0,Red);

OrderSelect(res, SELECT_BY_TICKET);
OrderModify(OrderTicket(), OrderOpenPrice(),NormalizeDouble( Ask+StopLoss*Point,Digits),NormalizeDouble( Ask-TakeProfit*Point,Digits),0,Red);
Thanks for the tip!!!
 
Sancho77:
Dear programmers, I am asking for help in modifying the Expert Advisor: I have an open position and after some time there is a second signal to open the position in the same direction. I want to fill the position by the second signal only if the first order is already in the plus position. I implemented this by comparing the balance size and equity (if the equity is higher than the balance, the order opened is in the plus).
Can you suggest a code to determine the profit/loss on the last open order you have?

If his ticket number is saved, then simply

OrderSelect(ticket, SELECT_BY_TICKET);

if (OrderProfit() > )

{

          // доливаем ордер

}
 
ilunga:

If his ticket number is saved, simply


Thank you! Can you tell me how to save the ticket of the last order?
 
Sancho77:
Thank you! Can you advise how to save the ticket of the last order?

well, the simplest option is to declare a global variable int ticket

and replace ticket = OrderSend(...) everywhere with ticket = OrderSend(...)

it will always store the number of the last opened order

Or see topic "Useful functions from KimIV" only!

 
ilunga:

well, the simplest option is to declare a global variable int ticket

and replace ticket = OrderSend(...) everywhere with ticket = OrderSend(...)

it will always store the number of the last opened order

or see topic "Useful functions from KimIV" only

Thanks for all your help!
 
rustein:

Help me find an error,

Thank you


BuySL*Point // зачем умножать на Point ? Тоже самое для SelSL*Point
 
khorosh:

Thank you,

I don't know... Thought it would work, it doesn't work without either, made it so and it works....

//-----
  double Spread = (NormalizeDouble(Ask,Digits) - NormalizeDouble(Bid,Digits)) / Point;
  double BuySL = NormalizeDouble(iCustom(NULL,0,"NRTR",AveragePeriod,0,1),Digits);
  double SelSL = NormalizeDouble(iCustom(NULL,0,"NRTR",AveragePeriod,1,1),Digits);
//-----
  int Orders = OrdersTotal();
  for (int i=0; i<Orders; i++)
  {
    if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
    if (OrderSymbol() != Symbol()) continue;
    {
      if(OrderType() == OP_BUY && OrderMagicNumber()==Magic && OrderStopLoss() != BuySL-Spread*Point
      && BuySL-Spread*Point > OrderStopLoss() && BuySL-Spread*Point > OrderOpenPrice())
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),BuySL-Spread*Point,OrderTakeProfit(),0,CLR_NONE);
      }
      if(OrderType() == OP_SELL && OrderMagicNumber()==Magic && OrderStopLoss() != SelSL+Spread*Point
      && SelSL+Spread*Point < OrderStopLoss() && SelSL+Spread*Point < OrderOpenPrice())
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),SelSL+Spread*Point,OrderTakeProfit(),0,CLR_NONE);
      }
    }
  }
}

 
Roger:
PRICE_OPEN !!!! - you cannot use this price! It only works for indicators. Use Bid or Ask.

Thank you!!! Yeah, that's a definite possibility.
 

Guys a more complicated question......

How to make an EA close all orders when a given profit is reached .... Close only orders on one symbol ...

Example : EA works on 3 pairs amount to close all orders on one symbol 100p ...

If the EUR has more than 100p it will only close orders on EUR while others may have 200p ...

If I take accountbalanse() then advisor will close only when sum of three pairs is more than 100p. this option does not fit me !!!!

Help please.........

Reason: