[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 149

 

This is where I recently answered an analogous question.

https://www.mql5.com/ru/forum/109048/page11

-Look it up.

In your case, you could probably go like this:

if ( AutoClose) { //если выключатель закрытия включен 

//----------------------------------------------------------------------
  for (int v=0; v<OrdersTotal(); v++)                             {       
      if (OrderSelect( v, SELECT_BY_POS, MODE_TRADES))               {           
        if (OrderSymbol()==Symbol()&& OrderMagicNumber()== MagicNum)   { 
//-----------------------------------------------------                  
if (OrderType() == OP_BUY) { 
      
           OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // закрываем позицию
                 //return(0); // выходим
                }       
      
 //--------------------------------------------------------
if (OrderType() == OP_SELL) { 
     
                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // закрываем позицию
                // return(0); // выходим
                }       
   
 //-------------------------------------------------------                       
    }  // Symbol()  
  } // select
 } //total
} //Close_
 

Gentlemen, please explain the difference between

NormalizeDouble(High[iHighest(NULL,0,MODE_HIGH,10,0)],4)
from
NormalizeDouble(High[iHighest(NULL,0,MODE_HIGH,iBarShift(NULL,0,Time[1],FALSE),1)] + 10 * Point,4)

I don't understand what iBarShift is and what it does

 
rid >> :

This is where I recently answered an analogous question.

'A question for connoisseurs'.

-See this.

In your case, you could probably go like this:


Thanks, rid!

It worked for me, I did it like this.

   if (( Close_P)&& TimeCurrent()>=StrToTime( CloseHour+":00")){  // даже по времени сделал
   int slippage=3;
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
    if (!OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) break;
    if (OrderType()==OP_BUY ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID), slippage);
    if (OrderType()==OP_SELL) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK), slippage);
    }
    }


 
Dimoncheg >> :

Gentlemen, could you please explain the difference between

from

I don't understand what iBarShift is and what it does

int iBarShift( string symbol, int timeframe, datetime time, bool exact=false)
Search for a bar by time. The function returns the offset of the bar to which the specified time belongs. If there is no bar for the specified time (a "hole" in the history), the function returns, depending on the exact parameter, -1 or the offset of the nearest bar.
Parameters:
symbol - Symbol name of the instrument. NULL means current symbol.
timeframe - Period. Can be one of the timeframes of a chart. 0 means period of the current chart.
time - Time value to search for.
exact - Returned value if no bar is found. FALSE - iBarShift returns closest. TRUE - iBarShift returns -1.
 
1Rakso >> :
int iBarShift(string symbol, int timeframe, datetime time, bool exact=false)
Bar search by time. The function returns the offset of the bar to which the specified time belongs. If there is no bar for the specified time (a "hole" in the history), the function returns -1 or the offset of the nearest bar, depending on the exact parameter.
Parameters:
symbol - Symbol name of the instrument. NULL means current symbol.
timeframe - Period. Can be one of the timeframes of a chart. 0 means the period of the current chart.
time - Time value to search for.
exact - Returned value if no bar is found. FALSE - iBarShift returns closest. TRUE - iBarShift returns -1.

I've read the reference, but I do not understand what it says: "The function returns the shift of the bar" - what does it mean? If I've read the first one, it simply means the number of candlesticks and the second one means some displacement. I think I need the nearest high after some conditions, the first case will not work because I may not see max 10 bars (and may not see max 20 or 30 either), how should I describe it correctly (the nearest high for example after crossing 2 Mascos)?

 
Dimoncheg >> :

I've read the help, but I don't understand what it says, "The function returns the shift of the bar" - what does it mean? If I've read the first one, it simply means the number of candlesticks, and the second one means some displacement. I think I need the nearest high after some conditions, the first case will not work because I may not see max 10 bars (and may not see max 20 or 30 either), what will be the right way to do it (the nearest high after 2 Mascos crossing for example)?

ibarshift shows in which bar from the beginning of the chart the n-th second time

 
Dimoncheg >> :

I've read it, but I don't understand what it says: "The function returns the bar shift" - what does it mean? If I've read the first one, it simply means the number of candlesticks, but the second one means some displacement. I think I need the nearest high after some conditions, the first case will not work because I may not see max 10 bars (and may not see max 20 or 30 either), what is the correct way to do it (the nearest high after crossing 2 Mascos)?

You give it Time and you get a schift.

Suppose you know the time of zero bar.

Some events have passed,

The situation has changed, and you want to check the position of the bar with this time compared to the zero bar.

This is where you need this function.

 

Dimoncheg

I'm a customer of this section myself)

======================

I have another question, how to divide the beam ZZ in half to calculate its level and make a fix at this level?


   double ind1. up = iCustom(Symbol(), PERIOD_H1, "ZigZag_NK", ZZ_Depth1, 5, 3, 0, 0);
   double ind1. dn = iCustom(Symbol(), PERIOD_H1, "ZigZag_NK", ZZ_Depth1, 5, 3, 1, 0);
   if ( ind1. up != EMPTY_VALUE  ) ind1. arr_1 =- 1;
	else if ( ind1. dn != EMPTY_VALUE )   ind1. arr_1 = 1;  
   

   if (( Close_P)&& ind. arr_1 /2*Point){   // как вписать формулу что я не так делаю? 
   
   int slippage=3;
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
    if (!OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) break;
    if (OrderType()==OP_BUY ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID), slippage);
    if (OrderType()==OP_SELL) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK), slippage);
    }
    }
 
My indicator inside the code is reinitialised, I need to know the state before and after to compare. What is the best way to implement this process?
 
1Rakso >> :

Dimoncheg

I'm a customer of this section myself)

======================

I have another question, how to divide the beam ZZ in half that would calculate its level and make a fix at this level?


The zigzag is not calculated at the last point. As a rule, it cannot be fixed at this level either.

Reason: