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

 
waroder:


as I understood it (hopefully correctly:)) Zolotai wants to take data from two loop statements and write them to text files. From each one to a separate file. Then he wants to load the data from these files into arrays. Then these two arrays should be joined into one array so that the data from two operators are not mixed and correlated with each other by each bar.

like this))))

Why do we need to merge the data into a multidimensional array? The first dimension is indexed by time (bars) - the rest are array data. And sort all the data in the first dimension any way you want.
 

People, I need help, the code below is executed only the second part, when sellstop should be set, and buystop for some reason is not set, although all conditions are met, I can not even see what's wrong))

if (OrdersTotal()==2)

{

OrderSelect(2,SELECT_BY_TICKET);

if (OrderType()==OP_SELL)

{

OrderSelect(2,SELECT_BY_TICKET);

double b = OrderOpenPrice();

OrderSend(Symbol(),OP_BUYSTOP,2,b+28*Point,3,b-25*Point,b+50*Point,0,5);

}

OrderSelect(4,SELECT_BY_TICKET);

if (OrderType()==OP_BUY)

{

OrderSelect(4,SELECT_BY_TICKET);

double a = OrderOpenPrice();

OrderSend(Symbol(),OP_SELLSTOP,2,a-28*Point,3,a+25*Point,a-50*Point,0,6);

}

}

 

Well, since you know for sure that order number 2 is a sell order, all you have to do is normalise the price, stop and take.

And watch the EA logs.

 

Hello, Can you advise me please - I am looking for an owl or a script:

There is an order level there is a stop and 3 takeprofits, it is necessary that when a certain level is reached for example the first tr order is closed by a certain part (set by myself) and the remaining part is transferred to a level that I also set myself..:

Example

order at 1.5800 stop 1.5750 1 position - 1.5850 2 points - 1.5900 3 points - 1.5950, so when the order reaches 1.5850 let us assume 40% of the lot is closed, the rest at 1.5800 (ie in bu) to 2 points 20% and the rest is transferred to 1.5850 and 3 points are closed completely.

The most important thing is to be able to change the values myself depending on the situation.

 
zaqwsx123:

People, I need help, the code below is executed only the second part, when sellstop should be set, and buystop for some reason is not set, although all conditions are met, I can not even see what's wrong))

if (OrdersTotal()==2)

{

OrderSelect(2,SELECT_BY_TICKET);

if (OrderType()==OP_SELL)

{

OrderSelect(2,SELECT_BY_TICKET);

double b = OrderOpenPrice();

OrderSend(Symbol(),OP_BUYSTOP,2,b+28*Point,3,b-25*Point,b+50*Point,0,5);

}

OrderSelect(4,SELECT_BY_TICKET);

if (OrderType()==OP_BUY)

{

OrderSelect(4,SELECT_BY_TICKET);

double a = OrderOpenPrice();

OrderSend(Symbol(),OP_SELLSTOP,2,a-28*Point,3,a+25*Point,a-50*Point,0,6);

}

}

Ticket #2, as well as #4, can only appear in the tester. This is utopia on the real/demo. When selecting an order on a ticket, you should first make sure that the order is selected at all, then check the time of its closing. If it is == 0, this means that the order has been selected from the list of market orders. If the order close time is > 0, it means that the order has already been closed and is selected from the list of closed orders. When sending a trade request to the server, all prices must first be up-to-date (the most recent; to do this, prices must be obtained via MarketInfo() or RefreshRates() before sending the request), and secondly, all prices must be normalized to the exact digits
 
Villcommen:

Hello, Can you advise me please - I am looking for an owl or a script:

There is an order level there is a stop and 3 takeprofits, it is necessary that when a certain level is reached for example the first tr order is closed by a certain part (set by myself) and the remaining part is transferred to a level that I also set myself..:

Example

order at 1.5800 stop 1.5750 1 position - 1.5850 2 points - 1.5900 3 points - 1.5950, so when the order reaches 1.5850 let us assume 40% of the lot is closed, the rest at 1.5800 (ie in bu) to 2 points 20% and the rest is transferred to 1.5850 and 3 points are closed completely.

The most important thing is to be able to change the values myself depending on the situation.

Have you looked in the catbase?
 

Guys, tell me about this shit!!! When I create a new indicator, I always have a problem with the output of the buffer to the chart. I seem to have written everything correctly, but the values do not show any.... I'm already exhausted....

#property copyright "nikelodeon"
#property link      ""
extern int k=5;
extern int k1=8;

#property indicator_chart_window
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double Buffer8[];
int init()
  {
SetIndexBuffer(0,Buffer2);         // Назначение массива буферу
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2,Red);// Линия
SetIndexBuffer(1,Buffer1);// Назначение массива буферу 
SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,2,Blue);// Линия
SetIndexStyle (2,DRAW_ARROW,STYLE_SOLID,1,Red);
SetIndexArrow (2,159);// Стиль линии 
SetIndexBuffer(2,Buffer3);
SetIndexEmptyValue(2,0.0);// Назначение массива буферу
SetIndexStyle (3,DRAW_ARROW,STYLE_SOLID,1,Blue);
SetIndexArrow (3,159);// Стиль линии 
SetIndexBuffer(3,Buffer4);// Назначение массива буферу 
SetIndexEmptyValue(3,0.0);
SetIndexStyle (4,DRAW_ARROW,STYLE_SOLID,2,Green);
SetIndexArrow (4,159);// Стиль линии 
SetIndexBuffer(4,Buffer5);// Назначение массива буферу 
SetIndexEmptyValue(4,0.0);
SetIndexStyle (5,DRAW_ARROW,STYLE_SOLID,2,Green);
SetIndexArrow (5,251);// Стиль линии 
SetIndexBuffer(5,Buffer6);// Назначение массива буферу 
SetIndexEmptyValue(5,0.0);
SetIndexStyle (6,DRAW_ARROW,STYLE_SOLID,2,Red);
SetIndexArrow (6,241);// Вход Бай
SetIndexBuffer(6,Buffer7);// Назначение массива буферу 
SetIndexEmptyValue(6,0.0);
SetIndexStyle (7,DRAW_ARROW,STYLE_SOLID,2,Blue);
SetIndexArrow (7,242);// Вход сел 
SetIndexBuffer(7,Buffer8);// Назначение массива буферу 
SetIndexEmptyValue(7,0.0);

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  int i,b,limit;
limit=Bars;
if (b!=Bars){
b=Bars;
      for(i=limit; i>=0; i--){
      
      if ((setupUP(i,4,5)==1)) {Buffer5[i+1]=Low[i+1];} else Buffer5[i+1]=0;
      if ((setupDOWN(i,4,5)==1)){Buffer5[i+1]=High[i+1];} else Buffer5[i+1]=0;
      
      
      

      }
      
  Buffer5[i+1]=Low[i+1];    
}
 
   return(0);
  }
//+------------------------------------------------------------------+


int setupUP (int i, int k, int k1)
{
int num=0;
int setUP=0;
for (i=0; i>=100; i++){
 if((Close[i+1]<Close[i+k])) {num=num+1;}
 }
 
 if (num>=k1) {
               setUP=1;
               return (setUP);     
            }
return (0);
}

int setupDOWN (int i, int k, int k1)
{
int num=0;
int setUP=0;
 if((Close[i+1]>Close[i+k])) {num=num+1;}
 if (num>k1) {
               setUP=1;
               return (setUP);     
            }

}
What should I do to output the fifth buffer?
 
zaqwsx123:

People, I need help, the code below is executed only the second part, when sellstop should be set, and buystop for some reason is not set, although all conditions are met, I can not even see what's wrong))

if (OrdersTotal()==2)

{

...

To properly insert code in the forum, click SRC

We should actually use if to select the order

if (OrderSelect(2,SELECT_BY_TICKET))
{
  //--- действие
 
Well there are no pros on my question????
 

I usually send orders by separate functions. I would like to optimise this, so that I can send both pending and market orders with one function.

Please, advise how to implement it correctly?

When sending pending orders, we should check opening price above (below) the Bid price and take into consideration some other aspects.

Let's look how others do it. Let's take the simplest variant used by Kim:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 21.03.2008                                                     |
//|  Описание : Открывает позицию и возвращает её тикет.                       |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (NULL или "" - текущий символ)          |
//|    op - операция                                                           |
//|    ll - лот                                                                |
//|    sl - уровень стоп                                                       |
//|    tp - уровень тейк                                                       |
//|    mn - MagicNumber                                                        |
//+----------------------------------------------------------------------------+
int OpenPosition(string sy, int op, double ll, double sl=0, double tp=0, int mn=0) {
  color    clOpen;
  datetime ot;
  double   pp, pa, pb;
  int      dg, err, it, ticket=0;
  string   lsComm=WindowExpertName()+" "+GetNameTF(Period());
 
  if (sy=="" || sy=="0") sy=Symbol();
  if (op==OP_BUY) clOpen=clOpenBuy; else clOpen=clOpenSell;
  for (it=1; it<=NumberOfTry; it++) {
    if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) {
      Print("OpenPosition(): Остановка работы функции");
      break;
    }
    while (!IsTradeAllowed()) Sleep(5000);
    RefreshRates();
    dg=MarketInfo(sy, MODE_DIGITS);
    pa=MarketInfo(sy, MODE_ASK);
    pb=MarketInfo(sy, MODE_BID);
    if (op==OP_BUY) pp=pa; else pp=pb;
    pp=NormalizeDouble(pp, dg);
    ot=TimeCurrent();
    ticket=OrderSend(sy, op, ll, pp, Slippage, sl, tp, lsComm, mn, 0, clOpen);
    if (ticket>0) {
      if (UseSound) PlaySound(NameFileSound); break;
    } else {
      err=GetLastError();
      if (pa==0 && pb==0) Message("Проверьте в Обзоре рынка наличие символа "+sy);
      // Вывод сообщения об ошибке
      Print("Error(",err,") opening position: ",ErrorDescription(err),", try ",it);
      Print("Ask=",pa," Bid=",pb," sy=",sy," ll=",ll," op=",GetNameOP(op),
            " pp=",pp," sl=",sl," tp=",tp," mn=",mn);
      // Блокировка работы советника
      if (err==2 || err==64 || err==65 || err==133) {
        gbDisabled=True; break;
      }
      // Длительная пауза
      if (err==4 || err==131 || err==132) {
        Sleep(1000*300); break;
      }
      if (err==128 || err==142 || err==143) {
        Sleep(1000*66.666);
        if (ExistPositions(sy, op, mn, ot)) {
          if (UseSound) PlaySound(NameFileSound); break;
        }
      }
      if (err==140 || err==148 || err==4110 || err==4111) break;
      if (err==141) Sleep(1000*100);
      if (err==145) Sleep(1000*17);
      if (err==146) while (IsTradeContextBusy()) Sleep(1000*11);
      if (err!=135) Sleep(1000*7.7);
    }
  }
  return(ticket);
}

He does not check anything at all. We can see that his function is intended only for opening market orders.

I don't think this is logical. If you send an order, it will be of any type. If you write it the way I think, it will be too long, at first glance.

In general, I am asking for help and hints on how to better implement these points.

Reason: