[Request] Market Session Indicator - page 3

 

Hi mladen, mrtools;

This is a good market sessions indi from Adam Jowett from his website...

One thing I noticed is its very resource intensive since it draws the sessions on all of the history visible for the symbol… on many pairs then it slows down the terminal… especially on offline charts...

I tried to add an input, extern int NumberOfDays = 3; and the loop, for (int d=0; d<NumberOfDays; d++) { ...} at appropriate functions init(), deinit() and start()... and am not getting the results on the chart,.. I don't seem to know what/where I am doing the code wrong in the indi code;

could you please add that NumberOfDays option in the code to limit the sessions display to days ( such that the Indicator only draws sessions for (n) days specified by the user in inputs )… This would help a lot in using this indi across pairs and mt4's simultaneously…

Thanking you!

Best Regards,

Mony

Files:
 
SSL:
Hi mladen, mrtools;

This is a good market sessions indi from Adam Jowett from his website...

One thing I noticed is its very resource intensive since it draws the sessions on all of the history visible for the symbol… on many pairs then it slows down the terminal… especially on offline charts...

I tried to add an input, extern int NumberOfDays = 3; and the loop, for (int d=0; d<=NumberOfDays; d++) { ...} at appropriate functions init(), deinit() and start()... and am not getting the results on the chart,.. I don't seem to know what/where I am doing the code wrong in the indi code;

could you please add that NumberOfDays option in the code to limit the sessions display to days ( such that the Indicator only draws sessions for (n) days specified by the user in inputs )… This would help a lot in using this indi across pairs and mt4's simultaneously…

Thanking you!

Best Regards,

Mony

Hi mladen, mrtools;

Could you please help me with this indicator modification request...

limiting the indicator to few days sessions would help a lot especially on the offline charts....(where huge cpu usage is an issue)...

Thanks a lot!

Best Regards

Mony

 
SSL:
Hi mladen, mrtools;

Could you please help me with this indicator modification request...

limiting the indicator to few days sessions would help a lot especially on the offline charts....(where huge cpu usage is an issue)...

Thanks a lot!

Best Regards

Mony

Mony

I tested that indicator on my chart and it did not cause any significant CPU overload. I am using charts with 5000 bars

 
mladen:
Mony I tested that indicator on my chart and it did not cause any significant CPU overload. I am using charts with 5000 bars

yes, on the online/standard timeframe charts its not much of an issue ... however it bogs down the terminal when used on offline charts (like Rangebars/renko charts)... even on a single offline chart of bars with more than 3k ... and renders the terminal stuck when used on more than one offline chart...

I tried to modify the code to limit it to nDays, but I didn't get the result...

below I am posting the code the way I tried, but I couldn't figure out where I am doing it wrong... please help me rectify it with your expertise...!

extern string __ = "Times in 24hr GMT time. Enter -1 to disable a line";

extern int nDays = 3;

extern string sydney = "22:00";

extern string tokyo = "23:00";

extern string london = "8:00";

extern string newyork = "12:00";

extern int gmtServerOffset = 3;

extern bool showInIndicatorWindows = true;

extern bool showFutureSessions = true;

extern bool showOpenPrice = false;

extern bool showPreviousRange = false;

extern bool colourLabels = true;

extern int maxTimeframe = PERIOD_H4;

extern color tokyoColour = DeepSkyBlue;

extern color sydneyColour = Plum;

extern color londonColour = Magenta;

extern color newYorkColour = Gold;

extern color futureSessionColour = DimGray;

extern ENUM_LINE_STYLE lineStyle = STYLE_DASHDOT;

int start()

{

if (Bars <= 10) return(0);

if (Period() > maxTimeframe) {

clearScreen(prefix, true, NULL);

Print("Market Sessions will only show on " + maxTimeframe + " or lower");

return(0);

}

int counted = IndicatorCounted();

if (counted < 0) return(-1);

if (counted > 0) counted--;

int i = Bars - counted;

int timeRange = 0;

double rangeHigh = 0;

double rangeLow = 0;

int days = 0;

int sessions = 0;

while(i>0)

{

while (nDays>0){

int currentTime = Time;

int dayNumber = TimeDayOfWeek(currentTime) + 1;

string offsetLabel = (gmtServerOffset >= 0) ? "+" + gmtServerOffset : gmtServerOffset;

string sydneyLabel = "Sydney open [" + sydney + " " + offsetLabel + "]";

string tokyoLabel = "Tokyo [" + tokyo + " " + offsetLabel + "]";

string londonLabel = "London [" + london + " " + offsetLabel + "]";

string newYorkLabel = "New York [" + newyork + " " + offsetLabel + "]";

if (TimeHour(currentTime) == sydneyHour && TimeMinute(currentTime) == sydneyMinute)

{

ObjectDelete(prefix + "future_line" + lastSydneySession);

lastSydneySession = currentTime;

drawVerticalLine(prefix + "sydneyTimeOpen"+i, currentTime, 1, sydneyColour, lineStyle, true, sydneyLabel);

if (showOpenPrice) drawTrendLine(prefix +"sydneyopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, sydneyColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastNewYorkSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "nyRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "nyRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == tokyoHour && TimeMinute(currentTime) == tokyoMinute)

{

ObjectDelete(prefix + "future_line" + lastTokyoSession);

lastTokyoSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, tokyoColour, lineStyle, true, tokyoLabel);

if (showOpenPrice) drawTrendLine(prefix +"tokyoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, tokyoColour, 4, true, false, DoubleToStr(Open, Digits));

}

else if (TimeHour(currentTime) == londonHour && TimeMinute(currentTime) == londonMinute)

{

ObjectDelete(prefix + "future_line" + lastLondonSession);

lastLondonSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, londonColour, lineStyle, true, londonLabel);

if (showOpenPrice) drawTrendLine(prefix +"londonoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, londonColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastSydneySession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "asianRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "asianRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == newyorkHour && TimeMinute(currentTime) == nyMinute)

{

ObjectDelete(prefix + "future_line" + lastNewYorkSession);

lastNewYorkSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, newYorkColour, lineStyle, true, newYorkLabel);

if (showOpenPrice) drawTrendLine(prefix +"newyorkopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, newYorkColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastLondonSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "ukRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "ukRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

if (i == 1) {

if (showFutureSessions) {

int project = (TimeDayOfWeek(lastNewYorkSession) == 5 || TimeDayOfWeek(lastSydneySession) == 5) ? oneDay * 3 : oneDay;

drawFutureSession(lastSydneySession + project, sydneyLabel);

drawFutureSession(lastTokyoSession + project, tokyoLabel);

drawFutureSession(lastLondonSession + project, londonLabel);

drawFutureSession(lastNewYorkSession + project, newYorkLabel);

}

}

nDays--; }

i--;

}

return(0);

}

--------- or --------------

 

extern string __ = "Times in 24hr GMT time. Enter -1 to disable a line";

extern int nDays = 3;

extern string sydney = "22:00";

extern string tokyo = "23:00";

extern string london = "8:00";

extern string newyork = "12:00";

extern int gmtServerOffset = 3;

extern bool showInIndicatorWindows = true;

extern bool showFutureSessions = true;

extern bool showOpenPrice = false;

extern bool showPreviousRange = false;

extern bool colourLabels = true;

extern int maxTimeframe = PERIOD_H4;

extern color tokyoColour = DeepSkyBlue;

extern color sydneyColour = Plum;

extern color londonColour = Magenta;

extern color newYorkColour = Gold;

extern color futureSessionColour = DimGray;

extern ENUM_LINE_STYLE lineStyle = STYLE_DASHDOT;

int start()

{

if (Bars <= 10) return(0);

if (Period() > maxTimeframe) {

clearScreen(prefix, true, NULL);

Print("Market Sessions will only show on " + maxTimeframe + " or lower");

return(0);

}

int counted = IndicatorCounted();

if (counted < 0) return(-1);

if (counted > 0) counted--;

int i = Bars - counted;

int timeRange = 0;

double rangeHigh = 0;

double rangeLow = 0;

int days = 0;

int sessions = 0;

for(int d=nDays; d>=0; d--){

while(i>0){

int currentTime = Time;

int dayNumber = TimeDayOfWeek(currentTime) + 1;

string offsetLabel = (gmtServerOffset >= 0) ? "+" + gmtServerOffset : gmtServerOffset;

string sydneyLabel = "Sydney open [" + sydney + " " + offsetLabel + "]";

string tokyoLabel = "Tokyo [" + tokyo + " " + offsetLabel + "]";

string londonLabel = "London [" + london + " " + offsetLabel + "]";

string newYorkLabel = "New York [" + newyork + " " + offsetLabel + "]";

if (TimeHour(currentTime) == sydneyHour && TimeMinute(currentTime) == sydneyMinute)

{

ObjectDelete(prefix + "future_line" + lastSydneySession);

lastSydneySession = currentTime;

drawVerticalLine(prefix + "sydneyTimeOpen"+i, currentTime, 1, sydneyColour, lineStyle, true, sydneyLabel);

if (showOpenPrice) drawTrendLine(prefix +"sydneyopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, sydneyColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastNewYorkSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "nyRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "nyRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == tokyoHour && TimeMinute(currentTime) == tokyoMinute)

{

ObjectDelete(prefix + "future_line" + lastTokyoSession);

lastTokyoSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, tokyoColour, lineStyle, true, tokyoLabel);

if (showOpenPrice) drawTrendLine(prefix +"tokyoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, tokyoColour, 4, true, false, DoubleToStr(Open, Digits));

}

else if (TimeHour(currentTime) == londonHour && TimeMinute(currentTime) == londonMinute)

{

ObjectDelete(prefix + "future_line" + lastLondonSession);

lastLondonSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, londonColour, lineStyle, true, londonLabel);

if (showOpenPrice) drawTrendLine(prefix +"londonoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, londonColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastSydneySession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "asianRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "asianRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == newyorkHour && TimeMinute(currentTime) == nyMinute)

{

ObjectDelete(prefix + "future_line" + lastNewYorkSession);

lastNewYorkSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, newYorkColour, lineStyle, true, newYorkLabel);

if (showOpenPrice) drawTrendLine(prefix +"newyorkopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, newYorkColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastLondonSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "ukRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "ukRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

if (i == 1) {

if (showFutureSessions) {

int project = (TimeDayOfWeek(lastNewYorkSession) == 5 || TimeDayOfWeek(lastSydneySession) == 5) ? oneDay * 3 : oneDay;

drawFutureSession(lastSydneySession + project, sydneyLabel);

drawFutureSession(lastTokyoSession + project, tokyoLabel);

drawFutureSession(lastLondonSession + project, londonLabel);

drawFutureSession(lastNewYorkSession + project, newYorkLabel);

}

}

i--;

}

}

return(0);

}

 

-------- or --------

extern string __ = "Times in 24hr GMT time. Enter -1 to disable a line";

extern int nDays = 3;

extern string sydney = "22:00";

extern string tokyo = "23:00";

extern string london = "8:00";

extern string newyork = "12:00";

extern int gmtServerOffset = 3;

extern bool showInIndicatorWindows = true;

extern bool showFutureSessions = true;

extern bool showOpenPrice = false;

extern bool showPreviousRange = false;

extern bool colourLabels = true;

extern int maxTimeframe = PERIOD_H4;

extern color tokyoColour = DeepSkyBlue;

extern color sydneyColour = Plum;

extern color londonColour = Magenta;

extern color newYorkColour = Gold;

extern color futureSessionColour = DimGray;

extern ENUM_LINE_STYLE lineStyle = STYLE_DASHDOT;

int start()

{

if (Bars <= 10) return(0);

if (Period() > maxTimeframe) {

clearScreen(prefix, true, NULL);

Print("Market Sessions will only show on " + maxTimeframe + " or lower");

return(0);

}

int counted = IndicatorCounted();

if (counted < 0) return(-1);

if (counted > 0) counted--;

int i = Bars - counted;

int timeRange = 0;

double rangeHigh = 0;

double rangeLow = 0;

int days = 0;

int sessions = 0;

while(i>0){

for(int d=nDays; d>=0; d--){

int currentTime = Time;

int dayNumber = TimeDayOfWeek(currentTime) + 1;

string offsetLabel = (gmtServerOffset >= 0) ? "+" + gmtServerOffset : gmtServerOffset;

string sydneyLabel = "Sydney open [" + sydney + " " + offsetLabel + "]";

string tokyoLabel = "Tokyo [" + tokyo + " " + offsetLabel + "]";

string londonLabel = "London [" + london + " " + offsetLabel + "]";

string newYorkLabel = "New York [" + newyork + " " + offsetLabel + "]";

if (TimeHour(currentTime) == sydneyHour && TimeMinute(currentTime) == sydneyMinute)

{

ObjectDelete(prefix + "future_line" + lastSydneySession);

lastSydneySession = currentTime;

drawVerticalLine(prefix + "sydneyTimeOpen"+i, currentTime, 1, sydneyColour, lineStyle, true, sydneyLabel);

if (showOpenPrice) drawTrendLine(prefix +"sydneyopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, sydneyColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastNewYorkSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "nyRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "nyRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == tokyoHour && TimeMinute(currentTime) == tokyoMinute)

{

ObjectDelete(prefix + "future_line" + lastTokyoSession);

lastTokyoSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, tokyoColour, lineStyle, true, tokyoLabel);

if (showOpenPrice) drawTrendLine(prefix +"tokyoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, tokyoColour, 4, true, false, DoubleToStr(Open, Digits));

}

else if (TimeHour(currentTime) == londonHour && TimeMinute(currentTime) == londonMinute)

{

ObjectDelete(prefix + "future_line" + lastLondonSession);

lastLondonSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, londonColour, lineStyle, true, londonLabel);

if (showOpenPrice) drawTrendLine(prefix +"londonoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, londonColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastSydneySession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "asianRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "asianRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == newyorkHour && TimeMinute(currentTime) == nyMinute)

{

ObjectDelete(prefix + "future_line" + lastNewYorkSession);

lastNewYorkSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, newYorkColour, lineStyle, true, newYorkLabel);

if (showOpenPrice) drawTrendLine(prefix +"newyorkopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, newYorkColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastLondonSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "ukRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "ukRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

if (i == 1) {

if (showFutureSessions) {

int project = (TimeDayOfWeek(lastNewYorkSession) == 5 || TimeDayOfWeek(lastSydneySession) == 5) ? oneDay * 3 : oneDay;

drawFutureSession(lastSydneySession + project, sydneyLabel);

drawFutureSession(lastTokyoSession + project, tokyoLabel);

drawFutureSession(lastLondonSession + project, londonLabel);

drawFutureSession(lastNewYorkSession + project, newYorkLabel);

}

} }

i--;

}

return(0);

}

 

----- or -----

extern string __ = "Times in 24hr GMT time. Enter -1 to disable a line";

extern int nDays = 3;

extern string sydney = "22:00";

extern string tokyo = "23:00";

extern string london = "8:00";

extern string newyork = "12:00";

extern int gmtServerOffset = 3;

extern bool showInIndicatorWindows = true;

extern bool showFutureSessions = true;

extern bool showOpenPrice = false;

extern bool showPreviousRange = false;

extern bool colourLabels = true;

extern int maxTimeframe = PERIOD_H4;

extern color tokyoColour = DeepSkyBlue;

extern color sydneyColour = Plum;

extern color londonColour = Magenta;

extern color newYorkColour = Gold;

extern color futureSessionColour = DimGray;

extern ENUM_LINE_STYLE lineStyle = STYLE_DASHDOT;

int start()

{

if (Bars <= 10) return(0);

if (Period() > maxTimeframe) {

clearScreen(prefix, true, NULL);

Print("Market Sessions will only show on " + maxTimeframe + " or lower");

return(0);

}

int counted = IndicatorCounted();

if (counted < 0) return(-1);

if (counted > 0) counted--;

int i = Bars - counted;

int timeRange = 0;

double rangeHigh = 0;

double rangeLow = 0;

int days = 0;

int sessions = 0;

if(Period()0){

for(int d=nDays; d>=0; d--){

int currentTime = Time;

int dayNumber = TimeDayOfWeek(currentTime) + 1;

string offsetLabel = (gmtServerOffset >= 0) ? "+" + gmtServerOffset : gmtServerOffset;

string sydneyLabel = "Sydney open [" + sydney + " " + offsetLabel + "]";

string tokyoLabel = "Tokyo [" + tokyo + " " + offsetLabel + "]";

string londonLabel = "London [" + london + " " + offsetLabel + "]";

string newYorkLabel = "New York [" + newyork + " " + offsetLabel + "]";

if (TimeHour(currentTime) == sydneyHour && TimeMinute(currentTime) == sydneyMinute)

{

ObjectDelete(prefix + "future_line" + lastSydneySession);

lastSydneySession = currentTime;

drawVerticalLine(prefix + "sydneyTimeOpen"+i, currentTime, 1, sydneyColour, lineStyle, true, sydneyLabel);

if (showOpenPrice) drawTrendLine(prefix +"sydneyopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, sydneyColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastNewYorkSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "nyRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "nyRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == tokyoHour && TimeMinute(currentTime) == tokyoMinute)

{

ObjectDelete(prefix + "future_line" + lastTokyoSession);

lastTokyoSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, tokyoColour, lineStyle, true, tokyoLabel);

if (showOpenPrice) drawTrendLine(prefix +"tokyoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, tokyoColour, 4, true, false, DoubleToStr(Open, Digits));

}

else if (TimeHour(currentTime) == londonHour && TimeMinute(currentTime) == londonMinute)

{

ObjectDelete(prefix + "future_line" + lastLondonSession);

lastLondonSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, londonColour, lineStyle, true, londonLabel);

if (showOpenPrice) drawTrendLine(prefix +"londonoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, londonColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastSydneySession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "asianRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "asianRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == newyorkHour && TimeMinute(currentTime) == nyMinute)

{

ObjectDelete(prefix + "future_line" + lastNewYorkSession);

lastNewYorkSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, newYorkColour, lineStyle, true, newYorkLabel);

if (showOpenPrice) drawTrendLine(prefix +"newyorkopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, newYorkColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastLondonSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "ukRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "ukRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

if (i == 1) {

if (showFutureSessions) {

int project = (TimeDayOfWeek(lastNewYorkSession) == 5 || TimeDayOfWeek(lastSydneySession) == 5) ? oneDay * 3 : oneDay;

drawFutureSession(lastSydneySession + project, sydneyLabel);

drawFutureSession(lastTokyoSession + project, tokyoLabel);

drawFutureSession(lastLondonSession + project, londonLabel);

drawFutureSession(lastNewYorkSession + project, newYorkLabel);

}

}

}

i--;

}

return(0);

}

I also tried adding the for{} in the init() and/or denint() as well, tested with many different ways, still clueless as to where am getting it wrong... so requesting your expertise .....

( inorder not to clutter the thread pages, I didn't post the code combinations I tried earlier... )

Best Regards,

Mony

 
SSL:
yes, on the online/standard timeframe charts its not much of an issue ... however it bogs down the terminal when used on offline charts (like Rangebars/renko charts)... even on a single offline chart of bars with more than 3k ... and renders the terminal stuck when used on more than one offline chart...

I tried to modify the code to limit it to nDays, but I didn't get the result...

below I am posting the code the way I tried, but I couldn't figure out where I am doing it wrong... please help me rectify it with your expertise...!

extern string __ = "Times in 24hr GMT time. Enter -1 to disable a line";

extern int nDays = 3;

extern string sydney = "22:00";

extern string tokyo = "23:00";

extern string london = "8:00";

extern string newyork = "12:00";

extern int gmtServerOffset = 3;

extern bool showInIndicatorWindows = true;

extern bool showFutureSessions = true;

extern bool showOpenPrice = false;

extern bool showPreviousRange = false;

extern bool colourLabels = true;

extern int maxTimeframe = PERIOD_H4;

extern color tokyoColour = DeepSkyBlue;

extern color sydneyColour = Plum;

extern color londonColour = Magenta;

extern color newYorkColour = Gold;

extern color futureSessionColour = DimGray;

extern ENUM_LINE_STYLE lineStyle = STYLE_DASHDOT;

int start()

{

if (Bars <= 10) return(0);

if (Period() > maxTimeframe) {

clearScreen(prefix, true, NULL);

Print("Market Sessions will only show on " + maxTimeframe + " or lower");

return(0);

}

int counted = IndicatorCounted();

if (counted < 0) return(-1);

if (counted > 0) counted--;

int i = Bars - counted;

int timeRange = 0;

double rangeHigh = 0;

double rangeLow = 0;

int days = 0;

int sessions = 0;

while(i>0)

{

while (nDays>0){

int currentTime = Time;

int dayNumber = TimeDayOfWeek(currentTime) + 1;

string offsetLabel = (gmtServerOffset >= 0) ? "+" + gmtServerOffset : gmtServerOffset;

string sydneyLabel = "Sydney open [" + sydney + " " + offsetLabel + "]";

string tokyoLabel = "Tokyo [" + tokyo + " " + offsetLabel + "]";

string londonLabel = "London [" + london + " " + offsetLabel + "]";

string newYorkLabel = "New York [" + newyork + " " + offsetLabel + "]";

if (TimeHour(currentTime) == sydneyHour && TimeMinute(currentTime) == sydneyMinute)

{

ObjectDelete(prefix + "future_line" + lastSydneySession);

lastSydneySession = currentTime;

drawVerticalLine(prefix + "sydneyTimeOpen"+i, currentTime, 1, sydneyColour, lineStyle, true, sydneyLabel);

if (showOpenPrice) drawTrendLine(prefix +"sydneyopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, sydneyColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastNewYorkSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "nyRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "nyRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == tokyoHour && TimeMinute(currentTime) == tokyoMinute)

{

ObjectDelete(prefix + "future_line" + lastTokyoSession);

lastTokyoSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, tokyoColour, lineStyle, true, tokyoLabel);

if (showOpenPrice) drawTrendLine(prefix +"tokyoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, tokyoColour, 4, true, false, DoubleToStr(Open, Digits));

}

else if (TimeHour(currentTime) == londonHour && TimeMinute(currentTime) == londonMinute)

{

ObjectDelete(prefix + "future_line" + lastLondonSession);

lastLondonSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, londonColour, lineStyle, true, londonLabel);

if (showOpenPrice) drawTrendLine(prefix +"londonoopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, londonColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastSydneySession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "asianRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "asianRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

else if (TimeHour(currentTime) == newyorkHour && TimeMinute(currentTime) == nyMinute)

{

ObjectDelete(prefix + "future_line" + lastNewYorkSession);

lastNewYorkSession = currentTime;

drawVerticalLine(prefix + "line"+i, currentTime, 1, newYorkColour, lineStyle, true, newYorkLabel);

if (showOpenPrice) drawTrendLine(prefix +"newyorkopen" + i, currentTime, currentTime + sessionLength, Open, Open, 1, newYorkColour, 4, true, false, DoubleToStr(Open, Digits));

if (showPreviousRange) {

timeRange = iBarShift(NULL, 0, lastLondonSession) - iBarShift(NULL, 0, currentTime) - 1;

rangeHigh = High;

rangeLow = Low;

drawTrendLine(prefix + "ukRangeHigh" + i, currentTime, currentTime + sessionLength, rangeHigh, rangeHigh, 1, DimGray, 2, true, false, "");

drawTrendLine(prefix + "ukRangeLow" + i, currentTime, currentTime + sessionLength, rangeLow, rangeLow, 1, DimGray, 2, true, false, "");

}

}

if (i == 1) {

if (showFutureSessions) {

int project = (TimeDayOfWeek(lastNewYorkSession) == 5 || TimeDayOfWeek(lastSydneySession) == 5) ? oneDay * 3 : oneDay;

drawFutureSession(lastSydneySession + project, sydneyLabel);

drawFutureSession(lastTokyoSession + project, tokyoLabel);

drawFutureSession(lastLondonSession + project, londonLabel);

drawFutureSession(lastNewYorkSession + project, newYorkLabel);

}

}

nDays--; }

i--;

}

return(0);

}

--------- or --------------

The problem with the offline charts is the problem of metatrader not a problem of the regular code used on it : ever since they started with the new mt4, a bunch on standard mql functions are not working properly when applied to offline charts and that causes CPU overload.

They were informed about it, but they never bothered to correct those errors. Making any workaround is useless, because, in my experience, with each new build some new problem with functions when used on offline charts emerges and if we were to make workarounds just to correct what mt un-corrected, there would be no end to it

___________________

The question why mt does not want offline charts any more (since the errors emerging can not be that precisely targeted to offline chart by chance) is a question for mt owners ...

 
mladen:
The problem with the offline charts is the problem of metatrader not a problem of the regular code used on it : ever since they started with the new mt4, a bunch on standard mql functions are not working properly when applied to offline charts and that causes CPU overload.

They were informed about it, but they never bothered to correct those errors. Making any workaround is useless, because, in my experience, with each new build some new problem with functions when used on offline charts emerges and if we were to make workarounds just to correct what mt un-corrected, there would be no end to it

___________________

The question why mt does not want offline charts any more (since the errors emerging can not be that precisely targeted to offline chart by chance) is a question for mt owners ...

Yep mladen, I understand the root cause for these issues on offline charts since I have read your posts regarding the matter posted several times in this forum across many threads related to offline charting... along with this issue, another issue is of indicators being re-executed on the offline charts on new bars formed...

God only knows the reason as to why MT does n't come with inbuilt Range/Renko/Tick charts by default like the standard tf charts...

This would make MT the level-playing field among traders on-par with other well-known professional trading platforms ... and also eliminate dependencies for offline charting and thereby also eliminate many redundancies at the same time...!

 

I understand and also chime with you that making workarounds would not solve the discrepancies, and lately from 600+ builds, things should have actually been taken to the next level... but its not so...

but the changes they are making are working for whose favor??? not for traders as far as I see... time only will tell for who's benefit...

meanwhile, just to reduce the overload a bit on the terminal/cpu for time-being by limiting this particular indicator to only n days specified, its really an issue with indicator printing all the way thro history, could you please help as to where what code has to be placed ???

because by using a few other indis like bbands-stop which only works upto specified bars have really shown some mercy on the resources unlike other indis which print all of the chart in these newer builds...

Please let me know...

Thanks a lot!