How do we analyse the next bar? - page 3

 

no, i didn't get the picture, y u thinking to cacth @ 1 & get out up there (i want 2 LOL)

 

"@Ais:: What if I place the new orders in another function,say "New()". Will it open the orders not in the same bar but different ones?"
Depends on code of the new function.

 
If I use the following code, why isn't it opening orders in different bars? Rest of the code as being the same.
  if(Fun_New_Bar())
   {
   New();
   }





bool Fun_New_Bar()
   {
   static datetime New_Time = 0;
   bool New_Bar = false;
   if (New_Time!= Time[0])
      {
      New_Time = Time[0];
      New_Bar = true;
      }
   return(New_Bar);
   }




void New()
{
      FMA=iMA(NULL,0,MPeriod1,0,MODE_SMA,PRICE_OPEN,0);
      SMA=iMA(NULL,0,MPeriod2,0,MODE_SMA,PRICE_OPEN,0);
      PFMA=iMA(NULL,0,MPeriod1,0,MODE_SMA,PRICE_OPEN,1);
      PSMA=iMA(NULL,0,MPeriod2,0,MODE_SMA,PRICE_OPEN,1);

      if(FMA<SMA && Open[0]<Open[1] && High[0]<High[1]&& sellcond1==true)
      {
      OrderClose(ticket,0.1,Bid,3,Snow);     
      ticket2=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,SLS,TPS,"",_MagicNumber,0,Blue);//open new Sell Order
      sellcond1=false;
      buycond1=true;
      return(0);
      }
      
      if(FMA>SMA && Open[0]>Open[1] && High[0]>High[1] && buycond1==true)
      {
      OrderClose(ticket11,0.1,Ask,3,Gold);      
      ticket12=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,SLB,TPB,"",_MagicNumber,0,Red); // open new BUY Order 
      buycond1=false;
      sellcond1=true;
      return(0);
      }
      
}


 
ksrohit2712: 2010.12.01 16:12
"If I use the following code, why isn't it opening orders in different bars? ..."

Because:

ksrohit2712: 2010.12.01 16:12
"... Rest of the code as being the same."
 
But "if condition" won't help?
 
Need to correctly remake function "start()".
 
ksrohit2712:
If I use the following code, why isn't it opening orders in different bars? Rest of the code as being the same.
  1.    FMA=iMA(NULL,0,MPeriod1,0,MODE_SMA,PRICE_OPEN,0);
       SMA=iMA(NULL,0,MPeriod2,0,MODE_SMA,PRICE_OPEN,0);
       PFMA=iMA(NULL,0,MPeriod1,0,MODE_SMA,PRICE_OPEN,1);
       PSMA=iMA(NULL,0,MPeriod2,0,MODE_SMA,PRICE_OPEN,1);
    
    At the beginning of a new bar FMA and PFMA will be almost the same. Use 1,2 not 0,1 as Qjol already said.

  2. OrderClose(ticket,0.1,Bid,3,Snow);     
    ticket2=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,SLS,TPS,"",_MagicNumber,0,Blue);//open new Sell Order
    ...
    OrderClose(ticket11,0.1,Ask,3,Gold);      
    ticket12=OrderSend(Symbol(),OP_BUY
    You have 4 ticket variables, you should have only one.
 

With this function "start()":

 
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
 
if(Fun_New_Bar())
   {
   New();
   }
 
checkclose();
   
//----
  }
//+------------------------------------------------------------------+
 

last changes make send orders only once in current bar.

Reason: