Suggest how to fix this code

 

Please suggest what do I need to change on this code? Idea for code is to place at last bars one BuyStop at high and one SellStop at low. This code is just adding SellStops.

extern double lot = 0.1;
datetime PreviousBar;      // record the candle/bar time

bool NewBar()
{
   if(PreviousBar<Time[0])
   {
      PreviousBar = Time[0];
      return(true);
   }
   else
   {
      return(false);
   }
   return(false);    // in case if - else statement is not executed
}
int start()
  {
     double h1 = iHigh(NULL,PERIOD_D1,1);
     double o1 = iOpen(NULL,PERIOD_D1,1);
     double c1 = iClose(NULL,PERIOD_D1,1);
     double l1 = iLow(NULL,PERIOD_D1,1);
     {
    
     int ticket;
     if(NewBar() == true)
     ticket=OrderSend(Symbol(),OP_BUYSTOP,lot,h1,0,(h1-(h1-l1)),(h1+(h1-l1)),"Shadow buy",0,0);
       {
        Print("OrderSend buystop failed with error #",GetLastError());
        //return(0);
       }
    
     ticket=OrderSend(Symbol(),OP_SELLSTOP,lot,l1,0,(l1+(h1-l1)),(l1-(h1-l1)),"Shadow sell",0,0);
       {
        Print("OrderSend sellstop failed with error #",GetLastError());
        //return(0);
       }

     
     }
   return(0);
  }
  

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

what error u get (i c u have writen 2 c the last error (Print("OrderSend sellstop failed with error #",GetLastError());))

 
qjol:

what error u get (i c u have writen 2 c the last error (Print("OrderSend sellstop failed with error #",GetLastError());))


There is no error (it is showing Error - #0). Problem is that code is placing one BuyStop and endless SellStop orders. I haven't figured it out why.

Idea is to make code place one BuyStop and one SellStop order on previous bar High and Low.

 

try BUYLIMIT 2

something like this:

if(NewBar() == true)
   {
   ticket = OrderSend(Symbol(),OP_BUYSTOP,lot,h1,0,(h1-(h1-l1)),(h1+(h1-l1)),"Shadow buy",0,0);
   if (ticket == -1)
      {
      Print("OrderSend buystop failed with error #",GetLastError());
      ticket=OrderSend(Symbol(),OP_BUYLIMIT,lot,h1,0,(h1-(h1-l1)),(h1+(h1-l1)),"Shadow buy",0,0);
      if (ticket == -1)
         {
         Print("OrderSend buystop failed with error #",GetLastError());
         return(0);
         }
      }
   
   ticket = OrderSend(Symbol(),OP_SELLSTOP,lot,l1,0,(l1+(h1-l1)),(l1-(h1-l1)),"Shadow sell",0,0);
   if (ticket == -1)
      {
      Print("OrderSend sellstop failed with error #",GetLastError());
      ticket = OrderSend(Symbol(),OP_SELLLIMIT,lot,l1,0,(l1+(h1-l1)),(l1-(h1-l1)),"Shadow sell",0,0);
      if (ticket == -1)
         {
         Print("OrderSend sellstop failed with error #",GetLastError());
         return(0);
         }
      }
   }
 

regardless

(h1-(h1-l1)) == l1

(l1+(h1-l1)) == h1

 
gordon:

Define a block for the if statement like so...

Before the if statement only referred to the line immediately following it.


u say the problem isn't BUYSTOP or BUYLIMIT
 
I deleted that message... U beat me to it.
 
gordon:
I deleted that message... U beat me to it.

Oops, didn't mean it was just a question, sorry
 
qjol:

try BUYLIMIT 2

something like this:


Thank you! I got it working. Don't really understood what was different than I tried before posting my problem.

Also thanks for pointing at ..== l1 &..==h1!

I will start learning how to implement next trick for my EA.

 

Now, can anyone tell me how to get expiration dates in the ordersend() function?

Thanks!

 
datetime expire = D'2010.12.23 00:25';
OrderSend(Symbol(),OP_BUYLIMIT,0.1,Ask-1000*Point,3,Ask-2000*Point,Ask+2000*Point,"",12345,expire,Green);
Reason: