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

 
skyjet:

Hello! My goal is to transfer the indicator by creating a function into the EA.

The first step, which is the creation of the function, is done. But the next one - testing - does not work.

The indicator draws channels. It has 4 buffers and a lot of variables. I have placed it all in the function.

But when I create a test EA to make sure that it works accurately by comparing the indicator and my function, I cannot get it to compile.

Constant errors of external variables, which were not there when I created the function, have popped up in the EA.

Please give me some advice or a link to an example. I used GODZILLA's articles, but his examples are different from mine.

The scheme is roughly as follows:

  • transfer everything that was in indicator init() to a separate function, for example, fInit_Indicator() and write it in init() of the EA, while remembering to remove everything that concerns initialization of indicator buffers from the code.
  • copy all global indicator variables and place them in global variables of the EA. Do not forget to define the size of indicator buffers when they are declared in the EA. Something like gd_Buf1[100], gd_Buf2[100] etc. I think that 100 values will be enough for you.
  • rename indicator's start() function, for example, fMyIndicator() and place it in the EA's start() function before the code of order opening (for making a decision).
  • Also, do not forget that the indicator buffer is different from the "non-indicator" buffer. There are several solutions for this:
  • when a new bar arrives, all data in the "non-indicator" array is shifted, releasing the 0-index, where the new calculated value is placed.
  • Again, when a new bar arrives, recalculate the entire "nonindicator array".

Try it out - it's not difficult.

 
999666:
Help me write a condition that will cause the EA to multiply the lot by two times after opening n orders
if (MyOrders >= n) Lots *= 2;
 

Good afternoon!

I'm still figuring things out with arrays.

I need to load values of the number of points into the array on each new tick.

Thesize of the array will be different each time. What should I do in this case, use ArreyResize on each iteration of the loop?

 

Good afternoon, on the subject of arrays.

there is a cell of this type

12345,p,fgh,2011-01-01,55,66

how can i get 55 from it?

Thanks.

 

If the array is heterogeneous, you should probably convert all elements to string type and then search for the required one using

StringFinde(https://www.mql5.com/ru/forum/138609/page22#613148). Correct me if I'm wrong.

 
TarasBY:

Not helpful: If it is not difficult to have two conditions if (LotConst_or_not) gd_200 = Lot;

else gd_200 = AccountBalance() * RiskPercent / 100.0 / 10000.0;

Replace it with an Expert Advisor that calculates not the balance but the number of open orders.

The answer would be very much appreciated.

 
TarasBY: Not helpful: If it is not difficult to have two conditions if (LotConst_or_not) gd_200 = Lot;

else gd_200 = AccountBalance() * RiskPercent / 100.0 / 10000.0;

Replace it with an Expert Advisor that calculates not the balance but the number of open orders.

The answer would be very much appreciated.


 
Snegovik:

Good afternoon, on the subject of arrays.

there is a cell of this type

12345,p,fgh,2011-01-01,55,66

how can i get 55 from it?

Thanks.


https://book.mql4.com/ru/variables/arrays
 
999666:
Help me write a condition that will cause the EA to multiply the lot by two times after n orders are opened
If you want to open the next (4, etc) orders with 3 already opened with 2 x lots, then:
int Opened_pos=0;
for (int i=OrdersTotal()-1; i>=0; i--)
{ if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
  { if (OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL))
    { Opened_pos++;
} } }
if (Opened_pos>=4) double lot=lot*2;
 
Fox_RM:

Good afternoon!

I'm still figuring things out with arrays.

I need to load values of the number of points into the array on each new tick.

The size of the array will be different each time. What should I do in this case, use ArreyResize on each iteration of the loop?

1-Item: your philosophy of changing the array size is defective from the very beginning, in 99 out of 100 cases you can use only 10 cells for handling indicator readings;

2-nd: to recalculate these readings at each tick is a whim of ill-informed brain.