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

 

I want to ask you, dear programmers, please explain me in Russian how to search for past indicator readings with the code. For example stoploss when selling I need to put on 3 High ZigZag from the zero bar, or over the eighth upper fractal. wherever I read - either not that, or written not so :)

 
Petiyashaket:

I want to ask you, dear programmers, please explain me in Russian how to search for past indicator readings with the code. For example stoploss when selling I need to put on 3 High ZigZag from the zero bar, or over the top eighth fractal. wherever I read - either not that, or written not so :)

The loop from the zero bar to the beginning of the chart, int x=0. In the loop, call the required indicator, for example, fractal. If the value is not empty, add 1 to x, when x reaches the desired value - memorize the loop iteration and exit the loop, the value of the iteration will theoretically be the number of the bar where the desired fractal is located. Theoretically because while the cycle is running one more bar can appear on M1 and then pointer will be shown to a wrong bar )))
 
evillive:
Cycle from zero bar to the beginning of the chart, int x=0. In the cycle call the required indicator, for example, fractal. If the value is not empty, add 1 to x, when x reaches the required value - remember the loop iteration and exit the loop, the iteration value will theoretically be the number of the bar where the required fractal is located. Theoretically, because when the loop is running, one new bar can appear on M1 and then pointer will be shown to a wrong bar)))
The time must be saved. Or, better yet, use the array where the time of formation of the last fractals is stored. The work speed will be reduced due to elimination of unnecessary loops
 
Petiyashaket:

Please, explain me in Russian how to search for the past indicator readings in the code? For example stoploss on the sale I need to put on 3 High ZigZag from the zero bar, or the top eighth fractal, wherever I read - or not something, or written not so :)

"Russian language" and "programming language" (want a code explanation) are not the same thing.

Algorithmically:

1) Define what value the ZigZag of interest returns, if it has no "fractal point" - it can be EMPTY_VALUE or 0.0.

2) Using iCustom() in the loop, obtain the value of the corresponding buffer indicator on the bar being checked in the loop, check it for difference from the "empty value" and keep a counter of those differences. When the counter is equal to 3 in your case - the number (N) of the bar will be the desired bar;

3) High[N]\Low[N] - will be the required level.

For the standard ZigZag High we are looking for something like this:

#define  ZZ_NULL  0.0

    uint li_N = 0, li_Bar = 1;
    double ld_ZZ = 0.;
//----
    while (li_Bar < Bars - 1)
    {
        ld_ZZ = iCustom (_Symbol, _Period, "ZigZag", /* внешние параметры индикатора */, 1, li_Bar);
        if (ld_ZZ != ZZ_NULL)
        {
            li_N++;
            if (li_N >= 3) break;
        }
        li_Bar++;
    }
    double ld_Price = High[li_Bar];

But before that, we have to change the number of displayed buffers in ZigZag code from 1 to 3:

#property indicator_buffers 3
 

Thanks for the answers, I will get back to them :) now the problem is

http://clip2net.com/s/j7xvk9

I can't figure out why it does not modify the order, but just opens new pending orders

 
Petiyashaket:

Thanks for the answers, I will get back to them :) now the problem is

http://clip2net.com/s/j7xvk9

I can't figure out why it does not modify the order, but just opens new pending orders

 
evillive: Thanks for showing :)
  double Up=iFractals(Symbol(),0,MODE_UPPER,3);           //верхний фрактал
  double Down=iFractals(Symbol(),0,MODE_LOWER,3);         //нижний фрактал
//----
  if(Up>0&&Down==0&&Volume[0]<2) //если верхний есть а нижнего нет то:
    {
    if((High[3]+5*Point-Ask)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL)) //если цена позволяет выставить отложенный ордер то:
    OrderSend(Symbol(),OP_BUYSTOP,Lot,High[3]+5*Point,20,High[3]-sl,High[3]+tp,NULL,Magic,0,Green); // то выставляем байстоп на 5 пунктов выше верхнего фрактала
        {
        for (int pos=0;pos<OrdersTotal();pos++) //     скопировал эту строчку хз откуда ибо не понимаю грёбаный счетчик :) тут видимо и косяк
        OrderSelect(pos,SELECT_BY_POS,MODE_TRADES); // ищем текущие ордера
        if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol()&&OrderType()==OP_BUYSTOP)// и если все условия совпадают то:
          {
          OrderModify(OrderTicket(),Up+5*Point,Up-sl,Up+tp,0,CLR_NONE);//переносим байстоп на новый верхний фрактал
          }


 
Petiyashaket:
Thanks for showing :)
What is it complaining about in the modification log? "Stupidly opens new pending orders" because there is no limit, but there is an OrderSend.
 
Petiyashaket:

1) Any strategy must be defined by the number of orders open at the same time. Accordingly, before opening the next order, we should check how many are already open.

2) On one bar, there cannot be UPPER and LOWER fractals at the same time, respectively, the check is classified as

    if (Up > 0 && Down == 0)

belongs to the category of programmer's idiocy.

3) Before writing the conditions for returning buffer indicator values, you need to know exactly what value is "empty" for it? Have you checked that it is 0?

4) The construct.

    if (Volume[0] > 2)

Although it will work (in most cases), but is unnatural, because it is a "free-will" idea of the developer, and is uninformative for the trader. An alternative - the tracking of a new bar.

5) You have to start from the basics, because this:

    OrderSend(Symbol(),OP_BUYSTOP,Lot,High[3]+5*Point,20,High[3]-sl,High[3]+tp,NULL,Magic,0,Green); // то выставляем байстоп на 5 пунктов выше верхнего фрактала
        {

Indicates that you don't understand what you're writing at all.

The best way to understand is to study how other people's codes work and modify them for your own purposes. Good luck.

 
TarasBY:

2) There cannot be UPPER and LOWER fractals on the same bar at the same time, respectively, check

belongs to the category of programmer's idiocy.

So these quotes are only for idiots.


Reason: