place pending order when line is touched - not working...

 

Good evening,

i'm having trouble to let my EA place pending orders when the middle white line on the chart is touched/reached. What am i doing wrong?

i only left the necessary code in here, because it was too long to post here...

double         BottomGoldLine;//Bottom, gold line
double         BottomGreenLine;//Bottom, green line
double         MiddleWhiteLine;//Middle, white line
double         TopGreenLine;//Top, green line
double         TopGoldLine;//Top, gold line
double         TopLine, BottomLine;
double         HalfTopLine, HalfBottomLine;
int BarCount;

extern int MagicNumber = 3;
extern double lots = 0.1;

//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

int ready;
double TP, SL, entry;
double TPw1, SLw1, entryw1, TPw2, SLw2, entryw2;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if (Digits == 5 || Digits == 3)
   {    // Adjust for five (5) digit brokers.
               pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
   } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   double ctgl = TopGoldLine;
   double cbgl = BottomGoldLine;
   BarCount = NormalizeDouble((iATR(NULL,1440 ,200,0)/MarketInfo(Symbol(),MODE_POINT))/10,0);
   double value = High[iHighest(NULL,0,MODE_HIGH,BarCount,1)] - Low[iLowest(NULL,0,MODE_LOW,BarCount,1)];      //value top of the chart - value bottom
   double sixth = value/6;
   TopLine = NormalizeDouble(High[iHighest(NULL,0,MODE_HIGH,BarCount,1)], Digits);
   HalfTopLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)]+sixth+sixth+sixth+sixth+sixth+(sixth / 2), Digits);
   BottomLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)], Digits);
   HalfBottomLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)]+(sixth / 2),Digits);
   BottomGoldLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)]+sixth, Digits);
   BottomGreenLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)]+sixth+sixth, Digits);
   MiddleWhiteLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)]+sixth+sixth+sixth, Digits);
   TopGreenLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)]+sixth+sixth+sixth+sixth, Digits);
   TopGoldLine = NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,BarCount,1)]+sixth+sixth+sixth+sixth+sixth, Digits);
      //Draw the lines
      double tl = ObjectGet("fivesixth", OBJPROP_PRICE1);
      double bl = ObjectGet("onesixth", OBJPROP_PRICE1);
      
      if(tl != TopGoldLine || bl != BottomGoldLine) 
      {
         if (ObjectFind("zerosixth") == -1)
         {
            ObjectCreate("zerosixth",1,0,TimeCurrent(),BottomLine);
            ObjectSet("zerosixth",OBJPROP_COLOR,Magenta);
            ObjectSet("zerosixth",OBJPROP_STYLE,STYLE_SOLID);
            ObjectSet("zerosixth",OBJPROP_WIDTH,2);     
         }//if (ObjectFind("zerosixth") == -1)
         else ObjectMove("zerosixth",0,TimeCurrent(),BottomLine);
      
         if (ObjectFind("halfbottomsixth") == -1)
         {
            ObjectCreate("halfbottomsixth",1,0,TimeCurrent(),HalfBottomLine);
            ObjectSet("halfbottomsixth",OBJPROP_COLOR,Magenta);
            ObjectSet("halfbottomsixth",OBJPROP_STYLE,STYLE_DASH);
            ObjectSet("halfbottomsixth",OBJPROP_WIDTH,1);     
         }//if (ObjectFind("halfbottomsixth") == -1)
         else ObjectMove("halfbottomsixth",0,TimeCurrent(),HalfBottomLine);
      
         if (ObjectFind("onesixth") == -1)
         {
            ObjectCreate("onesixth",1,0,TimeCurrent(),BottomGoldLine);
            ObjectSet("onesixth",OBJPROP_COLOR,Gold);
            ObjectSet("onesixth",OBJPROP_STYLE,STYLE_SOLID);
            ObjectSet("onesixth",OBJPROP_WIDTH,2);     
         }//if (ObjectFind("onesixth") == -1)
         else ObjectMove("onesixth",0,TimeCurrent(),BottomGoldLine);
      
         if (ObjectFind("twosixth") == -1)
         {
            ObjectCreate("twosixth",1,0,TimeCurrent(),BottomGreenLine);
            ObjectSet("twosixth",OBJPROP_COLOR,Green);
            ObjectSet("twosixth",OBJPROP_STYLE,STYLE_SOLID);
            ObjectSet("twosixth",OBJPROP_WIDTH,2);    
         }//if (ObjectFind(
         else ObjectMove("twosixth",0,TimeCurrent(),BottomGreenLine);

         if (ObjectFind("threesixth") == -1)
         {
            ObjectCreate("threesixth",1,0,TimeCurrent(),MiddleWhiteLine);
            ObjectSet("threesixth",OBJPROP_COLOR,White);
            ObjectSet("threesixth",OBJPROP_STYLE,STYLE_SOLID);
            ObjectSet("threesixth",OBJPROP_WIDTH,2);
         }//if (ObjectFind(
         else ObjectMove("threesixth",0,TimeCurrent(),MiddleWhiteLine);
      
         if (ObjectFind("foursixth") == -1)
         {
            ObjectCreate("foursixth",1,0,TimeCurrent(),TopGreenLine);
            ObjectSet("foursixth",OBJPROP_COLOR,Green);
            ObjectSet("foursixth",OBJPROP_STYLE,STYLE_SOLID);
            ObjectSet("foursixth",OBJPROP_WIDTH,2);
         }//if (ObjectFind(
         else ObjectMove("foursixth",0,TimeCurrent(),TopGreenLine);
      
         if (ObjectFind("fivesixth") == -1)
         {
            ObjectCreate("fivesixth",1,0,TimeCurrent(),TopGoldLine);
            ObjectSet("fivesixth",OBJPROP_COLOR,Gold);
            ObjectSet("fivesixth",OBJPROP_STYLE,STYLE_SOLID);
            ObjectSet("fivesixth",OBJPROP_WIDTH,2);
         }//if (ObjectFind(
         else ObjectMove("fivesixth",0,TimeCurrent(),TopGoldLine);
            
         if (ObjectFind("halftopsixth") == -1)
         {
            ObjectCreate("halftopsixth",1,0,TimeCurrent(),HalfTopLine);
            ObjectSet("halftopsixth",OBJPROP_COLOR,Magenta);
            ObjectSet("halftopsixth",OBJPROP_STYLE,STYLE_DASH);
            ObjectSet("halftopsixth",OBJPROP_WIDTH,1);     
         }//if (ObjectFind("halftopsixth") == -1)
         else ObjectMove("halftopsixth",0,TimeCurrent(),HalfTopLine);
      
         if (ObjectFind("sixsixth") == -1)
         {
            ObjectCreate("sixsixth",1,0,TimeCurrent(),TopLine);
            ObjectSet("sixsixth",OBJPROP_COLOR,Magenta);
            ObjectSet("sixsixth",OBJPROP_STYLE,STYLE_SOLID);
            ObjectSet("sixsixth",OBJPROP_WIDTH,2);     
         }//if (ObjectFind("sixsixth") == -1)
         else ObjectMove("sixsixth",0,TimeCurrent(),TopLine);
      }
   //}
   double minlot  = MarketInfo(Symbol(),MODE_MINLOT);
   if (minlot == 0.01)   lots = NormalizeDouble(lots,2);
   if (minlot == 0.1)    lots = NormalizeDouble(lots,1);
   if (minlot == 1)      lots = NormalizeDouble(lots,0);

   //SELL ORDER
   if (Bid == TopLine)   {
     entry = HalfTopLine;
     TP    = TopGoldLine;
     SL    = TopLine;
     Print("Pending SELL Order placed");
     OrderSend(Symbol(),OP_SELLSTOP,lots,entry,100,SL,TP,NULL,MagicNumber,0,Red);
     Print (GetLastError());
   }
   //END SELL ORDER
  
   //BUY ORDER
   if (Ask == BottomLine)    {
     entry = HalfBottomLine;
     TP    = BottomGoldLine;
     SL    = BottomLine;
     Print("Pending BUY Order placed");
     OrderSend(Symbol(),OP_BUYSTOP,lots,entry,100,SL,TP,NULL,MagicNumber,0,Blue);
     Print (GetLastError());
   }
   //END BUY ORDER   
     
   //CENTERLINE ORDER
   if (Ask == MiddleWhiteLine)    {
     entryw1 = TopGreenLine; 
     TPw1    = TopGoldLine;
     SLw1    = MiddleWhiteLine;
     entryw2 = BottomGreenLine;
     TPw2    = BottomGoldLine;
     SLw2    = MiddleWhiteLine;
     Print("Pending GSPE Orders placed");
     OrderSend(Symbol(),OP_BUYSTOP,lots,entryw1,100,SLw1,TPw1,NULL,MagicNumber,0,Blue);
     Print (GetLastError());
     Sleep(1000);
     OrderSend(Symbol(),OP_SELLSTOP,lots,entryw2,100,SLw2,TPw2,NULL,MagicNumber,0,Red);
     Print (GetLastError());
   }
   //END CENTERLINE ORDER    
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

what error u get ?

 
qjol:

what error u get ?


none, it just doesn't place the two pending orders when the white line is touched/reached?
 

have u tried BUY/SELL LIMIT

 

no, they need to be buy/sell STOPS. LIMIT is different kind of order :)

got it fixed now by changing the line to: if (Ask>=MiddleWhiteLine && Bid<=MiddleWhiteLine&& ready==1), seems like == was not right to compare two double values :)

now i just have to figure out, from two pending orders, how to close the other one, when one of the pending orders is opened (OCO?)

Reason: