//+------------------------------------------------------------------+ //| Sample Breakout.mq4 | //| DC | //| http://jidoubaibai.com | //+------------------------------------------------------------------+ #property copyright "DC" #property link "http://jidoubaibai.com" //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //変数の宣言 int cnt; int odBreak; int Ticket; double alots,blots; int clots; // オーダーチェック(ポジションなどのデータ) odBreak= - 1; for(cnt=0;cnt < OrdersTotal();cnt++){ OrderSelect(cnt,SELECT_BY_POS); if(OrderMagicNumber() == 10) odBreak = cnt; } //ロット数を、大体レバレッジ10倍にする //AccountBalance() は、現在の口座に入っている金額を出す //1万ドルが口座にある場合、1ロットが十万通貨なので、1万で割る blots = AccountBalance() / 10000; //小数点第一位までで四捨五入するために、一度10倍にして、0.5を足して、int型に入れる clots = blots * 10 + 0.5; //最後に、double型に0.1をかける。 //これにより、口座に入っているのが1万2千ドルの場合は、1.2ロットになる。 alots = clots * 0.1 ; // ポジションチェック ポジション無し if(odBreak == -1) { //もし過去40本文の時間足の高値を更新したら if(TBreak(40) == 1 ) { //買いポジションを取る Ticket = OrderSend(Symbol(), OP_BUY, alots, Ask, 3, 0, 0, "Buy", 10, 0, Red); } //もし過去40本文の時間足の安値を更新したら if( TBreak(40) == 2) { //売りポジションを取る Ticket = OrderSend(Symbol(), OP_SELL, alots, Bid, 3, 0, 0, "Sell", 10, 0, Blue); } } // ポジション有り else { //ポジションの選択 OrderSelect(odBreak,SELECT_BY_POS); //通貨ペアの確認 if(Symbol() == OrderSymbol()) { //もし買いポジションだったら if(OrderType()==OP_BUY) { //もし過去20本文の時間足の安値を更新したら if( TBreak(20) == 2) { //手仕舞い OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); } } //もし売りポジションだったら else if(OrderType()==OP_SELL) { //もし過去20本文の時間足の高値を更新したら if( TBreak(20) == 1 ) { //手仕舞い OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); } } } } return(0); } /*---------------------------------------------------------------------------------------------------- 変数名  TBreak 引数  count 何本文の時間足を調べるか? 概要 過去n本文の時間足の最高値、もしくは最安値が更新したら条件成立。 戻り値 1なら買いの条件 2なら売りの条件 0は条件不成立 -----------------------------------------------------------------------------------------------------*/ int TBreak(int count) { int i; double max,min; //変数maxに一つ前の時間足の高値のデータ入れる max = High[1]; //変数minに一つ前の時間足の底値のデータ入れる min = Low[1]; //引数に入れた数だけループする for(i=1;i Low[i] ) { //変数minにi本文前の時間足の底値のレートを入れる min = Low[i]; } } //もし過去n本文の時間足の高値より、現在の終値の方が高かったら if(max < Close[0]) return( 1 ); //もし過去n本文の時間足の底値より、現在の終値の方が低かったら if(min > Close[0]) return( 2 ); return( 0 ); } // the end. //+------------------------------------------------------------------+