■超簡単な売買プログラム(トラリピ編)を作ってみました。


// 外部パラメータ
extern double Lots = 0.1; // ロット数
extern int MaxLots = 5;  // 最大ポジション数
extern int StopLoss = 50; // 損切り値(Stop)
extern int TakeProfit = 80; // 利食い値(Limit)
extern int Slippage = 3; // スリッページ
extern int TradeMode = 2; // 0=買:1=売:2=買&売
extern double OpenPrice = 90.00; // 新規指値
extern double PriceRange = 0.20; // 指値の値幅
extern int Magic = 10001; // マジックナンバー


//////////////// スタート関数 /////////////////
int start() {
 double price;


 for(int i=0; i<MaxLots; i++) {
  // 現在のポジションのチェック
  if(CheckPosition(Magic+i) == 1) { continue; }


  // 買い注文
  if(TradeMode == 0 || TradeMode == 2) {
   if(OpenPrice-PriceRange*i >= Ask) { return(0); }
   price = OpenPrice-PriceRange*i;
   OrderSend(Symbol(), OP_BUYLIMIT, Lots, price, Slippage,
        price-Point*StopLoss, price+Point*TakeProfit, "Buy", Magic+i, 0, Red);
   }
   // 売り注文
   if(TradeMode == 1 || TradeMode == 2) {
    if(OpenPrice+PriceRange*i <= Bid) { return(0); }
    price = OpenPrice+PriceRange*i;
    OrderSend(Symbol(), OP_SELLLIMIT, Lots, price, Slippage,
         price+Point*StopLoss, price-Point*TakeProfit, "Sell", Magic+i, 0, Blue);
   }
  }
  return(0);
}


//////////////// ポジションのチェック /////////////////
int CheckPosition(int magic) {
 double OpenPosition = 0;
 for (int i = OrdersTotal() - 1; i >= 0; i--){
  if(OrderSelect(i, SELECT_BY_POS) == false) { break; }
  if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic) { continue; }
   OpenPosition++;
  }
  if(OpenPosition != 0) { return(1); }
  return(0);
}