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

 

All right!!!! If there are no desired orders, X remains equal to zero with the desired magic number and the orders will be opened. If there are any, X equals 2 and no more orders will be opened.

So what else is the problem?

- At the very first moment, you select an order that does not exist using the OrderSelect function.

in the first loop for(int Uy=OrdersTotal();Uy<=-1;Uy--) So what, well the cycle runs more for hope, then I changed it to 0, there is no change in the work, these are all not errors, they do not change, I apologize.

 
Inserted an alert to track the work of the cycle. I don't understand anything. The variable, which is in the loop, only once, in the beginning, with a value of 0, and then sell stop 0 and buy stop 130, which is also surprising, they are symmetrical!!!! And after 2.5 m of the inscription already says error 148 (broker bans many orders)
//+------------------------------------------------------------------+
//|                                                    для лавин.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern double stoploss=0; extern double takeprofit=20;extern int otstup=20; extern datetime expiration=0;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
 int tiket,tikett;double volume=0.1;int i=0,R1=0,R2=0,A=1 ;double price=PRICE_OPEN;
   //  R1=((PRICE_OPEN- stoploss*Point)*stoploss)/stoploss;R2=((PRICE_OPEN+ stoploss*Point)*stoploss)/stoploss;
     
     
int start()
  {       int X;       
//----
       for(int Uy=OrdersTotal();Uy==0;Uy--){
OrderSelect( Uy,SELECT_BY_POS );Alert ("Uy",Uy);
if(OrderSymbol()==Symbol()&&OrderMagicNumber( )==1000||OrderMagicNumber( )==2000 &&OrderSymbol()==Symbol())
{X ++;}}  
if (X<=2){
   tiket= OrderSend( Symbol(), OP_BUYSTOP,  volume*A, price +otstup*Point, Point* 3, R1, PRICE_OPEN+takeprofit*Point+otstup*Point, "OP_BUYSTOP", 1000,  expiration, Red); 
   Alert ("OP_BUYSTOP", GetLastError( )); 
   tikett= OrderSend( Symbol(), OP_SELLSTOP,  volume*A, price -otstup*Point, Point* 3,R2, PRICE_OPEN-takeprofit*Point-otstup*Point, "OP_SELLSTOP" , 2000,  expiration,C'0,128,255' );
    Alert ("OP_SELLSTOP", GetLastError( )); 
    }       
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Oh, what a nonsense. And at first, every time the date is not correct, about 49 times. Yes!!!! X always stays 0 and it writes fine. In 2 orders.

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

All right!!!! If there are no desired orders, X remains equal to zero with the desired magic number and the orders will be opened. If there are any, X equals 2 and no more orders will be opened.

So what else is the problem?

- At the very first moment, you select an order that does not exist using the OrderSelect function.

in the first loop for(int Uy=OrdersTotal();Uy<=-1;Uy--) So what, the loop runs more for hope, then I changed it to 0, there is no change in the work, these are all not errors, they do not change, I apologize.

How can it run longer than ?

No matter how many orders are open, the condition Uy<=-1 is not fulfilled immediately because the number of orders is greater than or equal to zero immediately

 

Help me find the error,

Thank you

void TrailPositions()
{
//-----
  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*Point
      && BuySL*Point > OrderStopLoss())// && BuySL*Point > OrderOpenPrice())
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),BuySL*Point,OrderTakeProfit(),0,CLR_NONE);
        if(UseSound == true)
        {
        PlaySound(SuccesSound);
        }
      }
      if(OrderType() == OP_SELL && OrderMagicNumber()==Magic && OrderStopLoss() != SelSL*Point
      && SelSL*Point < OrderStopLoss())// && SelSL*Point < OrderOpenPrice())
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),SelSL*Point,OrderTakeProfit(),0,CLR_NONE);
        if(UseSound == true)
        {
        PlaySound(SuccesSound);
        }
      }
    }
  }
}

 
PapaYozh:


If the ticks are running, the icon of EA is "smiling", EA should make deals (i.e. conditions for it appear), but it does not make them, then it is necessary to debug.

Arrange the price() command in the code of the EA, especially in those places where it is compared and see what exactly is being compared. Perhaps, you have a comparison on the equality of variables with type double and the comparison result is always false, while you assume that the variables are equal.

Thanks so much for the tips!!! Got my issue sorted out. It turned out that the broker I needed when placing a market order, i.e. according to the conditions, does not have the ability 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);

}

And it's the first order that is modified after the start of the Expert Advisor!

Naturally, I've got the order modification wrong in the code... Please advise!

 
so can anyone help with a function that shows the last two extremes on ZZ ???
 
Dear programmers, I am asking for a suggestion on how to improve the Expert Advisor: There is an open position and after some time there is a re-opening signal in the same direction. I want to fill the second signal only if the first order is already in profit. 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?
 
Measure in pips, the most reliable.
 
Roger:
Measure in pips, the most reliable.
Can you give me a code?