shabz Posted February 19, 2013 Report Share Posted February 19, 2013 I have an open levels indicator probably from this site, that needs code adjusting so that the lines refresh at the open of each hour. I use it as a basic trend indicator. Anyone can help please, indicator attached ? Thanks in advance. //+------------------------------------------------------------------+ //| open levels hourly.mq4 | //| Copyright © 2011, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "By cja - cjatradingtools.com " #property link "" #property indicator_chart_window extern int OPEN_PERIOD_1 = 60; extern int OPEN_PERIOD_2 = 240; extern int OPEN_PERIOD_3 = 1440; extern bool Show_LABELS = TRUE; extern bool Show_OPEN1_LINE = TRUE; extern int OPEN1_LABEL_Color = Black; extern color OPEN1_LINE_Color = Green; extern int OPEN1_LINE_Style = 2; extern int OPEN1_LINE_Width = 5; extern bool Show_OPEN2_LINE = TRUE; extern int OPEN2_LABEL_Color = Black; extern color OPEN2_LINE_Color = Aqua; extern int OPEN2_LINE_Style = 2; extern int OPEN2_LINE_Width = 5; extern bool Show_OPEN3_LINE = TRUE; extern int OPEN3_LABEL_Color = Black; extern color OPEN3_LINE_Color = Orange; extern int OPEN3_LINE_Style = 2; extern int OPEN3_LINE_Width = 5; string gs_152; string gs_160; string gs_168; int init() { IndicatorShortName("OPEN Levels"); switch (OPEN_PERIOD_1) { case 1: gs_152 = "M1"; break; case 5: gs_152 = "M5"; break; case 15: gs_152 = "M15"; break; case 30: gs_152 = "M30"; break; case 60: gs_152 = "Hourly"; break; case 240: gs_152 = "4 Hourly"; break; case 1440: gs_152 = "Daily"; break; case 10080: gs_152 = "Weekly"; break; case 43200: gs_152 = "Monthly"; } switch (OPEN_PERIOD_2) { case 1: gs_160 = "M1"; break; case 5: gs_160 = "M5"; break; case 15: gs_160 = "M15"; break; case 30: gs_160 = "M30"; break; case 60: gs_160 = "Hourly"; break; case 240: gs_160 = "4 Hourly"; break; case 1440: gs_160 = "Daily"; break; case 10080: gs_160 = "Weekly"; break; case 43200: gs_160 = "Monthly"; } switch (OPEN_PERIOD_3) { case 1: gs_168 = "M1"; break; case 5: gs_168 = "M5"; break; case 15: gs_168 = "M15"; break; case 30: gs_168 = "M30"; break; case 60: gs_168 = "Hourly"; break; case 240: gs_168 = "4 Hourly"; break; case 1440: gs_168 = "Daily"; break; case 10080: gs_168 = "Weekly"; break; case 43200: gs_168 = "Monthly"; } return (0); } int deinit() { ObjectDelete("OP1"); ObjectDelete("OP2"); ObjectDelete("OP3"); ObjectDelete("OP_1"); ObjectDelete("OP_2"); ObjectDelete("OP_3"); return (0); } int start() { CreateOP1(); return (0); } void CreateOpen1(string a_name_0, double a_price_8, double a_price_16, double a_width_24, double a_style_32, color a_color_40) { ObjectCreate(a_name_0, OBJ_TREND, 0, iTime(NULL, OPEN_PERIOD_1, 1), a_price_8, Time[0], a_price_16); ObjectSet(a_name_0, OBJPROP_COLOR, a_color_40); ObjectSet(a_name_0, OBJPROP_RAY, FALSE); ObjectSet(a_name_0, OBJPROP_WIDTH, a_width_24); ObjectSet(a_name_0, OBJPROP_STYLE, a_style_32); } void DeleteOpen1() { ObjectDelete("OP1"); } void CreateOP1() { DeleteOpen1(); CreateOP2(); } void CreateOpen2(string a_name_0, double a_price_8, double a_price_16, double a_width_24, double a_style_32, color a_color_40) { ObjectCreate(a_name_0, OBJ_TREND, 0, iTime(NULL, OPEN_PERIOD_2, 1), a_price_8, Time[0], a_price_16); ObjectSet(a_name_0, OBJPROP_COLOR, a_color_40); ObjectSet(a_name_0, OBJPROP_RAY, FALSE); ObjectSet(a_name_0, OBJPROP_WIDTH, a_width_24); ObjectSet(a_name_0, OBJPROP_STYLE, a_style_32); } void DeleteOpen2() { ObjectDelete("OP2"); } void CreateOP2() { DeleteOpen2(); CreateOP3(); } void CreateOpen3(string a_name_0, double a_price_8, double a_price_16, double a_width_24, double a_style_32, color a_color_40) { ObjectCreate(a_name_0, OBJ_TREND, 0, iTime(NULL, OPEN_PERIOD_3, 1), a_price_8, Time[0], a_price_16); ObjectSet(a_name_0, OBJPROP_COLOR, a_color_40); ObjectSet(a_name_0, OBJPROP_RAY, FALSE); ObjectSet(a_name_0, OBJPROP_WIDTH, a_width_24); ObjectSet(a_name_0, OBJPROP_STYLE, a_style_32); } void DeleteOpen3() { ObjectDelete("OP3"); } void CreateOP3() { DeleteOpen3(); double l_iopen_0 = iOpen(NULL, OPEN_PERIOD_1, 1); double l_iopen_8 = iOpen(NULL, OPEN_PERIOD_2, 1); double l_iopen_16 = iOpen(NULL, OPEN_PERIOD_3, 1); if (Show_OPEN1_LINE == TRUE) CreateOpen1("OP1", l_iopen_0, l_iopen_0, OPEN1_LINE_Width, OPEN1_LINE_Style, OPEN1_LINE_Color); if (Show_OPEN2_LINE == TRUE) CreateOpen2("OP2", l_iopen_8, l_iopen_8, OPEN2_LINE_Width, OPEN2_LINE_Style, OPEN2_LINE_Color); if (Show_OPEN3_LINE == TRUE) CreateOpen3("OP3", l_iopen_16, l_iopen_16, OPEN3_LINE_Width, OPEN3_LINE_Style, OPEN3_LINE_Color); if (Show_LABELS == TRUE) { ObjectDelete("OP_1"); if (ObjectFind("OP_1") != 0) { ObjectCreate("OP_1", OBJ_TEXT, 0, Time[0], l_iopen_0); ObjectSetText("OP_1", "" + gs_152 + " " + DoubleToStr(l_iopen_0, Digits) + "", 11, "Arial", OPEN1_LABEL_Color); } else ObjectMove("OP_1", 0, Time[0], l_iopen_0); ObjectDelete("OP_2"); if (ObjectFind("OP_2") != 0) { ObjectCreate("OP_2", OBJ_TEXT, 0, Time[0], l_iopen_8); ObjectSetText("OP_2", "" + gs_160 + " " + DoubleToStr(l_iopen_8, Digits) + "", 11, "Arial", OPEN2_LABEL_Color); } else ObjectMove("OP_2", 0, Time[0], l_iopen_8); ObjectDelete("OP_3"); if (ObjectFind("OP_3") != 0) { ObjectCreate("OP_3", OBJ_TEXT, 0, Time[0], l_iopen_16); ObjectSetText("OP_3", "" + gs_168 + " " + DoubleToStr(l_iopen_16, Digits) + "", 11, "Arial", OPEN3_LABEL_Color); } else ObjectMove("OP_3", 0, Time[0], l_iopen_16); } } Quote Link to comment Share on other sites More sharing options...
drbastem Posted February 19, 2013 Report Share Posted February 19, 2013 http://www46.zippyshare.com/v/89275335/file.html shabz 1 Quote Link to comment Share on other sites More sharing options...
shabz Posted February 19, 2013 Author Report Share Posted February 19, 2013 (edited) Thanks for your help drbastem. I think the problem is still there, it does not pick up the new 4 hour candle open, eg. at the moment it is 22.15 , it has not picked up the 20.00 open, it is still showing the 16.00 open. The hourly & daily is not a problem. Any ideas ? it may not be a refresh problem as I thought. Edited February 19, 2013 by shabz Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.