Wrong interpretation of bar.

 

Hello.

I have problem with my simple EA.

Robot should open position when bar is bigger than 30 pips but he opening positions very unclearly (after only 3 pips) and i don't know why.

Anyone could help??



#include <Trade\Trade.mqh>
CTrade          trade;
#include <Trade\SymbolInfo.mqh> 
CSymbolInfo     m_symbol;               
             

//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+


input ushort Bar =30;

double digit=0;
bool glSellPlaced;

//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+

  
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void  OnInit()
{


}
void OnTick()
  {
 m_symbol.Name("EURUSD");               
  
  
  bool openPosition=PositionSelect(m_symbol.Name());
  long positionType=PositionGetInteger(POSITION_TYPE);
  digit = MathPow(10,Digits());

  
   MqlRates bar[];
ArraySetAsSeries(bar,true);
CopyRates(m_symbol.Name(),PERIOD_M15,0,2,bar);

double open0  = bar[0].open*digit;
double open1  = bar[1].open*digit; 

double low0   = bar[0].low*digit;
double close1 = bar[1].close*digit;

double OmL =open0-low0;

if(glSellPlaced == false && positionType != POSITION_TYPE_SELL)
   {
if(OmL>Bar)
  {
     double volume = 0.1;
     string symbol =m_symbol.Name();
     double point=SymbolInfoDouble(symbol,SYMBOL_POINT); 
     double bid=SymbolInfoDouble(symbol,SYMBOL_BID);
     double SL=bid+100*point;
     double TP=0;
          double open_price=SymbolInfoDouble(m_symbol.Name(),SYMBOL_BID);
          
        trade.Sell(volume,m_symbol.Name(),open_price,SL,TP);
        glSellPlaced == true;
        Sleep(1500000);
    }
   }
    if(positionType == POSITION_TYPE_SELL)
                { 
                if(open1<close1)
                {
            trade.PositionClose(m_symbol.Name());  
            glSellPlaced  == false; 
                }
                
         }
   }
  
  
 
 

P.s. Sorry for english.

Thanks for attention.

Reason: