|
只显示持仓线指标,橙色为多单,蓝色为空单。
- #property indicator_chart_window
- int init()
- {
- return(0);
- }
- int deinit()
- {
- ObjectDelete(TimeToStr(OrderOpenTime()));
- return(0);
- }
- int start()
- {
- iMain();
- return(0);
- }
- void iMain()
- {
- color myLineColor;
- for (int cnt=0;cnt<OrdersTotal();cnt++)
- {
- if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
- {
- //画持仓单线段,动态
- if (OrderType()==OP_SELL) myLineColor=DeepSkyBlue;
- if (OrderType()==OP_BUY) myLineColor=OrangeRed;
- if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
- {
- ObjectDelete(TimeToStr(OrderOpenTime()));
- iTwoPointsLine(TimeToStr(OrderOpenTime()),OrderOpenTime(),OrderOpenPrice(),Time[0],Bid,2,1,myLineColor);
- }
- if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
- {
- ObjectDelete(TimeToStr(OrderOpenTime()));
- iTwoPointsLine(TimeToStr(OrderOpenTime()),OrderOpenTime(),OrderOpenPrice(),Time[0],Ask,2,1,myLineColor);
- }
- }
- }
- return(0);
- }
- /*
- 函 数:两点间连线(主图)
- 输入参数:string myLineName 线段名称
- int myFirstTime 起点时间
- int myFirstPrice 起点价格
- int mySecondTime 终点时间
- int mySecondPrice 终点价格
- int myLineStyle 线型 0-实线 1-断线 2-点线 3-点划线 4-双点划线
- int myLineKuan 线宽
- color myLineColor 线色
- 输出参数:在指定的两点间连线
- 算法说明:
- */
- void iTwoPointsLine(string myLineName,int myFirstTime,double myFirstPrice,int mySecondTime,double mySecondPrice,int myLineStyle,int myLineKuan,color myLineColor)
- {
- ObjectCreate(myLineName,OBJ_TREND,0,myFirstTime,myFirstPrice,mySecondTime,mySecondPrice);//确定两点坐标
- ObjectSet(myLineName,OBJPROP_STYLE,myLineStyle); //线型
- ObjectSet(myLineName,OBJPROP_COLOR,myLineColor); //线色
- ObjectSet(myLineName,OBJPROP_WIDTH, myLineKuan); //线宽
- ObjectSet(myLineName,OBJPROP_BACK,false);
- ObjectSet(myLineName,OBJPROP_RAY,false);
- }
复制代码 |
|