2 closing price

 
void CheckForOpen()
  {
   double ma;
   int    res;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
   ma=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,0); 
//---- sell conditions
   if(Open[1]>ma && Close[1]<ma) continue;
   if(Open[2]<ma && Close[2]<ma);
     {
      res=OrderSend(Symbol(),OP_SELL, GetLots(),Bid,3,0,0,"",BROV,0,Red);
      return;
     }
//---- buy conditions
   if(Open[1]<ma && Close[1]>ma) continue;
   if(Open[2]>ma && Close[2]>ma);
     {
      res=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,3,0,0,"",BRO,0,Blue);
      return;
     }
//----
  }





void CheckForOpen()
  {
   double ma;
   int    res;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
   ma=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,0); 
//---- sell conditions
   if(Open[1]>ma && Close[1]<ma) return;
   if(Open[2]<ma && Close[2]<ma);
     {
      res=OrderSend(Symbol(),OP_SELL, GetLots(),Bid,3,0,0,"",BROV,0,Red);
      return;
     }
//---- buy conditions
   if(Open[1]<ma && Close[1]>ma) return;
   if(Open[2]>ma && Close[2]>ma);
     {
      res=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,3,0,0,"",BRO,0,Blue);
      return;
     }
//----
  }




void CheckForOpen()
  {
   double ma1,ma2;
   int res;
//----go trading only first tiks of new Bars
   if(Volume[0]>1 return;
//----get Moving Average
   ma1=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,1)
   ma2=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,2)
//----sell conditions
   if(Open[1]>ma1&&Close[1]<ma1)return;
   if(Open[2]<ma2&&Close[2]<ma2);
     {
      res=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,3,0,0,"Good luck",MAGICMA,0,Magenta);
      return;
     }
//----buy conditions
   if(Open[1]<ma1 && Close[1]>ma1)return;
   if(Open[2]>ma2 && Close[2]>ma2);
   {
    res=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,3,0,0,"Good luck",MAGICMA,0,Aqua);
    return;
   }
  }

 

Which of these three codes is right. I'm a newbie in coding please help.

When have 2 closing price above moving average buy.

When have 2 closing price below moving average sell.

Thanks.

 
   if(Close[1]>ma)
       if(Close[2]>ma)
          {
          res=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,3,0,0,"",BRO,0,Blue);
          return;
          }

this will open a buy if the last bar and the bar before that are above the ma. Do you want to check if the current bar, Close[0], is above the ma too?

also, by the coding example, I think you really mean close above ma AND open below the ma?

sn

 

1 bar break a moving average and close above - waiting - second bar close above ma - and open long position.

Terms is to buy when have 2 closing price above ma.

First bar open below and close above ma. Second bar open above him and close above ma.

I want two closing bars above, i don't give a ... for opens.

Is it right that below i posted.

Thanks a lot.

 
void CheckForOpen()
  {
   double ma;
   int res;
//----go trading only first tiks of new Bars
   if(Volume[0]>1 return;
//----get Moving Average
   ma=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,0);
//----sell conditions
   if(Close[1]<ma)
       if(Close[2]<ma)
         {
          res=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,3,0,0,"Good luck",MAGICMA,0,Magenta);
          return;
         }
//----buy conditions
   if(Close[1]>ma)
       if(Close[2]>ma)
         {
          res=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,3,0,0,"Good luck",MAGICMA,0,Aqua);
          return;
         }
  }
 
  1.  if(Volume[0]>1 return;
    
    Volume is unreliable, Bars is unreliable. Always use time.
    int start(){    static datetime Time0;
      if (Time0 == Time[0]) return; Time0 = Time[0];

  2.  if(Open[1]>ma && Close[1]<ma) continue;
    
    This won't even compile, you're not in a loop.
 
First code of my first post is right, so i must Volume to define it right.
 
 if(Open[1]>ma && Close[1]<ma) - that must be check. How to continue to check second closing price and after check it - to do action.
 if(Open[2]<ma && Close[2]<ma) that is for sell conditions. Thanks a lot
Reason: