void OnTick(){ examineLastTrade(); } void examineLastTrade(){ double offset = 50*_Point; if (!PositionSelect(Symbol())){ HistorySelect(TimeCurrent() - 3600, TimeCurrent()); for (int i = 0; i < HistoryDealsTotal(); i++){ ulong ticket = HistoryDealGetTicket(i); if (ticket > 0){ double dealProfit = HistoryDealGetDouble(ticket, DEAL_PROFIT); long dealTime = HistoryDealGetInteger(ticket, DEAL_TIME); int barIndex = iBarShift(_Symbol, _Period, dealTime); double pricePosition = iHigh(_Symbol, _Period, barIndex) + offset; datetime positionTime = iTime(_Symbol, _Period, barIndex); Profit_display(0, "deal_profit", "$" + FormatString(dealProfit), pricePosition, 8, clrSilver, positionTime); } else{ Print("Failed to get ticket for index ", i); } } } } void Profit_display(int id, string name, string text, double distance, int fontSize, color fontColor, datetime time){ if (ObjectFind(0, name) < 0){ ObjectCreate(id, name, OBJ_TEXT, 0, time, distance); } ObjectSetInteger(id, name, OBJPROP_CORNER, 0); ObjectSetInteger(id, name, OBJPROP_FONTSIZE, fontSize); ObjectSetInteger(id, name, OBJPROP_COLOR, fontColor); ObjectSetString(id, name, OBJPROP_TEXT, text); } string FormatString(double value) { string str = DoubleToString(value, 8); // Find the position of the decimal point int dotPosition = StringFind(str, "."); if (dotPosition != -1){ // Check the part after the decimal point string fractionalPart = StringSubstr(str, dotPosition + 1); // If the fractional part has only one zero, keep it if (StringLen(fractionalPart) == 2 && StringSubstr(fractionalPart, 1, 1) == "0"){ str = StringSubstr(str, 0, dotPosition + 3); // Keep two decimal places } else{ // Remove trailing zeros while (StringLen(str) > 0 && StringSubstr(str, StringLen(str) - 1, 1) == "0"){ str = StringSubstr(str, 0, StringLen(str) - 1); // Remove trailing zero } // Remove the trailing dot if any if (StringSubstr(str, StringLen(str) - 1, 1) == "."){ str = StringSubstr(str, 0, StringLen(str) - 1); } } } return str; }