|
标记周线实体区块H4版:
使用:
1.切换到H4图
2.按ctrl+y显示区间
3.加载指标
----------------------
标记日线实体区块M30版:
使用:
1.切换到M30图
2.按ctrl+y显示区间
3.加载指标
PS:只适合服务器每周5天的平台
颜色可修改
标记日k实体区域30分钟代码:
- #property indicator_chart_window
- extern color 阳线颜色=C'75,0,0';
- extern color 阴线颜色=C'0,0,75';
- double DaysOpen,DaysClose;//DaysHigh,DaysLow;
- extern int 数量=1000;
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- for(int i=ObjectsTotal();i>=0;i--)
- {
- if(StringFind(ObjectName(i),"标记实体区块M30",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),"标记实体区块M30",0)==0)
- {
- ObjectDelete(ObjectName(i));
- i=ObjectsTotal();
- }
- }
-
- return(0);
- }
- //+------------------------------------------------------------------+
- //| Custom indicator iteration function |
- //+------------------------------------------------------------------+
- int start()
- {
- if(Period()!=PERIOD_M30){
- for(int i=ObjectsTotal();i>=0;i--)
- {
- if(StringFind(ObjectName(i),"标记实体区块M30",0)==0)
- {
- ObjectDelete(ObjectName(i));
- i=ObjectsTotal();
- }
- }
- return(0);
- }
- for(int j=1;j<=数量;j++){
- string 当天年月日="";
- 当天年月日=TimeYear(iTime(Symbol(),PERIOD_D1,j))+"."+TimeMonth(iTime(Symbol(),PERIOD_D1,j))+"."+TimeDay(iTime(Symbol(),PERIOD_D1,j));
- DaysOpen=iOpen(NULL,PERIOD_D1,j);
- DaysClose=iClose(NULL,PERIOD_D1,j);
- ObjectCreate("标记实体区块M30"+当天年月日,OBJ_RECTANGLE,0,M30中当日首K时间(j),DaysOpen,M30中当日首K时间(j-1),DaysClose);
- ObjectSet("标记实体区块M30"+当天年月日, OBJPROP_BACK, true );
- ObjectSet("标记实体区块M30"+当天年月日, OBJPROP_COLOR, Yellow );
- if(DaysOpen>DaysClose){
- ObjectSet("标记实体区块M30"+当天年月日, OBJPROP_COLOR, 阴线颜色 );
- }
- else if(DaysOpen<DaysClose){
- ObjectSet("标记实体区块M30"+当天年月日, OBJPROP_COLOR, 阳线颜色 );
- }
- }
- //END
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- datetime M30中当日首K时间(int 日K索引){
- datetime 首K时间=0;
- int 首K索引=0;
- for(int j=0;j<48;j++){
- 首K索引=iBarShift(Symbol(),PERIOD_M30,iTime(Symbol(),PERIOD_D1,日K索引)+j*30*60,true); //30*60=一个30分钟K的秒数
- if(首K索引!=-1){
- return(iTime(Symbol(),PERIOD_M30,首K索引));
- }
- else if(首K索引==-1){
- //啥也不做,继续下一个循环
- }
- }
- }
- //无用函数
- int M30中当日首K索引(int 日K索引){
- datetime 首K时间=0;
- int 首K索引=0;
- for(int j=0;j<48;j++){
- 首K索引=iBarShift(Symbol(),PERIOD_M30,iTime(Symbol(),PERIOD_D1,日K索引)+j*30*60,true);
- if(首K索引!=-1){
- return(首K索引);
- }
- else if(首K索引==-1){
- //啥也不做,继续下一个循环
- }
- }
- }
复制代码
标记日k实体区域4h代码:
- #property indicator_chart_window
- extern color 阳线颜色=C'75,0,0';
- extern color 阴线颜色=C'0,0,75';
- double WeeksOpen,WeeksClose;
- extern int 数量=200;
- //+------------------------------------------------------------------+
- //| 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){
- for(int i=ObjectsTotal();i>=0;i--)
- {
- if(StringFind(ObjectName(i),"标记实体区块H4",0)==0)
- {
- ObjectDelete(ObjectName(i));
- i=ObjectsTotal();
- }
- }
- return(0);
- }
- for(int j=1;j<=数量;j++){
- string 当天年月日="";
- 当天年月日=TimeYear(iTime(Symbol(),PERIOD_W1,j))+"."+TimeMonth(iTime(Symbol(),PERIOD_W1,j))+"."+TimeDay(iTime(Symbol(),PERIOD_W1,j));
- WeeksOpen=iOpen(NULL,PERIOD_W1,j);
- WeeksClose=iClose(NULL,PERIOD_W1,j);
- ObjectCreate("标记实体区块H4"+当天年月日,OBJ_RECTANGLE,0,H4中当周首K时间(j),WeeksOpen,H4中当周首K时间(j-1),WeeksClose);
- ObjectSet("标记实体区块H4"+当天年月日, OBJPROP_BACK, true );
- ObjectSet("标记实体区块H4"+当天年月日, OBJPROP_COLOR, Yellow );
- if(WeeksOpen>WeeksClose){
- ObjectSet("标记实体区块H4"+当天年月日, OBJPROP_COLOR, 阴线颜色 );
- }
- else if(WeeksOpen<WeeksClose){
- ObjectSet("标记实体区块H4"+当天年月日, OBJPROP_COLOR, 阳线颜色 );
- }
- }
- //END
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- datetime H4中当周首K时间(int 周K索引){
- datetime 首K时间=0;
- int 首K索引=0;
- for(int j=0;j<30;j++){
- 首K索引=iBarShift(Symbol(),PERIOD_H4,iTime(Symbol(),PERIOD_W1,周K索引)+j*60*60*4,true); //60*60*4=一个H4-K的秒数
- if(首K索引!=-1){
- return(iTime(Symbol(),PERIOD_H4,首K索引));
- }
- else if(首K索引==-1){
- //啥也不做,继续下一个循环
- }
- }
- }
复制代码
|
|