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

 
artmedia70:
Where in this function do you read the StopLoss of the last closed? There's nothing there.

It's right here. Directly pointed.
OrderSelect(1,SELECT_BY_POS,MODE_HISTORY);
      take=OrderTakeProfit();
       ts=take;
 
borilunad:
Go to sleep, everyone! It's always better in the morning! It's 1:00 in the morning! Good night! And Artyom has already slept in!

I've been doing what you're doing for five days now, and I've already started thinking at night. Good night.
 
Ooh! Error 130 appears in the logbook. These are the wrong stops, aren't they? BUT the new stop loss is 1.3282. The stop loss at the current moment is 1.3275 (this is also the opening price of the order) and the current quote is 1.3297. Where is the mistake?
 

Hello. Why in the predefined variable "Point", are zeros not defined in the strategy tester log, at the end, round numbers?

Пример:

static double lBUY;

lBUY=100*Point; //Так-же можно написать 10,20,180 или 520.

if(lBUY==0.01)

{

Alert("НУЛИ НЕ ПИШУТСЯ В КОНЦЕ Point ",lBUY);

}

 
artmedia70:
I'm a Siberian, yeah. Near Krasnoyarsk.


Sibiryak, so, almost, zamlYak)).
 
webip:

But I've been doing what you're doing for five days and I've already started thinking at night.

It's easier to say who doesn't think at night, if it's the other way around. I have the same situation. Besides, nobody bothers me at night at all. By the way, I read once that, like, the brain thinks better at night. It's like scientists found out...
 
semiromid:

Hello. Why in the predefined variable "Point", are zeros not defined in the strategy tester log, at the end, round numbers?

Пример:

static double lBUY;

lBUY=100*Point; //Так-же можно написать 10,20,180 или 520.

if(lBUY==0.01)

{

Alert("НУЛИ НЕ ПИШУТСЯ В КОНЦЕ Point ",lBUY);

}



And what does Alert actually output?
 
artmedia70:
DoubleToStr(number,digit) is for you


Thank you very much! I needed it to compare candle characteristics (more, less, etc.) I screwed it on - it works. Only can not understand how it compares the data type string? Or double to string does not translate number to string? :-D


PS. It doesn't work in indicator - only in script... When I call High[i] - only 4 decimal places will appear.

I'm writing:

Alert ("doubletostr High = ", DoubleToStr(High[1],5));
if (DoubleToStr(High[2],5)>(DoubleToStr(High[3],5))
{
Alert ("More");
}
if (DoubleToStr(High[2],5)<(DoubleToStr(High[3],5))
{
Alert ("Smaller");

}

Works, it writes the result with five digits, over/under counts. The problem is that in the indicator the string array doesn't show up on the chart. Therefore...

...writing:

Alert ("Normalized Double High = ", NormalizeDouble(High[1],5));

Doesn't work - the result is > 1,1234

I do not understand the developers - why did they have to complicate things so much? Why if it shows so many digits on the chart, it won't scratch the called function with five digits? Maybe there is a simple solution?

 

I'm struggling with a function that should return True if the last market position was closed at a profit, and False if it was not closed at a loss. If this function returns True, then all positions (both pending and market ones) are closed.

Here's what came out:

//+-------------------------------------------------------------------------------------+
//| Получаем состояние последней позиции (Открыта или закрыта)                          |
//+-------------------------------------------------------------------------------------+
bool isCloseByTakeLastOpenPos(int delta)
{
   datetime lastOrderCloseTime = 0,               // Время закрытия последнего открытого ордера
            lastOOTHist = -1;                     // Время открытия последнего открытого ордера из истории
   
   for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() > 1) continue;               // Все удалённые отложки нас не интересуют..
  
      if (lastOrderCloseTime < OrderCloseTime())   // Находим время закрытия..
      {
         lastOrderCloseTime = OrderCloseTime();   // ..последней закрытой позиции в истории
         int j = i;
      }
   }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY))
   {
      if (OrderProfit() + OrderCommission() + OrderSwap() <= 0) return (false);
      if (MathAbs(OrderProfit() - OrderClosePrice()) > delta * pt) return (false);
      else
      {
         lastOOTHist = OrderOpenTime();
         Comment("FUNC isCloseByTakeLastOpenPos : lastOOTHist = ", lastOOTHist);
      }
   }
   else
   {
     // Comment("FUNC isCloseByTakeLastOpenPos : не удалось выбрать ордер в истории");
      Print("FUNC isCloseByTakeLastOpenPos : не удалось выбрать ордер в истории");
      return(false);
   }
  
   for(int h=OrdersTotal()-1; h>=0; h--)
   {
      if (OrderSelect(h, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderMagicNumber() != i_magic)   continue;
         if (OrderSymbol() != Symbol())       continue;
         if (OrderType() > 1)                 continue;
         if (lastOOTHist < OrderOpenTime()) return(false);  // Выбранная рыночная позиция открыта позже закрытой по тейку
      }
      else {Print("FUNC isCloseByTakeLastOpenPos : не удалось выбрать рыночный ордер");return(false);}
   }
   
   return (true);
}

Artyom above suggested where I had a bug. I rewrote it for me. It's not the final variant yet, but... it's already quite clear. After I ran the Expert Advisor, I noticed at once that remaining positions were not closed and are not being closed at all. I started digging out what was the reason. I have recommended a couple of functions and realized that it is in this block:

 if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY))
   {
      if (OrderProfit() + OrderCommission() + OrderSwap() <= 0) return (false);
      if (MathAbs(OrderProfit() - OrderClosePrice()) > delta * pt) return (false);
      else
      {
         lastOOTHist = OrderOpenTime();
         Comment("FUNC isCloseByTakeLastOpenPos : lastOOTHist = ", lastOOTHist);
      }
   }
   else
   {
      Comment("FUNC isCloseByTakeLastOpenPos : не удалось выбрать ордер в истории");
      Print("FUNC isCloseByTakeLastOpenPos : не удалось выбрать ордер в истории");
      return(false);
   }

The comment is triggered all the time exactly:

Comment("FUNC isCloseByTakeLastOpenPos : не удалось выбрать ордер в истории");

I commented it out, drove on. Noticed that this comment:

Comment("FUNC isCloseByTakeLastOpenPos : lastOOTHist = ", lastOOTHist);

Never triggers at all, even when there is a closed position last. What could be wrong?

My thoughts, although I may be wrong... Maybe you need to put this block

 if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY))
   {
      if (OrderProfit() + OrderCommission() + OrderSwap() <= 0) return (false);
      if (MathAbs(OrderProfit() - OrderClosePrice()) > delta * pt) return (false);
      else
      {
         lastOOTHist = OrderOpenTime();
         Comment("FUNC isCloseByTakeLastOpenPos : lastOOTHist = ", lastOOTHist);
      }
   }
   else
   {
     // Comment("FUNC isCloseByTakeLastOpenPos : не удалось выбрать ордер в истории");
      Print("FUNC isCloseByTakeLastOpenPos : не удалось выбрать ордер в истории");
      return(false);
   }

put it in the for loop as well? Otherwise, who knows in what direction the overflow will go. The j variable will contain the index number of the position and it's not explicitly specified in which direction the search will go.

 
hoz:

I'm struggling with a function that should return True if the last market position was closed at a profit, and False if it was not closed at a loss. If this function returns True, then all positions (both pending and market ones) are closed.

Here's what came out:

Artyom above suggested where I had a bug. I rewrote it for me. It's not the final variant yet, but... it's already quite clear. After I ran the Expert Advisor, I noticed at once that remaining positions were not closed and are not being closed at all. I started digging out what was the reason. I recommended a couple of functions and realized that the reason is in this block:

The comment is triggered all the time exactly:

I commented it out, drove on. Noticed that this comment:

Never triggers at all, even when there is a closed position last. What could be wrong?

My thoughts, although I may be wrong... Maybe you need to put this block

put it in the for loop as well? Otherwise, who knows in what direction the overflow will go. The j variable will contain the index number of the position and it's not explicitly specified in which direction the search will go.

The variable j must be explicitly initialised at the beginning of the function with a negative value. Try it. I haven't looked any further yet.