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

 

So, hopefully the final form of the function.

double ATR_Max() {
int i;
double m;
datetime tim;
iATR_H1_PER = 15;// период
if ( tim != Time[0] ) {  
while( i < WindowBarsPerChart() ) {
double a = iATR( NULL, 0, iATR_H1_PER, i );
   if ( m < a ) {
   m = a;
   }
   i++;
   tim = Time[0];
  }
}
Alert( " Максимальное значение ATR для видимого количества баров равно - ", m );
return(m);
} 
 
dr.Vasgenich :

So, hopefully the final form of the function.

Dr.Vasgenich :

So, hopefully the final form of the function.

I think tim = Time[0] would be better placed after the loop ...because asking Time[0] is done on all visible bars - it's not rational.
 
Boeing747 :
I think tim = Time[0] would be better placed after the loop ...because asking Time[0] is done on all number of visible bars - it's not rational.
Thanks for the correction. The number of errors grows exponentially at night))))
 
dr.Vasgenich :
Thanks for the correction. The number of errors grows exponentially at night))))
exponentially )). however, i should go to bed too. if you need anything, let me know))
 
Good afternoon. Do you know if it is possible to change indicator parameters on the fly in mql4?
The idea is simple: the ZigZag indicator is installed on the chart. The script should be written and the hot key should be attached to it. By pressing it the zigzag parameters will be changed on the chart.
 

Continuing the current topic of finding a high volatility filter. Here is the code of an existing filter from WSR

extern string ____ = "Фильтр волатильности";
extern bool VolatilityFilter              = FALSE;
extern int VolaFilter                     = 25; //--- (15 1 30)
double pp;
double pd;

int init()

   if (Digits < 4) {
      pp = 0.01;
      pd = 2;
   } else {
      pp = 0.0001;
      pd = 4;
   }

Here is the function itself:

bool CheckVolatility() {
   double HeightFilter_a = NormalizeDouble(VolaFilter * pp, pd);
   bool restrict = false;
   if (NormalizeDouble(iHigh(NULL, PERIOD_M5, 1) - iLow(NULL, PERIOD_M5, 1), pd) > HeightFilter_a) restrict = true;
   if (NormalizeDouble(iHigh(NULL, PERIOD_M5, 2) - iLow(NULL, PERIOD_M5, 2), pd) > HeightFilter_a) restrict = true;
   return (restrict);
}

Thus, the function checks the values of the two previous bars and if they are too big, it returns TRUE. The question is how to improve it nicely: to make this function look for big candles on more candles. For example 24.

 
satorifx :
Good afternoon. Do you know if it is possible to change indicator parameters on the fly in mql4?
The idea is simple: the ZigZag indicator is installed on the chart. The script should be written and the hot key should be attached to it. As soon as I press it, the ZigZag parameters will change on the chart.
There is such a possibility.
 

I made a homemade Expert Advisor to test trading, but I cannot figure out one thing...

Bay/sell is opened using maximal and minimal MAs

// Condition for opening BUY position
if(MA_L1<MA_L0&&Ask<=MA_L0&MA_0>MA_1&&HA_up>HA_dw)

// Condition for opening a SELL position
if(MA_H1>MA_H0&&Bid>=MA_H0&MA_0<MA_1&HA_up<HA_dw)

#include <b-Lots.mqh>
extern double TrailingStop = 30;
extern double Sploss = 15;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start() {
   double HA_up,HA_dw;
   double MA_H0,MA_H1,MA_L0,MA_L1,MA_0,MA_1;
   int i, cnt, ticket, total;
   bool flag=true;

   if(Bars<100) {
      Print("bars less than 100");
      return(0); 
   }
// Проверяем стоит ли открываться
   
   cnt=OrdersHistoryTotal()-1;
   for(i=cnt;i>=0;i--) {
      if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY )) continue;
      if(OrderOpenTime()>=Time[0]) { // Time[0] - если позиция открывается на нулевом баре текущего символа
         flag=false;
         break;
      }
   }
   cnt=OrdersTotal()-1;
   for(i=cnt;i>=0;i--) {
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if(OrderOpenTime()>=Time[0]) { // Time[0] - если позиция открывается на нулевом баре текущего символа
         flag=false;
         break;
      }
   }
   if(!flag) return(0); 
//-----------------------------------------------
   MA_H0=iMA(0,0,3,0,MODE_SMA,PRICE_HIGH,0);
   MA_H1=iMA(0,0,3,0,MODE_SMA,PRICE_HIGH,1);
   MA_0=iMA(0,0,3,0,MODE_EMA,PRICE_MEDIAN,0);
   MA_1=iMA(0,0,3,0,MODE_EMA,PRICE_MEDIAN,1);
   MA_L0=iMA(0,0,3,0,MODE_SMA,PRICE_LOW,0);
   MA_L1=iMA(0,0,3,0,MODE_SMA,PRICE_LOW,1);
   HA_up=iCustom(0,0,"Heiken Ashi",3,0);
   HA_dw=iCustom(0,0,"Heiken Ashi",2,0);

//задали все данные 

   total=OrdersTotal();
   if(total<1) 
     {
      // Проверка свободной маржи
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // Условие открытие позиции BUY
      if(MA_L1<MA_L0&&Ask<=MA_L0&&MA_0>MA_1&&HA_up>HA_dw)
        {
         Lots=GetSizeLot();
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Bid-Sploss*Point,0,"",16384,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // Условие открытие позиции SELL
      if(MA_H1>MA_H0&&Bid>=MA_H0&&MA_0<MA_1&&HA_up<HA_dw)
        {
         Lots=GetSizeLot();
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Ask+Sploss*Point,0,"",16384,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
    
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol())  
        {
         if(OrderType()==OP_BUY)   // длинная позиция открыта
           {
           if(NormalizeDouble (MathAbs(MA_H0-Bid),Digits)<Point)
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
                 return(0); 
                }
            // трейлинг-стоп для длинной позиции
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else 
           {
           if(NormalizeDouble (MathAbs(MA_L0-Ask),Digits)<Point)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); 
               return(0); 
              }
            // трейлинг-стоп для короткой позиции
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
Question: The position on the current candle is not closed (the conditions have not come). How to close it on the next candle, when it matches MA_0= iMA ( 0, 0, 3, 0, MODE_EMA, PRICE_MEDIAN, 0 );

We have a condition to close it: crossing the high or low of the current candle, but we need the position to close on the next candle after it is opened.

We can write if ( NormalizeDouble ( MathAbs (MA_0-Ask), Digits )< Point ), but how to fulfill the condition of the second open candle.


If you can answer with code, the example is clearer.
 
Zhunko :
There is such a possibility.

Thank you for the incredibly detailed response.

Do you really have to be a smart aleck to understand that if a new person comes to the forum with a question, they need a specific solution or a link to something similar, not a dumb excuse that "anything is possible"?

 
satorifx :

Thank you for the incredibly detailed response.

Do you really have to be a smart aleck to understand that if a new person comes to the forum with a question, they need a specific solution or a link to something similar, not a dumb excuse that "anything is possible"?

People who are trying to do something on their own get help here. They guide you in the right direction, explain, etc. ...

You asked a question and you got an answer. Have you tried to start writing something yourself?

When asking a question in a certain format, first think about what kind of answer you will get to the format of the question...