gryps2/UI-code/T-044_TradeHistry-pips.txt
super.admin ae3f0ebf03 convert
2025-05-30 14:58:21 +02:00

380 lines
29 KiB
Text

// チャートにトレード履歴表示・データ表示用
double tes = 0.0; // 外付け手数料(PIPS換算)
int sf, tof;
datetime hf;
double totalpips = 0, ProfitFactor = 0;
double plus_profit = 0, minus_profit = 0;
double minus_count = 0, plus_count = 0;
double RRR, WinPer;
double TradeCounts;
int OnInit()
{
// トレード履歴をチャートに表示(ライン・pips)
history();
PosHis();
}
void OnTick()
{
// チャートにトレード線とpips表示
if (IsTesting() == false || IsVisualMode() == true)
{
if (sf != Seconds() && OrdersTotal() > 0)
{
PosHis();
sf = Seconds();
}
if ((hf != iTime((string)0, 60, 0) && Seconds() > 30) || tof != OrdersHistoryTotal())
{
history();
hf = iTime((string)0, 60, 0);
tof = OrdersHistoryTotal();
}
}
}
//+------------------------------------------------------------------+
//| チャートにトレード履歴表示(チャートコメントは別処理バージョン) |
//+------------------------------------------------------------------+
void PosHis()
{
int res;
double pips = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
res = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() != Symbol() || OrderType() > 1 || OrderMagicNumber() != MagicNumber)
continue;
pips += trend((string)OrderTicket(), OrderOpenTime(), OrderOpenPrice(), Time[0], OrderType() == 0 ? Bid : Ask, OrderType());
}
}
//+------------------------------------------------------------------+
void history()
{
int res;
totalpips = 0;
plus_profit = 0;
minus_profit = 0;//, ProfitFactor = 0;
minus_count = 0;
plus_count = 0;
TradeCounts = 0;
// トレード履歴を検索
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
{
res = OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if (OrderSymbol() != Symbol() || OrderType() > 1 || OrderMagicNumber() != MagicNumber)
continue;
// 合計pips計算
totalpips += trend((string)OrderTicket(), OrderOpenTime(), OrderOpenPrice(), OrderCloseTime(), OrderClosePrice(), OrderType());
// プロフィットファクター・RRR・勝率計算
if (OrderProfit() < 0)
{
minus_profit -= OrderProfit();
minus_count += 1;
}
else if (OrderProfit() >= 0)
{
plus_profit += OrderProfit();
plus_count += 1;
}
if (minus_profit != 0 && plus_count != 0 && minus_count != 0)
{
ProfitFactor = plus_profit / minus_profit;
RRR = (plus_profit / plus_count) / (minus_profit / minus_count);
WinPer = (plus_count * 100) / (plus_count + minus_count);
}
TradeCounts = minus_count + plus_count;
}
}
//+------------------------------------------------------------------+
double trend(string obj_name, datetime Time1, double Close1, datetime Time2, double Close2, int type)
{
double pips = (double)DoubleToStr((type == 0 ? Close2 - Close1 : Close1 - Close2) / Point() * 0.1 - tes, 1);
int Shift2 = iBarShift(NULL, 0, Time2);
datetime Timex = iTime(NULL, 0, Shift2 + 1);
// トレード線
ObjectDelete("hislt" + obj_name);
ObjectCreate(0, "hislt" + obj_name, OBJ_TREND, 0, Time1, Close1, Time2, Close2);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_COLOR, type == 0 ? clrDodgerBlue : clrOrangeRed);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_STYLE, 0);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_WIDTH, 2);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_SELECTABLE, false); // オブジェクトの選択可否設定
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_RAY_RIGHT, false); // 右に線を延長
// トレード線内のpips表示
// 文字本体
ObjectDelete("hislx" + obj_name);
ObjectCreate(0, "hislx" + obj_name, OBJ_TEXT, 0, Timex, Close2);
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_COLOR, pips < 0 ? clrOrangeRed : !IsTesting()? clrLime : clrYellow);//type == 0 ? BuyColor : SellColor);
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_SELECTABLE, false); // オブジェクトの選択可否設定
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_FONTSIZE, 12); // フォントサイズ
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_ANCHOR, ANCHOR_RIGHT); // 描画位置
ObjectSetString(0, "hislx" + obj_name, OBJPROP_TEXT, DoubleToStr(pips, 1)); // 表示するテキスト
ObjectSetString(0, "hislx" + obj_name, OBJPROP_FONT, "Segoe UI Semibold"); // フォント
return(pips);
}
//+------------------------------------------------------------------+
// バリエーション
//+------------------------------------------------------------------+
// チャートにトレード履歴表示用
double tes = 0.0; // 外付け手数料(PIPS換算)
color BuyColor = DodgerBlue;
color SellColor = OrangeRed;
color GainColor = Lime;
color LossColor = OrangeRed;
int sf, tof;
datetime hf;
double totalpips = 0, ProfitFactor = 0;
int OnInit()
{
// トレード履歴をチャートに表示(ライン・pips)
history();
PosHis();
}
void OnTick()
{
// チャートにトレード線とpips表示
if (IsTesting() == false || IsVisualMode() == true)
{
if (sf != Seconds() && OrdersTotal() > 0)
{
PosHis();
sf = Seconds();
}
if ((hf != iTime((string)0, 60, 0) && Seconds() > 30) || tof != OrdersHistoryTotal())
{
history();
hf = iTime((string)0, 60, 0);
tof = OrdersHistoryTotal();
}
}
}
//+------------------------------------------------------------------+
//| チャートにトレード履歴表示(チャートコメント表示処理も一緒) |
//+------------------------------------------------------------------+
void PosHis()
{
int res;
double pips = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
res = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() != Symbol() || OrderType() > 1 || OrderMagicNumber() != MagicNumber)
continue;
pips += trend((string)OrderTicket(), OrderOpenTime(), OrderOpenPrice(), Time[0], OrderType() == 0 ? Bid : Ask, OrderType());
}
}
//+------------------------------------------------------------------+
void history()
{
totalpips = 0;
int res;
double plus_profit = 0, minus_profit = 0;//, ProfitFactor = 0;
// トレード履歴を検索
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
{
res = OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if (OrderSymbol() != Symbol() || OrderType() > 1 || OrderMagicNumber() != MagicNumber)
continue;
// 合計pips計算
totalpips += trend((string)OrderTicket(), OrderOpenTime(), OrderOpenPrice(), OrderCloseTime(), OrderClosePrice(), OrderType());
// プロフィットファクター計算
if (OrderProfit() < 0) minus_profit -= OrderProfit();
else if (OrderProfit() >= 0) plus_profit += OrderProfit();
if (minus_profit != 0) ProfitFactor = plus_profit / minus_profit;
}
// 値表示
string Comment01 = "Profit (pips) : " + DoubleToStr(totalpips, 1);
string Comment02 = (plus_profit == 0 || minus_profit == 0? "Profit factor : ---" : "Profit factor : " + DoubleToStr(ProfitFactor, 2));
CommentLabel2("totalpips", Comment01, 6, 136, 8);
CommentLabel2("profitfactor", Comment02, 6, 154, 8);
}
//+------------------------------------------------------------------+
void CommentLabel2(string ComName2, string ComText2, int ComPos_x2, int ComPos_y2, int ComSize2)
{
// 値の仕様
ObjectCreate(ComName2, OBJ_LABEL, 0, 0, 0);
ObjectSetString (0, ComName2, OBJPROP_TEXT, ComText2);
ObjectSetInteger(0, ComName2, OBJPROP_XDISTANCE, ComPos_x2);
ObjectSetInteger(0, ComName2, OBJPROP_YDISTANCE, ComPos_y2);
ObjectSetInteger(0, ComName2, OBJPROP_FONTSIZE, ComSize2);
ObjectSetString (0, ComName2, OBJPROP_FONT, "Segoe UI");
ObjectSetInteger(0, ComName2, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, ComName2, OBJPROP_STATE, false);
ObjectSetInteger(0, ComName2, OBJPROP_BACK, true);
ObjectSetInteger(0, ComName2, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, ComName2, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
ObjectSetInteger(0, ComName2, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
ObjectSetInteger(0, "totalpips", OBJPROP_COLOR, totalpips < 0? clrOrangeRed : clrWhite);
ObjectSetInteger(0, "profitfactor", OBJPROP_COLOR, 0 < ProfitFactor && ProfitFactor < 1? clrOrangeRed : clrWhite);
}
//+------------------------------------------------------------------+
double trend(string obj_name, datetime Time1, double Close1, datetime Time2, double Close2, int type)
{
double pips = (double)DoubleToStr((type == 0 ? Close2 - Close1 : Close1 - Close2) / Point() * 0.1 - tes, 1);
int Shift2 = iBarShift(NULL, 0, Time2);
datetime Timex = iTime(NULL, 0, Shift2 + 1);
// トレード線
ObjectDelete("hislt" + obj_name);
ObjectCreate(0, "hislt" + obj_name, OBJ_TREND, 0, Time1, Close1, Time2, Close2);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_COLOR, type == 0 ? BuyColor : SellColor);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_STYLE, 0);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_WIDTH, 0);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_SELECTABLE, false); // オブジェクトの選択可否設定
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_RAY_RIGHT, false); // 右に線を延長
// トレード線内のpips表示
// 文字本体
ObjectDelete("hislx" + obj_name);
ObjectCreate(0, "hislx" + obj_name, OBJ_TEXT, 0, Timex, Close2);
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_COLOR, pips < 0 ? LossColor : GainColor);//type == 0 ? BuyColor : SellColor);
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_SELECTABLE, false); // オブジェクトの選択可否設定
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_FONTSIZE, 12); // フォントサイズ
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_ANCHOR, ANCHOR_RIGHT); // 描画位置
ObjectSetString(0, "hislx" + obj_name, OBJPROP_TEXT, DoubleToStr(pips, 1)); // 表示するテキスト
ObjectSetString(0, "hislx" + obj_name, OBJPROP_FONT, "Segoe UI Semibold"); // フォント
return(pips);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| チャートにトレード履歴表示(線の中央にpips表示) |
//+------------------------------------------------------------------+
void PosHis()
{
int res;
double pips = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
res = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() != Symbol() || OrderType() > 1 || OrderMagicNumber() != MagicNumber)
continue;
pips += trend((string)OrderTicket(), OrderOpenTime(), OrderOpenPrice(), Time[0], OrderType() == 0 ? Bid : Ask, OrderType());
}
}
//+------------------------------------------------------------------+
void history()
{
totalpips = 0;
int res;
double plus_profit = 0, minus_profit = 0;//, ProfitFactor = 0;
// トレード履歴を検索
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
{
res = OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if (OrderSymbol() != Symbol() || OrderType() > 1 || OrderMagicNumber() != MagicNumber)
continue;
// 合計pips計算
totalpips += trend((string)OrderTicket(), OrderOpenTime(), OrderOpenPrice(), OrderCloseTime(), OrderClosePrice(), OrderType());
// プロフィットファクター計算
if (OrderProfit() < 0) minus_profit -= OrderProfit();
else if (OrderProfit() >= 0) plus_profit += OrderProfit();
if (minus_profit != 0) ProfitFactor = plus_profit / minus_profit;
}
// 値表示
string Comment01 = "Profit (pips) : " + DoubleToStr(totalpips, 1);
string Comment02 = (plus_profit == 0 || minus_profit == 0? "Profit factor : ---" : "Profit factor : " + DoubleToStr(ProfitFactor, 2));
CommentLabel2("totalpips", Comment01, 6, 136, 8);
CommentLabel2("profitfactor", Comment02, 6, 154, 8);
}
//+------------------------------------------------------------------+
void CommentLabel2(string ComName2, string ComText2, int ComPos_x2, int ComPos_y2, int ComSize2)
{
// 値の仕様
ObjectCreate(ComName2, OBJ_LABEL, 0, 0, 0);
ObjectSetString (0, ComName2, OBJPROP_TEXT, ComText2);
ObjectSetInteger(0, ComName2, OBJPROP_XDISTANCE, ComPos_x2);
ObjectSetInteger(0, ComName2, OBJPROP_YDISTANCE, ComPos_y2);
ObjectSetInteger(0, ComName2, OBJPROP_FONTSIZE, ComSize2);
ObjectSetString (0, ComName2, OBJPROP_FONT, "Segoe UI");
ObjectSetInteger(0, ComName2, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, ComName2, OBJPROP_STATE, false);
ObjectSetInteger(0, ComName2, OBJPROP_BACK, true);
ObjectSetInteger(0, ComName2, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, ComName2, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
ObjectSetInteger(0, ComName2, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
ObjectSetInteger(0, "totalpips", OBJPROP_COLOR, totalpips < 0? clrOrangeRed : clrWhite);
ObjectSetInteger(0, "profitfactor", OBJPROP_COLOR, 0 < ProfitFactor && ProfitFactor < 1? clrOrangeRed : clrWhite);
}
//+------------------------------------------------------------------+
double trend(string obj_name, datetime Time1, double Close1, datetime Time2, double Close2, int type)
{
double pips = (double)DoubleToStr((type == 0 ? Close2 - Close1 : Close1 - Close2) / Point() * 0.1 - tes, 1);
int Shift1 = iBarShift(NULL, 0, Time1);
int Shift2 = iBarShift(NULL, 0, Time2);
datetime Timex = iTime(NULL, 0, (Shift1 + Shift2) /2);
// トレード線
ObjectDelete("hislt" + obj_name);
ObjectCreate(0, "hislt" + obj_name, OBJ_TREND, 0, Time1, Close1, Time2, Close2);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_COLOR, type == 0 ? BuyColor : SellColor);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_STYLE, 0);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_WIDTH, 0);
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_SELECTABLE, false); // オブジェクトの選択可否設定
ObjectSetInteger(0, "hislt" + obj_name, OBJPROP_RAY_RIGHT, false); // 右に線を延長
// トレード線内のpips表示
// 文字本体
ObjectDelete("hislx" + obj_name);
ObjectCreate(0, "hislx" + obj_name, OBJ_TEXT, 0, Timex, (Close1 + Close2)/2);
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_COLOR, pips < 0 ? LossColor : GainColor);//type == 0 ? BuyColor : SellColor);
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_SELECTABLE, false); // オブジェクトの選択可否設定
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_FONTSIZE, 12); // フォントサイズ
ObjectSetInteger(0, "hislx" + obj_name, OBJPROP_ANCHOR, ANCHOR_CENTER); // 描画位置
ObjectSetString(0, "hislx" + obj_name, OBJPROP_TEXT, DoubleToStr(pips, 1)); // 表示するテキスト
ObjectSetString(0, "hislx" + obj_name, OBJPROP_FONT, "Segoe UI Semibold"); // フォント
return(pips);
}
//+------------------------------------------------------------------+