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

 
artmedia70:

Can't you see the difference? You have the wrong comparison.

if (a && b < c) - you can't do that.

if (a<c && b<c) - you can.



No, I noticed the difference. It's just that I believed it was possible if (a && b < c)... :-)

Now I know, thank you!

 
MarkTrade:


No, I noticed the difference. It's just that I believed it was possible if (a && b < c)... :-)

Now I'll know, thank you!

Maybe you meant if(a+b < c) ? Then you can do it like that!
 
skyjet:


Thanks again! Now tried to make the number of "checkable" bars optimisable, but the results in the window just aren't there. Tried to start counting both from the beginning and the end, but in vain.

extern int number=3;
//------------------------------------+
for (int x=number; x>1; x--) // x>1 (а не x>=1)
{
if(Open[x]==Open[x-1]) continue;
if(Open[x]<Open[x-1])
   {
    //--- action 1
   }
else
   {
    //--- action 2
   }
}

What do you mean by "...no results in the window"? Maybe you are displaying results in the window incorrectly and there is an error elsewhere in the program?

 

Dear Fellows! Please advise if there is any literature (textbooks) on programming lines based on technical analysis, including Fibo levels. It is desirable with examples of program code "for dummies".

Or who can suggest a similar advisor with open source code.

I am grateful in advance.

 
alexey1979621:

Dear comrades! Please advise if there is any literature (textbooks) on programming lines based on technical analysis, including Fibo levels. Preferably with examples of code "for dummies".

I do not know how to use it.

I am very grateful.

What's wrong with this textbook? Whatever you need, study, practice, good luck!
 
artmedia70:
Do you understand and see what is contained in your array immediately after it is "filled" with order data? No. You don't know, you only assume. SPRINT the contents of all array cells, not with your pr(), but with the standard Print() and try to look into the tester log and see what you have in the array, in every cell, right after it is filled. When you know for sure that the contents of the array matches your ideas about its contents, then print it with your pr(). If it doesn't give you the same results - it's your pr(), if the data match, then look for an error in the next step.

Arrays have been printed, but, at the moment, it's not about them. I'll describe what I think below.

By the way. Switched all the outputs to a standard print. The situation is the same. There appears the moment when 4 positions are closed in +. And then logically the isCloseByTakeLastOpenPos() function should work, which I call from the start like this:

 for (int ord=OrdersTotal()-1; ord>=0; ord--)
   {
      if (!OrderSelect(ord,SELECT_BY_POS)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() == 6) continue;
        
      g_ticket = OrderTicket();
      g_type = OrderType();
              
      // Блок модификации ордеров       
      if (i_sl != 0 || i_tp != 0)
      {
         if (OrderStopLoss() == 0 && OrderTakeProfit() == 0)
         {
            OrdersModifyer(g_ticket);
         }
      }
      // Закрытие всех ордеров, если последний ордер закрыт
      if (isCloseByTakeLastOpenPos(2))        // Наша функция, определяющая.. закрылся ли последний закрытый ордер в + или нет.
      {
         // if (g_type < 2)
          {
              ClosePosBySortLots();
          }
          //else
          if (g_type > 1 && g_type < 6)
          {
              DeletePendingOrders(g_ticket);
          }
      }
   }

which will tell us that the last closed order is either closed at take or at profit. Here is the function:

//+-------------------------------------------------------------------------------------+
//| Получаем состояние последней позиции (Открыта или закрыта)                          |
//+-------------------------------------------------------------------------------------+
bool isCloseByTakeLastOpenPos(int delta)
{
   datetime lastOrderCloseTime = -1,               // Время закрытия последнего открытого ордера
            lastOOTHist = -1;                     // Время открытия последнего открытого ордера из истории
   int j = -1;
   Print ("isCloseByTakeLastOpenPos: вошли в функцию");
   
   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;               // Все удалённые отложки нас не интересуют..
      Print ("isCloseByTakeLastOpenPos: первоначальные условия выполнены!");

      if (lastOrderCloseTime < OrderCloseTime())   // Находим время закрытия..
      {
         lastOrderCloseTime = OrderCloseTime();   // ..последней закрытой позиции в истории
         j = i;
         Print ("j = " + j + "   " + TimeToStr(TimeCurrent()));
      }
   }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY))
   {
      if (OrderProfit() + OrderCommission() + OrderSwap() <= 0) return (false);
//      pr ("OTP() = " + OrderTakeProfit() + "; OCP() " + OrderClosePrice() + "   " + TimeToStr(TimeCurrent()));
  //    pr ("OOP() = " + OrderOpenPrice() + "; OCP() " + OrderClosePrice() + "   " + TimeToStr(TimeCurrent()));
      if (MathAbs(OrderTakeProfit() - OrderClosePrice()) > delta * pt) return (false);
      else
      {
         lastOOTHist = OrderOpenTime();
         Comment("\n", "FUNC isCloseByTakeLastOpenPos: ",
                 "\n", "j = ", j,
                 "\n", "lastOOTHist = ", TimeToStr(lastOOTHist, TIME_SECONDS));
      }
   }
   else
   {
      Comment("\n", "FUNC isCloseByTakeLastOpenPos: ",
              "\n", "j = ", j,
              "\n", "не удалось выбрать ордер в истории");
      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);}
   }
   Print ("isCloseByTakeLastOpenPos: последняя закрытая позиция профитна!");
   
   return (true);
}

The situation is interesting. Everything works. And here the situation appears:

We can see that 4 positions closed at take profit. They were closed by Takei. I.e. the functions that closed the orders did not work at all. The reason seems to be that the closing condition did not work. This is:

 if (isCloseByTakeLastOpenPos(2))

When we look at this function and print everything, it becomes clear that it didn't become true at that moment. How so? After all, the outermost 4 orders closed in +. I gave the code of the function above. Here is what is in the log at the same moment:

2013.09.09 00:13:23 2013.08.15 12:35 Perevorot EURUSD.GI,M5: OpenPendingSell(): Ордер послать не удалось 0

2013.09.09 00:13:23 2013.08.15 12:35 Perevorot EURUSD.GI,M5: OpenPendingSell(): Ордер послать не удалось 0

2013.09.09 00:13:23 2013.08.15 12:35 Perevorot EURUSD.GI,M5: OpenPendingSell(): Ордер послать не удалось 0

2013.09.09 00:13:23 2013.08.15 12:35 Perevorot EURUSD.GI,M5: OpenPendingSell(): Ордер послать не удалось 0

2013.09.09 00:13:23 2013.08.15 12:35 Perevorot EURUSD.GI,M5: OpenPendingSell(): Ордер послать не удалось 0

2013.09.09 00:13:04 2013.08.15 12:30 Tester: take profit #104 at 1.32731 (1.32722 / 1.32724)

2013.09.09 00:13:04 2013.08.15 12:30 Tester: take profit #102 at 1.32731 (1.32722 / 1.32724)

2013.09.09 00:13:04 2013.08.15 12:30 Tester: take profit #100 at 1.32731 (1.32722 / 1.32724)

2013.09.09 00:13:04 2013.08.15 12:30 Tester: take profit #98 at 1.32731 (1.32722 / 1.32724)

2013.09.09 00:13:03 2013.08.15 12:30 Tester: order #104, sell 0.93 EURUSD.GI is opened at 1.32831

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: isCloseByTakeLastOpenPos: первоначальные условия выполнены!

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: isCloseByTakeLastOpenPos: первоначальные условия выполнены!

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: isCloseByTakeLastOpenPos: первоначальные условия выполнены!

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: isCloseByTakeLastOpenPos: первоначальные условия выполнены!

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: j = 74 2013.08.15 12:30

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: isCloseByTakeLastOpenPos: первоначальные условия выполнены!

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: isCloseByTakeLastOpenPos: вошли в функцию

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: isCloseByTakeLastOpenPos: первоначальные условия выполнены!

2013.09.09 00:13:03 2013.08.15 12:30 Perevorot EURUSD.GI,M5: isCloseByTakeLastOpenPos: первоначальные условия выполнены!


We can see that the condition has not worked. What is wrong here?

 
Can you tell me if there is an indicator that detects the spread on the whole chart or if it is possible to do this? I have only found an indicator that records the spread when the terminal is switched on from the moment it is connected.
 
paladin80:

What do you mean "...results window is just empty". Maybe you are displaying the results in the window incorrectly and there is an error elsewhere in the program?


But I'm comparing 3,2 and 1 bars, i.e. the calculation is hindered by x >=1?

And does it mean that bars with the same price are simply not considered, they are not assigned numbers?

By setting the optimisation parameters: start 1, step 1, end 4; on H1 and H4 the results tab is simply empty, on D1 the same profitability with different number of bars analysed.

if(Open[x]==Open[x-1]) continue;
 

Professionals can't go anywhere without you.

Help with the function. Which counts the last number of losing orders in the history to a plus order.

I.e., the history shows 3 last orders in minus, then 1 in plus and 2 in minus.

This function should count the last three (before the positive order)

 
skyjet:


But I'm comparing 3,2 and 1 bars, so the calculation is limited to x >=1?

And does it mean that bars with the same price are simply not considered, they are not assigned numbers?

By setting the optimisation parameters: start 1, step 1, end 4; on H1 and H4 the results tab is simply empty, on D1 the same profitability at different number of bars analysed.

Perhaps what I understood from your question is different from what you meant. My example compares the opening prices between 3 and 2 bars, and 2 and 1. Bars 3 and 1 are not compared. In case the compared values are equal - nothing happens, just passes to the next comparison.
Why x>1 (not >=). The first iteration compares Open[3]==Open[3-1], i.e. Open[3]==Open[2]. OK. At the second (x=2), Open[2]==Open[1]. OK. There is no third iteration. At x>=1 there will be a comparison Open[1]==Open[0], it is not OK, because there will be a comparison with 0 bar.
Reason: