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

 
Vinin:

Are you sure you have all the braces. They are missing in some places. That's why your logic is flawed. And most likely the result is not what you expected.
Vitya, have you been away? Haven't seen you for a long time...
 
artmedia70:
Vitya, have you been away? I haven't seen you for a long time...


I was home today (almost).
 
Vinin:

Been home today (almost)
I'm almost home for the second week :))
 
Vinin:

Are you sure you have all the braces. They are missing in some places. That's why your logic is flawed. And most likely, the result is not what you expected.

If you mean the code of the indicator, everything is ok there, the indicator works, gives signals in the form of arrows (for buy/sell-4 and 5 indicator buffers). But when I read these arrows from the indicator in the Expert Advisor, I get nonsense. I did not bring up the Expert Advisor completely because the main thing there is to understand how to read the signal and do the corresponding operation. In general, the problem is in reading the signal.
 
paladin80:

To paste the code correctly here, first click on SRC and then copy the code there.

If I understood you correctly, at a certain moment in time we have to open one OP_BUYSTOP and one OP_SELLSTOP ? Is it acceptable to have any other pending orders at this moment? For example, there are pending orders, but before opening a new one, the old ones should be deleted?



if (hour1 == TimeHour(TimeCurrent()) && minute1 == TimeMinute(TimeCurrent()))// если время подошло то
{
min=Low[iLowest(Symbol(),0,MODE_LOW,6,1)]; // вычисляем минимальную цену последних 6 свечей
max=High[iHighest(Symbol(),0,MODE_HIGH,6,1)]; // вычисляем максимальную цену последних 6 свечей
double volum=max-min;// общий объем локалки последних 6 свечей М5

if ((volum<=n)==true)// если объем свечей меньше или равно n пунктов 
{ 
OrderSend ( Symbol (), OP_BUYSTOP, параметры);// открываем отложенный ордер байстоп
OrderSend ( Symbol (), OP_SELLSTOP, параметры);// открываем отложенный ордер селлстоп
}

if (OrderSelect(1,SELECT_BY_POS,MODE_HISTORY)&& OrderTakeProfit()==true) ///если первый открывшийся отложенный ордер закрыт с профитом
{
OrderDelete(1);// удаляем второй открытый отложенный ордер
}

}
bool closeorder;//определим  закрытие ордеров
closeorder=true;

if (closeorder==true)//
{
int hour2 = TimeHour(StrToTime(time2));// вычисляем время закрытия ордеров
int minute2 = TimeMinute(StrToTime(time2));

if (hour2 == TimeHour(TimeCurrent()) && minute2 == TimeMinute(TimeCurrent()))// если время 
{
for(int i=OrdersTotal()-1; i>=0; i--)// определяем количество открытых позиций, и отложенных ордеров и закрываем все возможные позиции, и отложенные ордера
 if (OrderSelect(1,SELECT_BY_POS,MODE_TRADES))break; //определяем место где будем искать ( рабочие позиции)
if (OrderType()==OP_BUY ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),slippage);// Закрытие ордера бай если такой есть
if (OrderType()==OP_SELL) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),slippage);//Закрытие ордера селл если такой есть
{
for(int D=OrdersTotal()-1; D>=0; D--)
if (OrderSelect(D,SELECT_BY_TICKET,MODE_TRADES)==true)
if (OrderType()==OP_BUYSTOP ) OrderDelete(D); //удаляем отложенный байстоп
if (OrderType()==OP_SELLSTOP) OrderDelete(D);// удаляем отложенный селлстоп

I have already pasted the generic code to make it clearer... At the end of the day I wanted to close all possible positions and orders...

and at the time of opening two pending orders (in the morning) there are no open orders or open positions before that, since they all have to be closed at a certain time in the evening. I wonder if my full order closure is at least correctly described? =)))



 
artmedia70:

I honestly don't know the logic of your function. Whether it should delete objects or build them, I don't know. Tell me what you want it to do and we'll see where the logic is wrong. However, if the function tries to build a graphical object but fails, it means it already exists. What's the next logical step in your program? You can build a new object with a different name (for example, add the current time to the object name (TimeToStr(TimeCurrent()))) or, if you already have an object but need to change its properties, do not build it again, but simply change its properties. Then the error won't occur again.

It's simple. The main thing is to know what you want... :)



Actually, the function is merely a visual substitute for the print, it just displays everything on the screen. It is not written very well yet, but it works. :) I'll get there and rewrite it. And then you can think about the question that was.

By the way, if you don't build new objects, but modify the properties of existing ones, then again... It's going to be a headache. The idea is to display the last N shoals on the screen. If we always overwrite the outermost object, we could end up with only one object that has a particular bug. I could go further and select in a loop as many objects as I need and rewrite them only, but it's probably not worth the effort, since this function is only for testing and I'm not really bored with it since I already have too many things to do. Someday I will try the code of that function, and bring it to my senses, and then I can think about it!

 

A question has arisen. I am writing the following experiment. I have a bunch of orders that, naturally, open one after another based on certain signals. If the last order is closed, all other market and pending orders should be closed at all...

Of course, everything can be written through arrays, but I used an ordinary way. Here we go:

for (int li_ord=OrdersTotal()-1; li_ord>=0; li_ord--)
   {
      if (!OrderSelect(li_ord,SELECT_BY_POS)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
        
      g_ticket = OrderTicket();
      g_type = OrderType();

      // Закрытие всех ордеров, если последний ордер закрыт
      if (GetLastOrderState() != 0)
      {
          if (g_type > 1)
          {
              DeletePendingOrders(g_ticket);
          }
          else
          {
              CloseMarketOrders(g_ticket);
          }
      }
   }

Condition:

 if (GetLastOrderState() != 0)

we check if the last open order is closed! Then we start to delete the pending orders and close the market orders...


Here is the function itself, so there is no doubt that something is wrong with it(Criticism and comments are welcome, and even more than welcome :)) ):

//+-------------------------------------------------------------------------------------+
//| Получаем состояние последней позиции (Открыта или закрыта)                          |
//+-------------------------------------------------------------------------------------+
double GetLastOrderState()
{
   double lastOrderCloseTime = -1,                   // Время закрытия последнего ордера
          lastOrderOpenTime = -1;                     // Время открытия последнего ордера
   
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
  
      if (lastOrderOpenTime < OrderOpenTime())
      {
          lastOrderOpenTime = OrderOpenTime();
          lastOrderCloseTime = OrderCloseTime();
      }
   }
   
   return (lastOrderCloseTime);
}
 
vovak_85:

If you're talking about the indicator code - everything is fine there with the brackets, the indicator works, gives signals in the form of arrows (for buy/sell - 4 and 5 indicator buffers). But when I read these arrows from the indicator in the Expert Advisor, I get nonsense. I did not bring up the Expert Advisor completely because the main thing there is to understand how to read the signal and do the corresponding operation. In general, the problem is in reading the signal.
This is yours:
double L_B=iCustom(0,0,"Makedonskii",MM,MP,0,4);

double L_S=iCustom(0,0,"Makedonskii",MM,MP,0,5);

This is how it should be:
double L_B=iCustom(NULL,0,"Makedonskii",MM,MP,4,0);

double L_S=iCustom(NULL,0,"Makedonskii",MM,MP,5,0);
Something like this.
 
hoz:

Actually, the function is just a visual substitute for the print, but it displays everything on the screen. It's not particularly well-written yet, but it works... :) I'll get there and rewrite it. And then you can think about the question that was.

By the way, if we don't build new objects, but change the properties of existing ones, then again... That would be a headache. By idea, we need to display the last N-joints on the screen. If we always overwrite the last object, we could end up with only one object that has a particular bug. I could go further and select in a loop as many objects as I need and rewrite them only, but it's probably not worth the effort, since this function is only for testing and I'm not really bored with it since I already have too many things to do. Someday I will try the code of that function, and bring it to my senses, and then I can think about it!

I once made a function that displays messages in an empty indicator window. You can adjust the colours of the displayed lines. It's already debugged. I can share it if you need it.
 
r772ra:
This is yours: It should be like this:
Something like this.

thanks for the correction, but the algorithm didn't work correctly...
Reason: