MACD Sampleの中身4

kawarobo 2005年6月15日 02:02

//print("Check: ",TotalTrades);//デバッグ用。Printは文字列を表示する
//PrintTrade(1);//デバッグ用。直近のポジション情報を表示

//ここからはポジションを閉じる条件を設定している

for cnt=1 to TotalTrades
//Forで指定回数繰り返す
//現在のポジション&未決オーダー数ぶん、以下を繰り返し実行
{ //forのはじまり
 if OrderValue(cnt,VAL_TYPE)<=OP_SELL and
  OrderValue(cnt,VAL_SYMBOL)=Symbol then

 //OrderValue=ポジションの情報を得る。
 //OP_BUY < OP_SELL < OP_BUYLIMIT < OP_SELLLIMIT < OP_BUYSTOP < OP_SELLSTOP の関係。
 //現在選択中のシンボル(通貨組み合わせ)でポジションがあるなら、の意。
 { // 2
  If OrderValue(cnt,VAL_TYPE)=OP_BUY then // 買いポジションなら
  { // 2_1
   // 現在MACDが正で、MACDがシグナルを上から下へクロスし、
   // MACD絶対値がクローズレベルを超えているなら、ポジションを閉じる
   If MacdCurrent&rt0 and MacdCurrent<SignalCurrent and
    MacdPrevious&rtSignalPrevious and
    MacdCurrent&rt(MACDCloseLevel*Point) then

   { // 2_1_1
    CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet);
    // CloseOrder=ポジションを閉じる
    Exit; //終了
   }; // 2_1_1

   // (2_1_1に当てはまらなかった場合ここに来る)
   // トレイリングストップが設定されている場合はストップ値を変更
   If TrailingStop&rt0 then
   {
// 2_1_2
    If (Bid-OrderValue(cnt,VAL_OPENPRICE))&rt(Point*TrailingStop) then
    //売値-ポジの買値>トレーリングストップ値より大なら
    { // 2_1_2_1
     If OrderValue(cnt,VAL_STOPLOSS)<(Bid-Point*TrailingStop) then
     //ポジのストップ値がまだ引き上げられていないなら
      { // 2_1_2_1_1
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Bid-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red);
      //ストップ値を編集。ストップ値を引き上げる
      //ModifyOrder=オーダーを変更
      Exit;
     }; //2_1_2_1_1
    }; // 2_1_2_1
    }; // 2_1_2
  } // 2_1
  else // 売りポジションなら
  { // 2_2
  // 現在MACDが負で、MACDがシグナルを下から上にクロスし、
  // MACD絶対値がクローズレベルを超えているなら、ポジションを閉じる
   If MacdCurrent<0 and MacdCurrent&rtSignalCurrent and
    MacdPrevious<SignalPrevious and
    Abs(MacdCurrent)&rt(MACDCloseLevel*Point) then
   {
// 2_2_1
CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet);
    Exit;
// 終了
   }; // 2_2_1
   // そうでないなら
   If TrailingStop&rt0 then
   //トレーリングストップ設定あればストップ値編集
   { // 2_2_2
    If (OrderValue(cnt,VAL_OPENPRICE)-Ask)&rt(Point*TrailingStop) then
    {
//2_2_2_1
     If OrderValue(cnt,VAL_STOPLOSS)=0 or
      OrderValue(cnt,VAL_STOPLOSS)&rt(Ask+Point*TrailingStop) then
     {
// 2_2_2_1_1
ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Ask+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red);
      Exit;
     };
// 2_2_2_1_1
    }; // 2_2_2_1
   }; // 2_2_2
  }; // 2_2
  }; // 2
}; // forの終わり
// the end.

トラックバック(0)

http://kawarobo.com/mt/mt-tb.cgi/492

コメントを書く

PageTop

RSS

ヤフオク

おすすめFX口座

ひまわり証券【証券CFD取引】
FX 比較なら