anybody help my ea coding trade per candle & trailing stop

 
int start()

{
      if (Hour()>=7&&Hour()<=18)

  
             { 
               if (OrdersTotal()==0)
                   { 
                     if(Bid == Open[0]-4*Point)
                        {OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,0);
                        }    
                        else
                           if(Ask == Open[0]+4*Point)
                              {OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,0);
                              }
                              
                    }
                       if(TrailingStop>0)
                        {                
                           if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                           {
                              if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                              {
                                 OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                                 return(0);
                               }
                           }
                        }
             }
 

   
//----
   return(0);
}
the problem is order not open every candle sometimes..and the trailing is not working...TF H1
anybody help...!!!!
 
Did you try the search?
 
 if (Hour()>=7.30&&Hour()<=18.30)
    {
    // ...
This won't work as you think it would... Hour() returns an int with possible values 0,1,2,...,23. You can't compare it to 7.30 (which is the double number 7.3) and expect the minutes to be magically considered...
 
gordon:

This won't work as you think it would... Hour() returns an int with possible values 0,1,2,...,23. You can't compare it to 7.30 (which is the double number 7.3) and expect the minutes to be magically considered...


thank's...it's really help... but how abaout trade per candle & trailing can u help me?
 
robofx.org:
Did you try the search?


i did not know what you trying to told me? can u explain more specific?
 
in4nrm:


i did not know what you trying to told me? can u explain more specific?

You are not the first to ask this. Just search the forum.

 
int start()


{//1

         bool NewBar() 

         {//2
               static datetime lastbar = 0;
               datetime curbar = Time[0];

                  if(lastbar!=curbar)

                  {//3
                        lastbar=curbar;
                        return (true);
                  }//3

                else

                   {//4
                     return(false);
                   }//4

          }//2


            if(NewBar())

               {//5
                  if (Hour()>=8 && Hour()<=15)
                  if (OrdersTotal()==0) 
                     {//6
                        if(Bid == Open[0]-5*Point)
                        {//7
                        OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,txComment,MagicNumber);
                        }//7

                           else 
                           if(Ask == Open[0]+5*Point)
                              {//8
                              OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,txComment,MagicNumber);
                              )//8
            
      
      
                      }//6   
                 }//5
 
    

 



 
//----
   return(0);
 }  
robofx.org:

You are not the first to ask this. Just search the forum.

you mean like this ..??? i can't compile that code (there is 5 error) ...where is my mistake??please help me...!!!

 
in4nrm wrote >>

you mean like this ..??? i can't compile that code (there is 5 error) ...where is my mistake??please help me...!!!



if(Ask == Open[0]+5*Point)
{//8
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,txComment,MagicNumber);
)//8

for example: block should be closed by character } and not by )

All errors are described by your compiler when you are using MetaEditor for development.
So my advice is to check errors decription returned by compiler.

Folvo

 
if(Bid == Open[0]-4*Point){
   OrderSend(Symbol(), OP_SELL,Lots, Bid, Slippage, Bid+StopLoss*Point, Bid-TakeProfit*Point, 0);
}    

you can not compare doubles with == (except == 0) they will never be EXACTLY equal. you probably want
if(Bid >= Open[0]+5*Point)
Also, on a 5 digit broker a Pip is NOT a Point so the above is a 1/2 pip not 5 pips. You must adjust all constants
//++++ 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 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; }
Reason: