# [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 403

GaryKa:
It's just that these labyrinthine programmers don't have the heart to come in even once a week and earn their schtick. They're so sick of it that they just want to make money.

This is my idea:

I open an order, and then it depends on what balance it closed in.

If the balance is less than zero, we record the loss, and if it is greater than zero, we start working from the beginning.

If our loss is less than zero, we have fixed it and assigned to a variable, for example: Minus

Minus = OrderProfit (- 45 cents);

AccountAqviti + Minus + my value (my conscience)

further on the next order

if the profit of this order is higher than AccountAqviti + Minus + my value (my conscience), then we close the order; if not, go higher than zero, then we fix it:

(AccountAqviti + OrderProfit) - (AccountAqviti + Minus + my value (my conscience)) = Minus

if Minus >= 0, then Minus = 0;

belck:

That's what my idea is all about:

You have to go to Service Work with an idea, and here it's customary to deal with specific situations with a specific code.

Good afternoon! I would like to create an indicator that displays a channel on indicators like MASD, AO and similar. This indicator is superimposed on the window of basic indicators (MASD, AO and similar) and is drawn as parallel lines above and below 0. These lines are defined as an average of maximum peaks (above 0) and minimum troughs (below 0) for the specified period.
I am trying to use AO indicator as an example but it does not work.
Algorithm:
we write the indicator readings to an array,
we run through this array searching for peaks / troughs,
we write them to certain arrays,
we find the average value of peaks, then troughs,
we assign the obtained value to the indicator buffer.
At this step, it is not the channel (sticking to 0) on the indicator that is defined in the code, but the average value of maximum peaks and average value of minimum troughs.
The definition of peaks and troughs can be removed from the code and executed as a function, but for now I have left it that way - it does not change the matter.
Problems:
1. terminal hangs (considerably)
2. lines are not displayed as an average; they appear as max/min for a period.
Took a long time to figure it out, but I can't figure out the cause of the problems. Can you please help me to correct my code or give me a link to the source code of similar issues and I will try to correct it further. Thanks in advance.

```int start(){
int limit=Bars-IndicatorCounted();
for(int i=limit;i>=0;i--){
//     if (IsNewBar()){
int j=0;
for (int d=2;d<=period-1;d++){
ArrayResize(AO,j+1);
AO[j]=AO(d);                            // Запишем данные инд. в цикле в массив
Print("АО-",AO[j],"-",d,"-",i);
j++;
}
int k_up=0,k_dw=0; double SDw=0,SUp=0,P1=0,P2=0;
//собираем экстремумы выше 0
for (int p=4;p<=period-1; p++){
if (AO[p]>AO[p+1] && AO[p]>AO[p-1]
&& AO[p+1]>AO[p+2]
&& AO[p+2]>AO[p+3]
&& AO[p+3]>0
&& AO[p-1]>AO[p-2]
&& AO[p-2]>AO[p-3]
&& AO[p-3]>0){                           // Нашли макс
ArrayResize(Up, k_up+1);                 // Размер массива донышек под кол-во найденных донышек
Up[k_up]=AO(p);                          // Заносим значение пика в массив
Print("значение пика-",Up[k_up],"-",p);
SUp=SUp+Up[k_up];
P1=SUp/(k_up+1);
k_up++;                                  // Увеличиваем индекс массива донышек
}
//собираем впадины ниже 0
if (AO[p]<AO[p+1] && AO[p]<AO[p-1]
&& AO[p+1]<AO[p+2]
&& AO[p+2]<AO[p+3]
&& AO[p+3]<0
&& AO[p-1]<AO[p-2]
&& AO[p-2]<AO[p-3]
&& AO[p-3]<0){                           // Нашли мин
ArrayResize(Dw, k_dw+1);                 // Размер массива донышек под кол-во найденных донышек
Dw[k_dw]=AO[p];                          // Заносим значение пика в массив
Print("значение донышка-",Dw[k_dw],"-",p);
SDw=SDw+Dw[k_dw];
P2=SDw/(k_dw+1);
k_dw++;// Увеличиваем индекс массива донышек
}
}
level1[i]=P1;
level2[i]=P2;
}
return(0);
}
//+------------------------------------------------------------------+
double AO(int a){double AO=iAO( NULL, 0, a);
return(AO);
}```

LOA:

Good afternoon!
Problems:

1. terminal hangs (significantly)

```for (int d=2;d<=period-1;d++){
ArrayResize(AO,j+1); ```

Increasing an array's size in a loop is cruel, that's why it hangs. Increase the size once at once. Or use timeseries at once

P.S. see personal messages

How do I loop through a variable of type string?

Example

```   double A[3];
A[0]=iClose("EURUSD",0,0);
A[1]=iClose("GBPUSD",0,0);
A[2]=iClose("AUDUSD",0,0);```
How do I replace this construction with a loop?

Good afternoon, could you please tell me how to write a condition whereby if the profit of an open order is one pungent, then close that order?

first_may:
Good afternoon, could you please tell me how to write a condition whereby if the profit of an open order is one pungent, then close that order?

Using the function.

https://www.mql5.com/ru/forum/131859/page3#434225

```//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает суммарный профит открытых позиций в пунктах         |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
int GetProfitOpenPosInPoint(string sy="", int op=-1, int mn=-1) {
double p;
int    i, k=OrdersTotal(), pr=0;

if (sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
if (mn<0 || OrderMagicNumber()==mn) {
p=MarketInfo(OrderSymbol(), MODE_POINT);
if (p==0) if (StringFind(OrderSymbol(), "JPY")<0) p=0.0001; else p=0.01;
pr+=(MarketInfo(OrderSymbol(), MODE_BID)-OrderOpenPrice())/p;
}
if (OrderType()==OP_SELL) {
}
}
}
}
}
return(pr);
}```

Rorschach:

How do I loop through a variable of type string?

Example

How do I replace this construct with a loop?

```   string asSymbols[3] = {"EURUSD", "GBPUSD", "AUDUSD"};
double A[3] = {0};
for (int i = 0; i < ArraySize( sSymbols) && i < ArraySize( A); i++) A[i]= iClose(asSymbols[i], 0, 0);```