[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 242

 
Hello, how do I write a robot (which topics in the tutorial should I use so I don't have to read everything) that opens a buy order with a trailing stop, and if the trailing stop triggers, it also opens a new one (i.e. it gets double lot in trailing stop), but when the stop triggers, a new trailing stop is placed.
 

Question how to calculate a series of losing orders ????

I want to know how many orders in a row closed at a stop to test the tactic... and especially the last

Guys, I really need it .....

 
VOLDEMAR:

Question how to calculate a series of losing orders ????

I want to know how many orders in a row closed at a stop to check tactics... and especially the last

Guys, I really need it .....


This is how I calculate it for me:

Iteration = how many times an order in a row has closed at a stop if a stop in your sense is a loss-making close.

 //---------------------расчет по истории ордеров номера очередной итерации----------------------------------------------- 
  Iteration = 0; // зануляем инерации перед их учетом в цикле по истории
  Sum_Loss = 0;  // суммарный убыток по этим итерациям

datetime 
Time_at_History_Current = 0,
Time_at_History_Previos = 0;     
 
 if(OrdersHistoryTotal() != 0)
   {
    for(int counter = OrdersHistoryTotal()-1; counter >= 0; counter--)
      {
       OrderSelect(counter, SELECT_BY_POS, MODE_HISTORY);
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         {
          if(OrderType() == OP_BUY || OrderType() == OP_SELL)
            {
             if(OrderProfit() < 0) // если убыток по выбранному ордеру, то считаем суммарный и записываем время закрытия ордера
                                   // для последующего его анализа при подсчете количества итераций
                {
                 double lastLoss = OrderProfit();
                 Sum_Loss=Sum_Loss+lastLoss;  // считаем общий убыток по закрытым подряд убыточным ордерам
                 Time_at_History_Current = OrderCloseTime();
                } 
             
             //Print(" Time_at_History_Current_в цикле = ", TimeToStr(Time_at_History_Current, TIME_DATE|TIME_SECONDS));
             //Print(" Time_at_History_Previos_в цикле = ", TimeToStr(Time_at_History_Previos, TIME_DATE|TIME_SECONDS));
             
             if(Time_at_History_Current != Time_at_History_Previos) // если они не равны, то считаем итерации и делаем их равными
               {
                Time_at_History_Previos = Time_at_History_Current ;
                Iteration++;
                //Print("Iteration at History в условии сравнения  = ",  Iteration);
               }   
             else // они равны, то проверяем, дополнительно, наличие профита по выбранному следующему ордеру и выходим из цикла
               {
                if(OrderProfit() >= 0)
                  break;
               }
            }
         }
      }
   }
 
Thanks ! But as I understand it this code finds the whole series in history whether it was 100 trades ago or 5 ....
 
VOLDEMAR:
Thanks ! But as I understand it, this code finds the whole series in the history regardless of whether it was 100 trades ago or 5 .....

No. The selection from the closest closed one goes deep into the history, and when a closed one turns into a profit, the series is interrupted with the output of the number of consecutive losing trades = Iteration.
 

Good afternoon.

Would this be the right combination?

  // заполним значениями сигнальные массивы и посчитаем их количество
  for(i=DisplayBars;i>=0;i--) 
  {

    
if (Prz0 == 0) 
       {
           f= GetBarNumWithZerroDist(i);// на этом баре пересечение
        if (f!=-1)
          {
           Price01 = iClose(Symbol_1,0,f);
           Price02 = iClose(Symbol_2,0,f);
           Prz0 = 1;
           i=f;
           }
       } 
   }
int GetBarNumWithZerroDist(int i)
{
double Smb1Cl0 = NormalizeDouble(iClose(Symbol_1,0,0),Digits);
double Smb2Cl0 = NormalizeDouble(iClose(Symbol_2,0,0),Digits2);
double Smb1Pnt = MarketInfo(Symbol_1, MODE_POINT);
double Smb2Pnt = MarketInfo(Symbol_2, MODE_POINT);
int    mBars   = MathMin(iBars(Symbol_1,0), iBars(Symbol_2,0));

    for (int f=i;f>=0;f--) 
    {
        Price1 =   NormalizeDouble(Lot*(Smb1Cl0 - iClose(Symbol_1,0,f)) / Smb1Pnt,0);
        Price2 = NormalizeDouble(K*Lot2*H*(Smb2Cl0 - iClose(Symbol_2,0,f)) / Smb2Pnt,0);
        Spread = Price1 - Price2; 
        //Print ("Price1="+Price1, " Price2="+Price2);
        if(MathAbs(Spread)== 0) return(f);
    }
    return(-1);
}
 

I liked this one:)

if(MathAbs(Spread)== 0) return(f);
 
Roger:

I like this one:)


is there an error here ?

I need to return the value of the bar where Spread==0,

If no such value is found, return -1.

 

Hello.

Question: can OrderSend() return a value of "0", or less than "-1" after execution? Has anyone encountered anything like this? Or is the information given in the "documentation" correct:

int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
Basic function used to open a position or set a pending order.
Returns the ticket number that is assigned to the order by the trade server, or -1 in case of failure.
P.S.: working as a Telepath, looking for an error in someone else's code...
 
I made a virtual trawl with horizontal lines, in the tester it works fine, but during optimisation the tester apparently does not work with these lines, why?
Reason: