Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 65

 

Good day to you all! If i've tried to place a stop loss on a trawl, i have not seen this problem in the Strategy Tester. When in the Strategy Tester when the EA should place a Stop Loss it does not however it does periodically, but I have not found any regularities and therefore the accuracy of the test suffers considerably. The same Expert Advisor on the demo deposit shows that the trawl works. The terminal does not report any errors. Is this a bug in the code or a bug in the terminal? Can you help me understand it? I have tried all the code and do not understand what's wrong, I do not want to change the trail strategy. I attached the full code of Expert Advisor and below is the code of trawl (slightly modified trailing on candlestick shadow by Yury Dzyuban)

void TrailingByShadows(int ticket,int tmfrm,int bars_n, int indent) {  
   int i;
   double new_extremum;

   if ((bars_n<1) || (indent<0) || (ticket==0) || ((tmfrm!=1) && (tmfrm!=5) && (tmfrm!=15) && (tmfrm!=30) && (tmfrm!=60) && (tmfrm!=240) && (tmfrm!=1440) && (tmfrm!=10080) && (tmfrm!=43200)) || (!OrderSelect(ticket,SELECT_BY_TICKET))) {
      Print("Трейлинг функцией TrailingByShadows() невозможен из-за некорректности значений переданных ей аргументов.");
      return(0);
   } 
   if (OrderType()==OP_BUY) {
      for(i=1;i<=bars_n;i++) {
         if (i==1) new_extremum = iLow(Symbol(),tmfrm,i); else if (new_extremum>iLow(Symbol(),tmfrm,i)) new_extremum = iLow(Symbol(),tmfrm,i);
      }  
  
      if ((((new_extremum - indent*Point)>OrderStopLoss() + 1.0 * Point) || (OrderStopLoss()==0)) && ((new_extremum - indent*Point)>OrderOpenPrice()) && (new_extremum - indent*Point<Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) && (getLots(new_extremum) > 0))
      if (!OrderModify(ticket,OrderOpenPrice(),new_extremum-indent*Point,OrderTakeProfit(),OrderExpiration()))
         Print("Не удалось модифицировать ордер №",OrderTicket(),". Ошибка: ",GetLastError());
   }
   if (OrderType()==OP_SELL) {
      for(i=1;i<=bars_n;i++) {
         if (i==1) new_extremum = iHigh(Symbol(),tmfrm,i); else if (new_extremum<iHigh(Symbol(),tmfrm,i)) new_extremum = iHigh(Symbol(),tmfrm,i);
      }         
      if ((((new_extremum + (indent + MarketInfo(Symbol(),MODE_SPREAD))*Point)<OrderStopLoss() - 1.0 * Point) || (OrderStopLoss()==0)) && ((new_extremum + (indent + MarketInfo(Symbol(),MODE_SPREAD))*Point)<OrderOpenPrice()) && (new_extremum + (indent + MarketInfo(Symbol(),MODE_SPREAD))*Point>Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) && (getLots(new_extremum) > 0))
      if (!OrderModify(ticket,OrderOpenPrice(),new_extremum + (indent + MarketInfo(Symbol(),MODE_SPREAD))*Point,OrderTakeProfit(),OrderExpiration()))
         Print("Не удалось модифицировать ордер №",OrderTicket(),". Ошибка: ",GetLastError());     
   }      
}

double getLots(double newSL) {
   int opnTime = 0; // время открытия трейда для цикла пересчета позиций
   double lotSum = 0; 
   for (int i = 0; i <= OrdersTotal()-1; i++) {
      OrderSelect(i, SELECT_BY_POS);     
      if ((OrderOpenTime() > opnTime) && (OrderType() == OP_BUY) || (OrderType() == OP_SELL)) { 
         opnTime = OrderOpenTime(); 
         if (OrderType() == OP_BUY)    { lotSum += OrderLots() * (newSL - OrderOpenPrice()) / Point; }
         if (OrderType() == OP_SELL)   { lotSum -= OrderLots() * (newSL - OrderOpenPrice()) / Point; }
      }
   }   
   return(lotSum);
}
Files:
avalanche.mq4  12 kb
 
What timeframe do you test on and with what quality?
 

EURUSD, M1, 99%, 90%

At first I used standard tick history, loaded with MT, I have found this problem, as well as unexplainable gaps in quotes history, so I have switched to Tick Data Suite, I downloaded quotes from Dukascopy, the quality increased from 90 to 99, but the problem persists.

ZS: Probably the same situation in real life, or I didn't test long enough (about 3 weeks), during that period I had to close manually several times because trawl was not installed, but I thought it was because I had to disconnect terminal machine periodically and it somehow affected EA operation, recently moved it to VPS maybe a week ago and now seems to be drawing the same situation

 

Is the test performed on a timeframe that is equal to the value of tmfrm variable or not?

if not, you should make sure that there is a history on the tmfrm timeframe...

and the number of tanks transmitted in the variable bars_n corresponds to the timeframe transmitted in the variable tmfrm ?

 
keekkenen:

Is the test performed on a timeframe that is equal to the value of tmfrm variable or not?

if not, you should make sure that there is a history on the tmfrm timeframe...

and the number of tanks passed in the variable bars_n corresponds to the timeframe passed in the variable tmfrm ?


Yes, I guess you're right, I've neglected the code of someone else's function, didn't look into it deeply and didn't take that parameter into account. As a result, the stop loss was set for a different period. Thank you for your help.

ZS: That's always how it is: some little thing makes the code not work the way I'd like it to.

 

Good afternoon! Who knows what the hell is going on with the red brick in the log!

2013.08.05 08:00:41 '9291791': Signal - not found update signal - 7400 in base

There's nothing wrong with my code! And with signals too! What does this mean?

 
Mepkypuu:


Yes, it looks like you're right, I neglected the code of someone else's function, didn't go into it in detail and didn't take this parameter into account. As a result, the stop loss was set for a different period. Thank you for your help.

ZS: It's always like this: some little thing makes the code not work the way I'd like it to.


I was happy about it too early, trailing has started to work better, but on the history there are still cases when it does not work, i.e. the problem is only partially solved.
 
splxgf:

Do you fix the spread? Because during runs the current spread is taken, but during the news and in the evening it differs from the daily spread.

How do you fix the spread? After all, OrderSend specifies either Ask or Bid.
 
Mepkypuu:

I am not happy about it yet, trailing is working better, but there are still cases when it does not work, i.e. the problem is only partially solved.

What you call Trailing is not really Trailing, it is calculated in a different way and its behaviour can be illogical.
 
Leo59:

How can the spread be fixed? After all, OrderSend specifies either Ask or Bid.
In the tester under the TF!
Reason: