论坛搜了一个盈亏统计的小指标,和自己预期的有点差别,无奈没编程的技术功底,只能发出江湖求助令了。
只统计当前窗口的货币,需要的功能很简单:
多单手数,,多单盈利,,
空单手数,,空单盈利,,
净持仓量,,浮动盈亏,,
[C++] 纯文本查看 复制代码#property copyright " "
#property link " "
#property indicator_chart_window
extern color 颜色=Yellow;
extern int 字号=12;
////////////////////////////////////////////
int init() { return(0); }
///////////////////////////////////////////
int deinit() { return(0); }
//////////////////////////////////////////
int start()
{
ObjectSet("text", OBJPROP_CORNER, 50);
ObjectSet("text", OBJPROP_XDISTANCE, 450);
ObjectSet("text", OBJPROP_YDISTANCE, 1);
string name_0 = "yl";
string name_16 = "yl0";
string name_24 = "yl1";
string name_32 = "yl2";
string name_40 = "yl3";
string name_48 = "yl4";
string name_56 = "yl5";
string name_64 = "yl6";
string name_72 = "yl7";
double ld_56 = 0;
double ld_64 = 0;
double ld_87 = 0; //多单盈利
double ld_88 = 0; //空单盈利
double ld_89 = 0; //总盈利
double ld_96 = 0;
double ld_97 = 0;
double ld_104 = 0;
double ld_105 = 0;
double ld_116 = 0;
double ld_117 = 0;
double ld_118 = 0;
//当前统计
int li_53 = OrdersTotal();
for (int pos_48 = li_53 - 1; pos_48 >= 0; pos_48--) {
OrderSelect(pos_48, SELECT_BY_POS, MODE_TRADES);
ld_89 += OrderProfit(); //+OrderCommission()+OrderSwap()
if(OrderSymbol() == Symbol()){
ld_88 += OrderProfit();
double buy,sell;
if (OrderType() == OP_BUY) { buy += OrderLots(); ld_87 += OrderProfit(); }
if (OrderType() == OP_SELL){ sell += OrderLots(); ld_88 += OrderProfit();}
double cha = buy - sell;
}
}
//统计当前持有单的盈亏状况
string text_8 ="多单手数:" + DoubleToStr(buy, 2)+" , "+"多单盈利:" + DoubleToStr(ld_87, 2)+";";
ObjectCreate(name_32, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_32, text_8, 字号, "Times New Roman", 颜色);
ObjectSet(name_32, OBJPROP_CORNER, 0);
ObjectSet(name_32, OBJPROP_XDISTANCE, 10);
ObjectSet(name_32, OBJPROP_YDISTANCE, 30);
text_8 ="空单手数:" + DoubleToStr(sell, 2)+" , "+ "空单盈利:" + DoubleToStr(ld_88, 2)+";";
ObjectCreate(name_56, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_56, text_8, 字号, "Times New Roman", 颜色);
ObjectSet(name_56, OBJPROP_CORNER, 0);
ObjectSet(name_56, OBJPROP_XDISTANCE, 10);
ObjectSet(name_56, OBJPROP_YDISTANCE, 50);
text_8 ="净持仓量:" + DoubleToStr(cha, 2)+" , "+ "浮动盈亏:" + DoubleToStr(ld_89, 2)+";";
ObjectCreate(name_64, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_64, text_8, 字号, "Times New Roman", 颜色);
ObjectSet(name_64, OBJPROP_CORNER, 0);
ObjectSet(name_64, OBJPROP_XDISTANCE, 10);
ObjectSet(name_64, OBJPROP_YDISTANCE, 70);
return (0);
}
//+------------------------------------------------------------------+
望各路编程达人,高手,大师,天尊拔刀相助
有合适指标的江湖人士分享也是可以的
|