Advertisement
hombretao

AlertOnTakeProfit

Aug 1st, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. void OnTick() {
  2.    RefreshRates();
  3.    Print("--- tick ---");
  4.    int ord = OrdersTotal();
  5.    int err = 0;
  6.    for(int i = (ord - 1); i >= 0; i--) {
  7.       if ( !OrderSelect( i, SELECT_BY_POS ) ) {
  8.          err = GetLastError();
  9.          Alert( "OrderSelect( ", i, ", SELECT_BY_POS ) - Error #", err );
  10.          continue;
  11.       } else {
  12.          string type = ((OrderType()) ? "Sell" : "Buy");
  13.          Print(i,". ",type,"#",OrderTicket(),": TP = ",OrderTakeProfit());
  14.      // if order type is buy and bid is below take profit
  15.          if((OrderType() == 1) && (Bid <= OrderTakeProfit())) {
  16.             //PlaySound("profit.wav");
  17.             Alert("TP!");
  18.          }  
  19.      // if order type is sell and bid is above take profit
  20.          if((OrderType() == 0) && (Bid >= OrderTakeProfit())) {
  21.             //PlaySound("profit.wav");
  22.             Alert("TP!");
  23.          }
  24.       }
  25.    }
  26.    Print("Bid: ",Bid);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement