I'm learning to write an advisor... - page 6

 
ALex2008 >> :

Take your time to read the thread!

I am writing there about the option

even if the BROKER gives a requote ...


error code 138 and a real account.

 

If you mean this option and it refers to OrderModify

YuraZ писал(а) >>

допустим

получен сигнал -

на тике бъем на вход раз 5

не пробили! вышли

на втором тике после сигнала входим и долбим далше!

..then I haven't grown to the ticks yet))) How to account for them 1st tick, 2nd tick?

Sleep(2000); // it's a 2 second wait after an error

And wait for a new tick for how long?


 
Talex >> :
Try it like this.

I now have the task of setting a stop via OrderModify immediately after OpenSend and checking if this stop exists.

If it didn't work, don't trace it anymore, if not, what's the error and try to put... put... and put...)

RefreshRates();   
           double SLS = Ask+ Stop*Point;   //стоп на продажу
           Modify = OrderModify(OrderTicket(),OrderOpenPrice(), SLS,OrderTakeProfit(),0,Red);
              if ( Modify == false)
                  {
                      Print("Ошибка при попытке установить стоп для SEL, код ошибки ="+GetLastError());
                      for (int j=0 ;; j++) //пытаемся пока ДЦ не умрет)
                             {
                                SLS = SLS+ j*Point;   //увеличиваем стоп на 1 пп 
                                RefreshRates();
                                Modify = OrderModify(OrderTicket(),OrderOpenPrice(), SLS,OrderTakeProfit(),0,Red);
                                   if ( Modify==true)
                                       break;
                                   else   
                                       Print("Ошибка при попытке установить стоп для SEL, код ошибки ="+GetLastError());        
                              }
                  }
 
Can you tell me how to check the status of OrderModify, so that after a successful modification you won't try to modify again and get unnecessary errors?
 
bool ModifyS = OrderModify(OrderTicket(),OrderOpenPrice(), SLS,OrderTakeProfit(),0,Red);
if ( ModifyS==true) continue;

replace with this:

ModifyS = OrderModify(OrderTicket(),OrderOpenPrice(), SLS,OrderTakeProfit(),0,Red);
if ( ModifyS==true) break;

here:

1. why define variable type unnecessarily - this is an error that should pop up during compilation

2. instead of continue - to transition to a new iteration (i.e. to a new attempt to modify), use break - exit from the loop (and infinite, which is not good)

 
Xupypr >> :

1. why define the type of variable unnecessarily - this is an error that should pop up at compile time

fixed)

2. Instead of continue - iteration jumping to a new iteration (i.e. a new modification attempt), use break - exit from the loop

>> Thank you!

...and it's endless, which is not good...

infinite because it is necessary to stop it...

And if I make a couple of attempts and it is rejected for some reason and the price goes far against the position during this time... What to do then?

 

Errors in the log:

open #1 sell 0.01 EURUSD ok
modify #1 sell 0.01 EURUSD ok
Error trying to set a stop for SEL, error code =0
stop loss #1
open #2 sell 0.01 EURUSD ok
modify #2 sell 0.01 EURUSD ok
Error trying to set a stop for SEL, error code =0
stop loss #2
open #3 sell 0.01 EURUSD ok
modify #3 sell 0.01 EURUSD ok
Error trying to set a stop for SEL, error code =0

enter SELL

RefreshRates();
      if ((OrdersTotal()==0)&&(Bid == Enter))  //бъем до упора эту цену
         { 
            if (IsTradeContextBusy()==false)
               {
                  OrderSend(Symbol(), OP_SELL, Lot, Enter, Slippage, 0, ldTake, lsComm, MAGIC,0, clOpenSell);
                  if (OrdersTotal()>0)
                     {
                        ModifySL();                   //ставим стоп
                        SLBU = OrderOpenPrice()- BU;               //цена БУ
                     }   
                  else Print("Ошибка при попытке установить ордер на SELL, ",OrderOpenPrice()," код ошибки ="+GetLastError());             
               }
         }




modify SELL





void ModifySL() 
   {
      if (OrderSelect(0, SELECT_BY_POS)==true) // Если есть открытый ордер
         {       
            if (OrderType()==OP_BUY)
               {
                  RefreshRates();
                  OrderModify(OrderTicket(),OrderOpenPrice(),Bid- StopL*Point,OrderTakeProfit(),0,Red);
                  if (OrderStopLoss()==0) Print("Ошибка при попытке установить стоп для BUY, ",OrderStopLoss()," код ошибки ="+GetLastError());

               }
                               
            else
                  RefreshRates();   
                  OrderModify(OrderTicket(),OrderOpenPrice(),Ask+ StopL*Point,OrderTakeProfit(),0,Red);
                  if (OrderStopLoss()== 0) Print("Ошибка при попытке установить стоп для SEL, ",OrderStopLoss()," код ошибки ="+GetLastError());
               }
         } 
   }




 
ALex2008 >> :

If you mean this option and it refers to OrderModify

..then I haven't grown to the ticks yet))) How to account for them 1st tick, 2nd tick?

Sleep(2000); // this is a 2 second wait after an error

And how long to wait for a new tick?


at every tick

is called

START()

{

}

---

note that if you're in the START function for a long time

you might miss one or more ticks

e.g. you enter a START function and sit there for 10 minutes, it is logical that ticks will come but you won't catch them

although you may not get a tick for quite a long time at night

---

so sitting in START function for a long time is bad for ticks capturing (if they are important for you)

write economy programs with a minimum of cycles and delays

---

 
YuraZ >> :

...bear in mind that if you're in the START function for a long time

you may well miss one or more ticks

e.g. you have entered the START function and have been there for 10 minutes, it is logical that ticks will come but you will not catch them

although you may not get a tick at night for a long time

---

so sitting in START function for a long time is bad for ticks capturing (if they are important for you)

Write economy programs with a minimum of cycles and delays.

---

If you use the RefreshRates() function before modifying or setting an order, it just updates the state outside of Start(), i.e. ticks?

Do I understand it correctly?

 

Here is the final version of the opening and modification of the pose for critique.

The "+" and "-" of this option?

opening sell

RefreshRates();
      if ((OrdersTotal()==0)&&(Bid == Enter))  //бъем до упора эту цену
         { 
            if (IsTradeContextBusy()==false)
               {
                  OrderSend(Symbol(), OP_SELL, Lot, Enter, Slippage, 0, ldTake, lsComm, MAGIC,0, clOpenSell);
                  if (OrdersTotal()>0)
                     {
                        ModifySL();                   //ставим стоп
                        SLBU = OrderOpenPrice()- BU;               //цена БУ
                     }   
                  else Print("Ошибка при попытке установить ордер на SELL, ",OrderOpenPrice()," код ошибки ="+GetLastError());             
               }
         }




stop modification





void ModifySL()
   {
      if (OrderSelect(0, SELECT_BY_POS)==true) // Если есть открытый ордер
         {       
            if (OrderType()==OP_BUY)
               {
                  RefreshRates();
                  bool Modify = OrderModify(OrderTicket(),OrderOpenPrice(),Bid- StopL*Point,OrderTakeProfit(),0,Red);
                  if ( Modify == false) Print("Ошибка при попытке установить стоп для BUY, ",OrderStopLoss()," код ошибки ="+GetLastError());

               }
            else
               {
                  RefreshRates();   
                  Modify = OrderModify(OrderTicket(),OrderOpenPrice(),Ask+ StopL*Point,OrderTakeProfit(),0,Red);
                  if ( Modify == false) Print("Ошибка при попытке установить стоп для SEL, ",OrderStopLoss()," код ошибки ="+GetLastError());
               }
         }     
   }
Reason: