Horizontal Lines on Array and Problem with order opening

To add comments, please log in or register
Stanislav Ivanov
6592
Stanislav Ivanov  

Hi,

I`m having a problem with a piece of code for an EA. I want to open orders Buy above the line and Sell below, on every line as follows, there is also trigger distance if reverse order is to be opened, the price has to break that level, the lines will be manually drown. This is the piece of code that is problematic, hope someone can help me!

for(int i=0;i<ObjectsTotal();i++)
 { 
 string objectname = ObjectName(ChartID(),i);
double  hline=ObjectGet(objectname,OBJPROP_PRICE1);
if(ObjectType(objectname)==OBJ_HLINE)
{
lin++;
ArrayResize(lineS,lin);
ArrayResize(lineB,lin);
if(Bid>hline)lineS[l]=hline;
if(Bid<hline)lineB[l]=hline;
l++;
ArraySort(lineB,WHOLE_ARRAY,0,MODE_ASCEND);
ArraySort(lineS,WHOLE_ARRAY,0,MODE_DESCEND);
 lineBmin = ArrayMinimum(lineB,WHOLE_ARRAY,0);
 lineSmax = ArrayMaximum(lineS,WHOLE_ARRAY,0);

}
if( lineB[lineBmin]+offset*point<Close[0] && lineB[lineBmin]+offset*point>Open[0] && lineB[lineBmin]>0 )
 {
 buyHLA=true;
 }  
if(lineS[lineSmax]-offset*point>Close[0] && lineS[lineSmax]-offset*point<Open[0] && lineS[lineSmax]>0 )
 {
 sellHLB=true;
 }
else buyHLA=false;sellHLB=false; 

//----------------------------
for(int k=0;k<=OrdersTotal();k++)
 {
 if(OrderSelect(k,SELECT_BY_POS,MODE_TRADES))
 if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())
  {
  if(OrderType()==OP_BUY)
   {
   if(OrderOpenPrice()<lineB[lineBmin] && OrderOpenPrice()>lineS[lineSmax] && buyHLA==true && Close[0]<lineB[lineBmin+1]+offset*point)
    {
    buyHLA=false;
    }
   if(OrderOpenPrice()<lineB[lineBmin] && OrderOpenPrice()>lineS[lineSmax] && sellHLB==true && Low[0]>lineS[lineSmax+1]-trigger_distance*point ) 
    {
    sellHLB=false;
    }
   }
  if(OrderType()==OP_SELL) 
   {
   if(OrderOpenPrice()<lineB[lineBmin] && OrderOpenPrice()>lineS[lineSmax] && sellHLB==true && Close[0]>lineS[lineSmax+1]-offset*point)
    {
    sellHLB=false;
    }
   if(OrderOpenPrice()<lineB[lineBmin] && OrderOpenPrice()>lineS[lineSmax] && buyHLA==true && High[0]<lineB[lineBmin]+trigger_distance*point ) 
    {
    buyHLA=false;
    }
   }
  }
 }
 }
To add comments, please log in or register