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

 
sss2019:
The thing is that I was outputting all MA values in the loop, and all values are correct, i.e. all MA values for this period have been enumerated. But calculation is wrong in this place - range = (Ma1 - Ma2)/Point;
if(range > maxrange) maxrange = range;

Well, you need to check what is being input. Which variable values are involved in calculations?
 

In the MQLtutorial in the Standard Functions chapter in the Graph Operations section there is a function WindowHandle with the following description:" ... returns system descriptor of the window (window handle) containing specified graph".

Question: what does "window handle" mean (what is it) and what is it for?

P.S. In order not to clutter up the forum, thank you in advance for your answer

 
7777877:

In the MQLtutorial in the Standard Functions chapter in the Graph Operations section there is a function WindowHandle with the following description:" ... returns system descriptor of the window (window handle) containing specified graph".

Question: what does "window handle" mean (what is it) and what is it for?

P.S. In order not to clutter up the forum, thanks in advance for the answer


Response:

window descriptor is a number.

a window descriptor is needed to manipulate a window

 
int start()
{
  for (int i=OrdersHistoryTotal()-1;i>=0; i--)
  {
    if( OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
    {
       if (TimeDay (OrderOpenTime())==Day()
        && TimeMonth(OrderOpenTime())==Month()
        && TimeYear (OrderOpenTime())==Year())
         if(OrderType()==OP_SELL && OrdersTotal()==0 || OrdersHistoryTotal()==0)
         {
            OrderSend( Symbol(), OP_BUY, 0.1, Ask, 5,Bid-25*Point,Bid+25*Point, "", 0, 0, Blue );
         }
         if( OrderType()==OP_BUY && OrdersTotal()==0 || OrdersHistoryTotal()==0)
         {
            OrderSend( Symbol(), OP_SELL, 0.1, Bid, 5,Ask-25*Point,Ask+25*Point, "", 0, 0, Red );
         }
    }
  }
  return(0);
}

hello! problem with the code!!! i need the orders to open one by one sell, bay, sell etc., but the counting was done during the day, the next day by a new one, without considering the order of opening orders of previous day! that is a new day a new cycle! above code i think it should look like this! except that the EA does not open any order! can not understand what's wrong ...tell me if you know!!!

 
How to do it correctly.
I want the pending orders to be closed when a new day arrives, if they have not been executed... I wrote it, but it does not work. error 4051
  if (iTime(Symbol(),PERIOD_D1,0) != New_Day_DateTime)
   {
         New_Day_DateTime = iTime(Symbol(),PERIOD_D1,0); 
         GlobalVariableSet("gNew_Day_DateTime",New_Day_DateTime); 
  
for( i=1;i<=OrdersTotal(); i++)         
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) 
        {                                      

         if (OrderSymbol()!= Symb) continue;    
          Tip=OrderType();                   
         if (Tip==0) continue;           

            Limit_Stop=Tip;
             if (OrderMagicNumber()==3)                     
            {Ticket_B=OrderTicket();}
        }                                    
     }                                       

   while(true)                                
     {
      if (Limit_Stop==-1)                      
        {
         break;                                      
        }
       Ans_B=OrderDelete(Ticket_B);             

      if (Ans_B==true)                          
        {
         break;                                 
     }   }
        
for ( i=1; i<=OrdersTotal(); i++)         
     {        
    if (OrderSelect(i-1,SELECT_BY_POS)==true) 
        {                                      

         if (OrderSymbol()!= Symb) continue;    
          Tip=OrderType();                   
         if (Tip==1) continue;                 

      if (OrderMagicNumber()==4) 
      {Ticket_S=OrderTicket();}              
     }
     }
   while(true)                                
     {
      if (Limit_Stop==-1)                      
        {
         break;                                      
        }
        Ans_S=OrderDelete(Ticket_S);            

      if (Ans_S==true) 
        {
         break; 
        }
}
 
Egori4:


When you open a pending order, set an expiry time, say 23:59, the order will close by itself.

nt OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

 
lowech:

hello! problem with the code!!! i need the orders to open one by one sell, bay, sell etc., but the counting was done during the day, the next day by a new one, without considering the sequence of opening orders of previous day! that is a new day a new cycle! above code i think it should look like this! except that the EA does not open any order! can not understand what's wrong ...tell me if you know!!!


And why should it open orders, especially if the history is empty. And learn how to insert code humanly, I don't like editing other people's posts.
 
Sepulca:
Thank you! I'll try...
 

How to add to this advisor

//+------------------------------------------------------------------+

//| CCI.mq4 |

//| Copyright 2012, MetaQuotes Software Corp.

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "Copyright 2012, MetaQuotes Software Corp.

#property link "http://www.metaquotes.net"



extern double LotTrend = 0.1;

extern int TP=100;

extern int SL=250;


//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialisation function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)

{

if (Bid>iMA(Symbol(),PERIOD_M15,100,0,1,4,0)

)

{

OrderSend(Symbol(),OP_BUY,LotTrend,Ask,0,Ask-SL*Point,Ask+TP*Point,0,0,0,Green)

}

if (Bid<iMA(Symbol(),PERIOD_M15,100,0,1,4,0)

)

{

OrderSend(Symbol(),OP_SELL,LotTrend,Bid,0,Bid+SL*Point,Bid-TP*Point,0,0,0,Green);

}

}



//----

return(0);

}

//+------------------------------------------------------------------+

1.To open a trade only on close of a candle.(When price crosses SMA)

 

Hello! I have one question concerning the indicators in MQL4 and I cannot completely understand it... For example, I have a simple fractal indicator:

//+===========================================================================+ 
//|                                                                  FRAC.mq4 | 
//+===========================================================================+ 
// Параметры: 
// 
// По умолчанию frac_5 - оранжевый, frac_3 - темно-синий. 
//----- 
// History    - определяет на сколько глубоко в историю вам нужно отображение  
//              индикатора (в количестве свечей). Минимальное значение = 2. 
//-----  
// frac_3     - если значение "on", то frac_3 отображается, иначе нет. 
//-----  
// frac_5     - если значение "on", то frac_5 отображается, иначе нет. 
//+===========================================================================+ 
#property indicator_chart_window 
#property indicator_buffers            4     
#property indicator_color1  MidnightBlue 
#property indicator_color2  MidnightBlue  
#property indicator_color3        Orange 
#property indicator_color4        Orange 
//-----         
extern int         history     =     500; 
extern string       frac_3     =    "on";   
extern string       frac_5     =    "on";
extern int          metka      =      20;
//-----         
double FRAC_3_POS[]; 
double FRAC_3_NEG[]; 
double FRAC_5_POS[]; 
double FRAC_5_NEG[]; 

//+===========================================================================+ 

int init() 
   { 
     SetIndexBuffer (0, FRAC_3_POS);  
              
     SetIndexStyle  (0, DRAW_ARROW, 0, 3); 
      
     SetIndexArrow  (0, 217); 
   //-----         
     SetIndexBuffer (1, FRAC_3_NEG);    
            
     SetIndexStyle  (1, DRAW_ARROW, 0, 3); 
      
     SetIndexArrow  (1, 218); 
   //-----         
     SetIndexBuffer (2, FRAC_5_POS);      
          
     SetIndexStyle  (2, DRAW_ARROW, 0, 3); 
      
     SetIndexArrow  (2, 217); 
   //-----         
     SetIndexBuffer (3, FRAC_5_NEG);        
        
     SetIndexStyle  (3, DRAW_ARROW, 0, 3); 
      
     SetIndexArrow  (3, 218); 
      
    return(0); 
   } 

//+===========================================================================+ 

int start() 
   { 
    int i,Counted_bars; 
     
    Counted_bars = IndicatorCounted(); 
     
     i = Bars - Counted_bars - 1; 
     
     if (history < 2) 
      
         history = 2; 
                   
     if (i > history - 1) 
      
         i = history - 1;
         //i=Bars -  1;
    //----- 
     if (Digits <= 3) 
       
         double K = 0.01; 
       
     else       K = 0.0001;     
              
    while (i >= 0) 
          { 
           double FR_3P=0, FR_3N=0, 
                  FR_5P=0, FR_5N=0; 
          //-----         
           if (High[i+1] >= High[i+2] && High[i+1] >= High[i]) 
            
               FR_3P = High[i+1] + metka*K; 
          //-----         
           if (Low[i+1] <= Low[i+2] && Low[i+1] <= Low[i]) 
            
               FR_3N = Low[i+1] - metka*K; 
          //-----         
           if (High[i+2] >= High[i+4] && High[i+2] >= High[i+3] && High[i+2] >= High[i+1] && High[i+2] >= High[i]) 
            
               FR_5P = High[i+2] + metka*K; 
          //-----         
           if (Low[i+2] <= Low[i+4] && Low[i+2] <= Low[i+3] && Low[i+2] <= Low[i+1] && Low[i+2] <= Low[i]) 
            
               FR_5N = Low[i+2] - metka*K; 
          //-----  
           if (frac_3 != "on") 
              { 
               FR_3P = EMPTY; 
                 
               FR_3N = EMPTY; 
              }  
          //-----  
           if (frac_5 != "on") 
              { 
               FR_5P = EMPTY; 
                 
               FR_5N = EMPTY; 
              }       
          //-----  
            
               FRAC_3_POS[i+1] = FR_3P; 
                
               FRAC_3_NEG[i+1] = FR_3N; 
                
               FRAC_5_POS[i+2] = FR_5P; 
                
               FRAC_5_NEG[i+2] = FR_5N; 
               
               i--; 
          } 
      return(0); 
   } 
//+===========================================================================+ 

If you compile it in this form, it starts to glitch when extending the left graph border and loading history and shows marks where they shouldn't be (see screenshot in the attachment). If we comment out a part of the code:

if (history < 2) 
      
         history = 2; 
                   
     if (i > history - 1) 
      
         i = history - 1;

Then these glitches disappear... The same glitches appear when loading history, if you fill only "nonempty" elements of the indicator array and don't reset indicator value where there are no labels...

Why does this happen? Why, it turns out, is it necessary to recalculate the whole indicator when loading the history? And why do I have to null the values of "empty" elements of the array?

If the bars were indexed from left to right, at history loading the indexes of the bars would change, and the indicator would be incorrectly displayed without recalculation, then we would understand this glitch ... But in MT4 bars are indexed from right to left, so, when loading the history, the indexes of those bars that were previously there should have remained the same (and the indicator values, too), then why recalculate the indicator and where do these marker shifts come from?