<MyLib.mqh>

#define
MAGIC 3070405
#define
COMMENT "PSAR"

extern double Lots = 0.1;
extern int Slippage = 3;

extern string SAR_Parameters="---SAR---";
extern double SAR_step = 0.02;
extern double SAR_maximum = 0.2;

int EntrySignal(int magic)
{
  //オープンポジションの計算
  double pos = MyCurrentOrders(MY_OPENPOS, magic);
  
  //Parabolic SARの計算
  //double iSAR(string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)
  double SAR0 = iSAR(NULL, 0, SAR_step, SAR_maximum, 0); 
  double SAR1 = iSAR(NULL, 0, SAR_step, SAR_maximum, 1); 
  double Close0 = iClose(NULL, 0, 0); 
  double Close1 = iClose(NULL, 0, 1); 
  int ret = 0;
  
  //買いシグナル ポジションを持っていない時にパラボリックが足の下に転換(上昇トレンドを示唆) 
  if(pos <=0 && SAR0 < Close0 && SAR1 > Close1 ) ret = 1;
  //売りシグナル パラボリックが足の上に転換(下降トレンドを示唆) 
  if(pos >=0 && SAR0 > Close0 && SAR1 < Close1 ) ret = -1;
  
  return(ret);
}

int start()
{
  // エントリーシグナル
  int sig_entry = EntrySignal(MAGIC);
  
  //買い注文
  if(sig_entry > 0)
  {
     MyOrderClose(Slippage, MAGIC);//MyOrderClose(P242)
     MyOrderSend(OP_BUY, Lots, Ask, Slippage, 0, 0, COMMENT, MAGIC);//MyOrderSend(P236)
  }
  //売り注文
  if(sig_entry < 0)
  {
     MyOrderClose(Slippage, MAGIC);
     MyOrderSend(OP_SELL, Lots, Bid, Slippage, 0, 0, COMMENT, MAGIC);
  }
  
  return(0);
}
最終更新:2010年11月28日 11:37