[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 271

 
hoz:

I understand what's there. But it's not clear why it's implemented this way.

Each individual library function is part of the whole, and an individual library is part of the whole complex of my libraries - without this awareness it is impossible to understand the code.

hoz:

You can't use your libraries in their original form anyway, i.e. you have everything tied up there. Every function on the pack of others...

And that's where you're wrong. Have you ever thought about the structure of "average" EA? What makes an EA individual is the strategy conditions (i.e., entry/exit conditions), and everything else is standard code. The way I create EAs, including those based on orders: I take a template (for example, SAR, if a network EA is needed) and connect to it an additional library in which the conditions of a new strategy are written (I re-create it).

hoz:

I did not want to check it by any means. Even more, there is no doubt that everything is written very competently. I just do not quite understand everything, so I said that I do not think so. I look, I think... But I don't understand everything. That's why I asked.

P.S. With bs_Symbol I still don't get it.

To understand the implementation, you need to understand the source data. The libraries were created with the ability to work with any instrument (forex) and both mono and multicurrency modes, hence the introduction of the bs_Symbol global variable, which contains the value of the current instrument.
 
IIya:

Friends! I need help in fine-tuning an EA.

We have code that opens an order under certain if condition. The execution of the condition can take place every tick because it is placed in the body of int start().

We need:

1. After the execution of the condition (and the opening of an order), pause for the opening of new orders, pause for n bars. For example, if the EA is on timeframe M30 and I need to pause for 3 hours, the pause should be 6 bars.

2. This program should work in the strategy tester.

What code is needed? And what would be the right place to put it.

The iBarShift() function will help you. First, you need to find out the time of the last order opening and pass it to this function, and then monitor the value returned by this function by comparing it to some number (in your case 6).
 
TarasBY:
The function iBarShift() will help you. First, you need to find out the time of the last order opening and pass it to this function, and then monitor the value returned by this function by comparing it to some number (in your case, 6).

Let's sort it out together )

We pass the time of the last order opening to this function and obtain the number returned. This is approximately:

OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES);
int my_bar = iBarShift(NULL,PERIOD_M30,OrderOpenTime()); 

Ok we got the bar number. Now how do we pause to open orders for 6 bars?

 
IIya:

Let's sort it out together )

We pass the time of the last order opening to the function, and get the number returned is approximately:

Ok we got the bar number. Now how do we pause to open orders for 6 bars?

This is an illiterate approach:

OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES);

But since it's not directly relevant to this case, we just don't focus on it. The scheme looks like this:

    if (my_bar >= 6)
    {
        OrderSend();
    }
 
TarasBY:
There are no obvious errors in the logic. Print the code step by step. The trade procedure is tied to the value of the ticket variable. First of all, monitor its changes. Also pay attention to the value of global variable "TRADECONTEXT" - its value must be 0.

Thank you! I just don't understand anything(((, I'm like a blind kitten in these codes(((...
 
al7bar:

Thank you! But I don't understand a thing(((, I'm like a blind kitten in these codes(((...
It turns out you're not the author of this code. Then it's easier to contact the author.
 
TarasBY:

Each individual library function is part of the whole, and each individual library is part of the whole complex of my libraries - without this awareness it is impossible to understand the code.

I'm trying to understand it, and I'm bumping into all sorts of nuances. That's why I'm asking you, because you know best. You are the author...

TarasBY:

And that's where you're wrong. Have you ever thought about the structure of the "average" Expert Advisor? What makes an EA individual is its strategy conditions (i.e., entry/exit conditions), and everything else is standard code. The way I create Expert Advisors, including those based on orders: I take a template (for example, SAR, if a network EA is needed) and connect to it an additional library in which the new strategy conditions are written (I re-create it).

I understand that. I just do not want to copy the entire library. You understand that it is more convenient to create a foundation, with which it will be convenient to work personally.

TarasBY:

To understand the implementation, you need to understand the initial data. The libraries were created with the possibility to work with any tool (Forex) and in both mono and multicurrency mode, hence, the global variable bs_Symbol was introduced, which contains the value of the current symbol.

And where this variable is set explicitly, if it's not a secret? :) I see in the libraryb-PSI@Base.mqh that it is only declared:

 bs_Symbol,                            // текущий инструмент

But there is nothing further in fact. Anyway, the value of the current tool is returned by default through Symbol(). So why do we need a variable here?

 
TarasBY:

This is an illiterate approach:

But, as it's not directly relevant to this case, we just don't focus on it. And the pattern looks like this:

Now our code works. In my version, it works like this:
int start()
  {
   if (OrdersTotal()<1)                                                //условие
      {
         OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"Order BUY",0,0);     //открытие ордера
      }
   OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES);
   int my_bar = iBarShift(NULL,PERIOD_M30,OrderOpenTime()); 
   if (my_bar > 6)                                                     //если прошло 6 баров с момента открытия последнего ордера
      {
         OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"Order BUY",0,0);      //открываем новый ордер
      }
   return(0);
  }

:) But if it is introduced into the Expert Advisor as it is now, everything starts to work incorrectly.

As far as I understand, it is due to this entry:

OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES);

What's wrong?

 
Hello everyone. please respond to all who can create a script that increases the lots at the opening of the transaction. details write in a personal. remuneration guarantee in the satisfaction of the task
 
IIya:
Our code now works. In my version, it works like this:

:) Except that if it is implemented in the EA as it is now, then everything starts to work incorrectly.

I understand because of this entry:

What's wrong?

I have only sketched a scheme, while your task was to think over the further logic:

int start()
{
   if (OrdersTotal()<1)                                                //условие
      {
         OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,"Order BUY",0,0);     //открытие ордера
      }
   else
   {
       OrderSelect (OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES);
       int my_bar = iBarShift (NULL,PERIOD_M30,OrderOpenTime()); 
       if (my_bar >= 6)                                                     //если прошло 6 баров с момента открытия ордера
       {OrderSend (Symbol(),OP_BUY,1,Ask,0,0,0,"Order BUY",0,0);}      //открываем новый ордер
   }
   return(0);
}
Reason: