|
标记周线实体区块H4版本,复盘可用
代码:
- #property indicator_chart_window
- extern color 阳线颜色=C'75,0,0';
- extern color 阴线颜色=C'0,0,75';
- double WeeksOpenPrice,WeeksClosePrice;
- double LastWeeksOpenPrice,LastWeeksClosePrice; //上周
- datetime WeeksOpenTime,WeeksCloseTime;
- datetime LastWeeksOpenTime,LastWeeksCloseTime; //上周
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- for(int i=ObjectsTotal();i>=0;i--)
- {
- if(StringFind(ObjectName(i),"标记实体区块H4",0)==0)
- {
- ObjectDelete(ObjectName(i));
- i=ObjectsTotal();
- }
- }
- return(0);
- }
- //+------------------------------------------------------------------+
- //| Custom indicator deinitialization function |
- //+------------------------------------------------------------------+
- int deinit()
- {
- for(int i=ObjectsTotal();i>=0;i--)
- {
- if(StringFind(ObjectName(i),"标记实体区块H4",0)==0)
- {
- ObjectDelete(ObjectName(i));
- i=ObjectsTotal();
- }
- }
-
- return(0);
- }
- //+------------------------------------------------------------------+
- //| Custom indicator iteration function |
- //+------------------------------------------------------------------+
- int start()
- {
- if(Period()!=PERIOD_H4){ //只在H4中使用
- for(int i=ObjectsTotal();i>=0;i--)
- {
- if(StringFind(ObjectName(i),"标记实体区块H4",0)==0)
- {
- ObjectDelete(ObjectName(i));
- i=ObjectsTotal();
- }
- }
- return(0);
- }
- int YesterdayTimeDayOfWeek=-1;
- int TodayTimeDayOfWeek=-1;
- string 方块日期标识字符="";
- YesterdayTimeDayOfWeek=TimeDayOfWeek(Time[1]);
- TodayTimeDayOfWeek=TimeDayOfWeek(Time[0]);
-
- if(TodayTimeDayOfWeek<YesterdayTimeDayOfWeek){
- Comment("X"); //进入到一周的第一个K
- LastWeeksOpenPrice=WeeksOpenPrice;//原来本周的开盘价变为上周的开盘价
- LastWeeksClosePrice=Close[1];
- WeeksOpenPrice=Open[0];
- Print("开"+LastWeeksOpenPrice,"收"+LastWeeksClosePrice);
- //---
- LastWeeksOpenTime=WeeksOpenTime; 方块日期标识字符=TimeToStr(WeeksOpenTime);
- LastWeeksCloseTime=Time[1]; //没用,因为方块右侧使用的是本周开盘时间
- WeeksOpenTime=Time[0];
- //Print("开"+TimeToStr(LastWeeksOpenTime),"收"+TimeToStr(LastWeeksCloseTime));//实际画画时在开盘时间画
- //画画
- if(LastWeeksOpenPrice>0.0001 && TimeYear(LastWeeksOpenTime)>1970){//代表均获得了正确数据
- ObjectCreate("标记实体区块H4"+方块日期标识字符,OBJ_RECTANGLE,0,LastWeeksOpenTime,LastWeeksOpenPrice,WeeksOpenTime,LastWeeksClosePrice);
- ObjectSet("标记实体区块H4"+方块日期标识字符, OBJPROP_BACK, true );
- ObjectSet("标记实体区块H4"+方块日期标识字符, OBJPROP_COLOR, Yellow );
-
- if(LastWeeksOpenPrice>LastWeeksClosePrice){
- ObjectSet("标记实体区块H4"+方块日期标识字符, OBJPROP_COLOR, 阴线颜色 );
- }
- else if(LastWeeksOpenPrice<LastWeeksClosePrice){
- ObjectSet("标记实体区块H4"+方块日期标识字符, OBJPROP_COLOR, 阳线颜色 );
- }
- }
- else{
- }
- }
- else{
- }
-
- return(0);
- }
复制代码
|
|