거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
Experts

Check Last Closed Trade (Profit / Type / Symbol etc.) - MetaTrader 5용 expert

조회수:
1363
평가:
(3)
게시됨:
2024.04.21 18:51
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

With this code block, you can get the last closed trade data without using loops. 

  • Create a variable to set the current day start time. (This is not necessary to do.)
  • Create some other variables to print a chart output and use if in other code blocks as well. (This is not necessary to do.)
  • Using this code inside of the OnTick(); function leads to show result for every tick. You can set it also for once a bar

// variables
string DayStart = "00:00"; // Day Start Time
double LastClosed_Profit; // Last Closed trade profit
string TradeSymbol, TradeType;



// Expert Initializing --------------------
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

// Expert DeInitializing -------------------
void OnDeinit(const int reason)
  {

  }

// Expert OnTick --------------------------
void OnTick()
  {
// check for last closed trade.
   CheckLastClosed();

  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CheckLastClosed()
  {
   datetime HistoryTime = StringToTime(DayStart);

// history from "Day begining to current time
   if(HistorySelect(HistoryTime,TimeCurrent()))
     {
      int Total = HistoryDealsTotal();

      // Get the last deal ticket number and select it to furthur work.
      ulong Ticket = HistoryDealGetTicket(Total -1);

      // Get what you need to get.
      LastClosed_Profit = NormalizeDouble(HistoryDealGetDouble(Ticket,DEAL_PROFIT),2);
      TradeSymbol      = HistoryOrderGetString(Ticket,ORDER_SYMBOL);

      // Identify a sell trade.
      if(HistoryDealGetInteger(Ticket,DEAL_TYPE) == DEAL_TYPE_BUY)
        {
         TradeType = "Sell Trade";
        }

      // Identify a buy trade
      if(HistoryDealGetInteger(Ticket,DEAL_TYPE) == DEAL_TYPE_SELL)
        {
         TradeType = "Buy Trade";
        }

      // chart out put.
      Comment("\n","Deals Total - :  ", Total,
              "\n","Last Deal Ticket - :  ", Ticket,
              "\n", "Last Closed Profit -:  ", LastClosed_Profit,
              "\n", "Last Trade was -:  ", TradeType);

     }
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

you can get the whole trading history (from the very beginning of the account) by using the  HistorySelect(); function this way.

// Get entire history
HistorySelect(0,TimeCurrent());


    Trailing with Close by Button and Profit Trailing with Close by Button and Profit

    This EA help you for Auto set the TP & SL by default parameter, Auto trailing stop & step for any order that you place from any device, Easy way to close all orders with 3 Button "Close All" "Close Profit" "Close Lose", Auto close all orders by profit or lose treshold value

    Confluence Detector Confluence Detector

    It will detect whether there's confluence between the current chart timeframe and two other timeframes.

    A BETTER RSI A BETTER RSI

    Relative Strength Index that completely removes noise, works on all markets!

    Manual Backtest Bar Replay Simulator Manual Backtest Bar Replay Simulator

    A simple indicator which may help you in manual backtest by just moving a vertical line to show hide bars.