[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 66

 
Fox_RM:
Good afternoon!
I have encountered a problem with opening a certain (user-defined) number of orders.
I have written a small code to solve this problem.
But there are times when an arbitrary number of orders is opened, usually near the end of the test.

Below is the code itself.

If you have a simpler solution, I would be glad to receive comments.


This is probably better.

extern string Kolichestvo_orderov = "Количество единовременно открытых ордеров";
extern int OrederBuy = 1;
extern int OrederSell = 1;


int OrdS,OrdB,ticketBuy,ticketSell,lastticketSell=0,lastticketBuy=0;
//========================================================================================================//
                                //Подсчет количества ордеров BUY & SELL//
//========================================================================================================//
    for(int i = OrdersTotal()-1; i>=0; i--)
       {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
        if(OrderType()==OP_BUY)
            {
            OrdB++
            }
        if(OrderType()==OP_SELL)
            {
            OrdS++
            }
          }
       }   
//========================================================================================================//     
                                  //---- Открытие ордеров SELL ----//
//========================================================================================================//

  if(OrdS<=OrederSell)
    { //----- start 
    if(trendDn==true && SthFast>88.2 && SthSlow<38.2)
       {
      ticketSell=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,0,magick,0,Blue); //--- Если ордер открыт параметр OrdS увеличиваю 
       }
     } //-----end
          
//========================================================================================================//  
                                   //----Открытие ордеров BUY ----//
//========================================================================================================//  

   if(OrdB<=OrederBuy)
     { //-----start
     if(trendUp==true && SthFast<11.8 && SthSlow>61.8)
        {
        ticketBuy=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,0,magick,0,Red); //--- Если ордер открыт параметр OrdB увеличиваю
        }
      } //------end
//========================================================================================================//  
 
Lians:
Thanks, but it's a bit complicated for me, and your function outputs 4 messages at once, while I need one. It turns out no more than 64 characters in one line?

No. You take your long message and divide it into as many parts as you can read on the screen, but no more than four. The main thing is that each part should not exceed 64 characters. If your message is short, you can pass it to a function in one part.

Look, I've attached a tipster in the trailer to test this function. Run it in the tester in visual mode and put Win_Inform indicator on the visualization chart (it is in my previous message in the trailer). You will immediately see how this function works.

Files:
 
r772ra:


That's probably better.

This is about the code I used to start upgrading mine. There are 3 problems in your version:

- as soon as OP_BUY and OP_SELL orders are opened, the OrdB and OrdS parameters will automatically increase on every tick, so I added the recalculation condition only on the change of the corresponding tick (sell or buy);

- the recalculation of all orders leads to the error OrdB and Ord, we need only the last change in orders to be considered;

- in your version there is no decrease of parameters OrdB and Ord for further opening of orders if (OrdB<=OrederBuy),if(OrdS<=OrederSell).

That seems to be the case.

 
Fox_RM:

This is about the code I used to start upgrading mine. There are 3 problems in your version:

- as soon as OP_BUY and OP_SELL orders are opened, the OrdB and OrdS parameters will automatically increase on each tick, so I added the recalculation condition only on the change of the corresponding tick (sell or buy);

- the recalculation of all orders leads to the error OrdB and Ord, we need only the last change in orders to be considered;

- in your version there is no decrease of parameters OrdB and Ord for further opening of orders if (OrdB<=OrederBuy),if(OrdS<=OrederSell).

It seems to be the same.

Right, we need to zeroize the counters of orders before the for loop

//========================================================================================================//
                                //Подсчет количества ордеров BUY & SELL//
//========================================================================================================//
     OrdS=0;
     OrdB=0;
    
    for(int i = OrdersTotal()-1; i>=0; i--)
       {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
        if(OrderType()==OP_BUY)
            {
            OrdB++
            }
        if(OrderType()==OP_SELL)
            {
            OrdS++
            }
          }
       }   


 

Good afternoon! Please help me understand the function from Kim:

 
double FindNearFractal(string sy="0", int tf=0, int mode=MODE_LOWER) {
 if (sy=="" || sy=="0") sy=Symbol();
  double f=0;
  int d=MarketInfo(sy, MODE_DIGITS), s;
  if (d==0) if (StringFind(sy, "JPY")<0) d=4; else d=2;
 
  for (s=2; s<100; s++) {
    f=iFractals(sy, tf, mode, s);
    if (f!=0) return(NormalizeDouble(f, d));
  }
  Print("FindNearFractal(): Фрактал не найден");
  return(0);
}

I don't understand the line

if (d==0) if (StringFind(sy, "JPY")<0) d=4; else d=2;

Why there are no signs after the first if, what happens when an expression is written like this. What does StringFind do, and why is the string searched by JPY? How can d = 0, and in which case 2 is assigned and in which 4? I will be very grateful for the answer, thanks in advance)))

 
r772ra:

That's right, before the for loop, you have to reset the order counters to zero

)) For some reason I didn't think of that myself and started fumbling.
 
Fox_RM:
)) For some reason I didn't think of that myself, started to get winded.

Good riddance.
 
Lisi4ka330: why there are no signs after the first if, what happens if the expression is written like this... How can d = 0, and in which case 2 is assigned and in which 4? I would be very grateful for an answer, thanks in advance)))

I think this makes more sense

if (d==0)
{ 
  if (StringFind(sy, "JPY")<0)
  {
    d=4;
  } 
  else
  {
    d=2;
  }
}

d - quotation accuracy (digits after the decimal point)

if there is a JPY pair, then the rate for the majors is xxx.xx

if there is no JPY in the pair, then the rate for the majors will be x.xxxx (hence the name "four digits")

 
r772ra:

Yes right, before the for loop, we need to reset the order counters to zero


I have missed another point:

- in your version, there is no decrease of parameters OrdB and OrdS for further opening of ordersif (OrdB<=OrederBuy),if (OrdS<=OrederSell).

In the new version, we have, for example, opened 5 orders, recalculated them, but the if condition won't let us open any more orders. In my old variant, OrdB-- and OrdS--

were used.

 
GaryKa:

I think this makes more sense

d - quotation accuracy (digits after the decimal point)

if there is a JPY pair, then the rate for the majors is xxx.xx

if there is no JPY in the pair, then the rates for the majors are approximately x.xxxx (hence the name "four digits")

GaryKa, thanks for the answer, it's a little unclear how d can be 0, because the function
 d=MarketInfo(sy, MODE_DIGITS)
returns the number of decimal places, so d will always be greater than 0 and the condition will always be false