Questions from a "dummy" - page 51

 

Thank you very much papaklass, it worked, now I will try to understand the difference.

 

Why Expert Advisor hangs on this piece of code:

if(Orders_Total!=0)
  {
   for(i=Orders_Total;i>=0;i--)
     {
      Alert(Orders_Total);
      if(Symbol()==PositionGetSymbol(i))
        {
         OpenPrice=PositionGetDouble(POSITION_PRICE_OPEN);
         OrderLot = PositionGetDouble(POSITION_VOLUME);
         StopLoss = PositionGetDouble(POSITION_SL);
         TakeProfit=PositionGetDouble(POSITION_TP);
         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
           {
            for(i=0;i<12;i++)
              {
               if(Price[i].low<lowest)
                 {
                  lowest=Price[i].low;
                 }
              }
            Alert(lowest);
            SL=NormalizeDouble(lowest-spread-_Point,_Digits);
            if(StopLoss<SL)
              {
               request.action=TRADE_ACTION_SLTP;
               request.symbol=_Symbol;
               request.volume= OrderLot;
               request.sl=SL;
               request.tp=TakeProfit;
               request.type=ORDER_TYPE_BUY;
               OrderSend(request,result);
              }
           }
         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
           {
            for(i=0;i<12;i++)
              {
               if(Price[i].high>highest)
                 {
                  highest=Price[i].high;
                 }
              }
            Alert(highest);
            SL=NormalizeDouble(highest+spread+_Point,_Digits);
            if(StopLoss>SL)
              {
               request.action=TRADE_ACTION_SLTP;
               request.symbol=_Symbol;
               request.volume= OrderLot;
               request.sl=SL;
               request.tp=TakeProfit;
               request.type=ORDER_TYPE_SELL;
               OrderSend(request,result);
              }
           }
        }
     }
  }

I inserted alerts Orders_Total=2 lowest and highest also give adequate values nevertheless expert hangs in this loop, giving infinite number of alerts, no other errors (concerning order modification) are given.

Please help a newbie to understand :)

 

For one outer cycle and two inner cycles, the same cycle variable i, which becomes 12 with each new iteration of the outer cycle

 
stringo:

For one outer cycle and two inner cycles, the same cycle variable i, which becomes 12 with each new iteration of the outer cycle

Thank you!!!
 

Can you fix the code? I need the opening price of the current bar. Thank you in advance.

double Open[], val4;
ArraySetAsSeries(Open,true);
CopyOpen(Symbol_, PERIOD_M15,1,0,Open);
val4 = (Open[ArrayMinimum(Open,0,1)] );

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы - Документация по MQL5
 
abeiks:

Can you fix the code? I need the opening price of the current bar. Thank you in advance.

"Symbol_ " is the wrong parameter, the underscore should be on the front

And the number of copied items is 0.

 

If I connect an external indicator to my EA through iCustom, I can't change input parameters dynamically. iMA is ok, it works with fixed values, two interchangeable strings, I put it in OnTick(), MA period is recalculated.

ma_handle = iCustom(_Symbol,0,"Examples\\JJMA.ex5",MA,4);
   
ma_handle = iMA(_Symbol,0, MA,0, MODE_EMA, PRICE_CLOSE); 

If this is the case, what cannot be changed in external ones, then why do I need to embed code in my EA?

Sorry, it works, it just takes much longer.

 
Karlson:

If I connect an external indicator to my EA through iCustom, I can't change input parameters dynamically. iMA is ok, it works with fixed values, two interchangeable strings, I put it in OnTick(), MA period is recalculated.

If this is the case, what cannot be changed in the EA, then how can we embed the code in the EA?

"...I can't dynamically change the input parameters" of the indicator?

Reproduce the input parameters of the indicator as input parameters of the Expert Advisor. And it's better to get the handle once at initialization of the Expert Advisor rather than on every new tick.

 
Yedelkin:

"...can't dynamically change the input parameters" of the indicator?

Reproduce the input parameters of the indicator as input parameters of the Expert Advisor. And it's better to get the handle once when initialising the Expert Advisor than on every new tick.

I have a period of the average varies from ATR during the work of the EA, so the handle of the average is placed in OnTick() . In fact, the input parameter for the EA is the period of ATR, it does not change.

int OnInit()
  {
  atr_handle = iATR(_Symbol,0, ATR);  //инициализируем хэндл ATR
  }

void OnTick()
  {
     CopyBuffer(atr_handle,0,0,5,atr);   //заполняем массив ATR
     ArraySetAsSeries(atr,true);

     MA=(int)(atr[1]*kMA);                 //рассчитываем период требуемый для средней от ATR

   //ma_handle = iCustom(_Symbol,0,"Examples\\JJMA.ex5",MA,4);  // получаем хэндл средней
   
     ma_handle = iMA(_Symbol,0, MA,0, MODE_EMA, PRICE_CLOSE);

     CopyBuffer(ma_handle,0,0,5,ma);     //заполняем массив средней
     ArraySetAsSeries(ma,true); 
  }
 
Karlson:

I have an average period changing from ATR while the EA is running, so the handle of the average is placed in OnTick().In fact the input parameter to the EA is the ATR period.It does not change.ATR in OnInit().

I have understood it approximately. But it is difficult to obtain the indicator handle every time on a new tick. And what do you do with the previous handle?
Reason: