I'm trying to code an indicator that can show a vline at the first trading day of the month (in some month the first tradingday is the 1. other month the first trading day is the 2. or 3.)
Here is what i have tried
Problem: It does not draw a line on days where the day is the second or third
I have tried a few other indies, but they draw the vline on the last day of the month and i want it on the first day of the month.
Here is what i have tried
Inserted Code
#property copyright "" #property link "" #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { ObjectsDeleteAll(); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int Day1Exist, Day2Exist, Day3Exist = 0; int LookBack = 1000; // no of days you wanna look back for(int i=0;i<=LookBack;i++) { datetime dailyTime=iTime(Symbol(),1440,i); string name="Time_Vertical_Line"+i; if(TimeDay(dailyTime)==1) { if(!ObjectCreate(0,name,OBJ_VLINE,0,dailyTime,0)) Print("Fail to draw the line ERROR CODE : ",GetLastError()); ObjectSet(name,OBJPROP_WIDTH,3); ObjectSet(name,OBJPROP_COLOR,Red); ObjectSet(name,OBJPROP_BACK,true); Day1Exist = Day1Exist + 1; } else if(TimeDay(dailyTime)==2 && Day1Exist < 1) { if(!ObjectCreate(0,name,OBJ_VLINE,0,dailyTime,0)) Print("Fail to draw the line ERROR CODE : ",GetLastError()); ObjectSet(name,OBJPROP_WIDTH,3); ObjectSet(name,OBJPROP_COLOR,Green); ObjectSet(name,OBJPROP_BACK,true); Day2Exist = Day2Exist + 1; } else if(TimeDay(dailyTime)==3 && (Day1Exist < 1) || (Day2Exist < 1)) { if(!ObjectCreate(0,name,OBJ_VLINE,0,dailyTime,0)) Print("Fail to draw the line ERROR CODE : ",GetLastError()); ObjectSet(name,OBJPROP_WIDTH,3); ObjectSet(name,OBJPROP_COLOR,Blue); ObjectSet(name,OBJPROP_BACK,true); Day1Exist = 0; Day2Exist = 0; } } // For } // Start
Problem: It does not draw a line on days where the day is the second or third
I have tried a few other indies, but they draw the vline on the last day of the month and i want it on the first day of the month.
Blindly following others will make you blind!