//+------------------------------------------------------------------+ //| PosCnt.mq4 | //| Copyright ゥ 2010, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright ゥ 2010, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- // 現在保有中のポジションのロット数、平均建値をアラート表示します。 // 修正履歴 20110127 平均建値の表示処理を追加 int total = OrdersTotal(); // 全ポジション数 string PosSymbol[10]; // シンボル退避 double CntBuy[10]; // 買いロット数 double CntSell[10]; // 売りロット数 double PriceBuy[10]; // 買い総額 double PriceSell[10]; // 売り総額 double PriceBuyHeikin = 0; // 平均買い建値 double PriceSellHeikin = 0; // 平均売り建値 int kk,ii,jj; int cmd; Alert(""); Alert(WindowExpertName()," START"); // 配列の初期化 for ( kk =0; kk < 10 ; kk++) { PosSymbol[kk] = ""; // シンボル退避 CntBuy[kk] = 0; // 買いロット数 CntSell[kk] = 0; // 売りロット数 PriceBuy[kk] = 0; // 買い総額 PriceSell[kk] = 0; // 売り総額 } // ポジションを保有している場合、 if(total > 0) { // 全ポジション分、繰り返し処理を行う。 for(ii = 0; ii < total ; ii++ ) { // 0番目からポジションを選択する if(OrderSelect(ii,SELECT_BY_POS,MODE_TRADES)>0) { // シンボルの把握 for ( jj= 0; jj < 10 ;jj++) { // 初めてのシンボルが出現した場合、 if (PosSymbol[jj] == "") { PosSymbol[jj] = OrderSymbol(); } // 既存のシンボルにヒットした場合 if (OrderSymbol() == PosSymbol[jj]) { // 売り、買いの判断 cmd=OrderType(); // 買いだったら if(cmd==OP_BUY) { CntBuy[jj] = CntBuy[jj] + OrderLots(); PriceBuy[jj] = PriceBuy[jj] + ( OrderLots() * OrderOpenPrice() ); } // 売りだったら、 else if(cmd==OP_SELL) { CntSell[jj] = CntSell[jj] + OrderLots(); PriceSell[jj] = PriceSell[jj] + ( OrderLots() * OrderOpenPrice() ); } break; } } } else { // ポジション検索失敗 Alert( "Error when order select ", GetLastError()); } } } // 配列を0から検索する for ( kk = 0 ; kk < 10 ; kk++) { // 最終シンボルに達したら終了 if (PosSymbol[kk] == "" ) { break; } // 買値の平均の取得 PriceBuyHeikin=0; if ( CntBuy[kk] > 0) { PriceBuyHeikin = PriceBuy[kk] / CntBuy[kk] ; } // 売値の平均の取得 PriceSellHeikin = 0; if ( CntSell[kk] > 0) { PriceSellHeikin = PriceSell[kk] / CntSell[kk]; } // シンボル別のロット数をアラート表示する。 Alert(PosSymbol[kk]," Buy:",CntBuy[kk] ," @", PriceBuyHeikin," Sell:",CntSell[kk] , " @",PriceSellHeikin ); } // 終了メッセージ Alert(WindowExpertName()," END"); Alert("Please Stop EA"); //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- //---- return(0); } //+------------------------------------------------------------------+