# [Help] SetLevelValue() - Switching To Other Time-frame Showing Unnecessary Lines/Maybe Lines in Previous Time-frame. (Image & Souce Code Included)

340

[Help] SetLevelValue() - Switching To Other Time-frame Showing Unnecessary Lines/Maybe Lines in Previous Time-frame. This is bug in SetLevelValue().

If I switch to other time-frame there's an additional lines that appearing. For example: From M15 to D1 time-frame I see some lines from M15 that placed in D1.

double G_Max = WindowPriceMax(1);
double CG_Min = WindowPriceMin(1);
double G_Min = -CG_Min;

int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- the last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//---- main loop
for(int i=0; i<limit; i++)
{
/* some code here */
}

double max = WindowPriceMax(1);
if(G_Max != max)  // Check if Previous PriceMax is different in Current PriceMax, if true then recalculate the LevelValue again
{
double cmin = WindowPriceMin(1);
double min = -cmin;  // Turn negative to positive

if(max >= min)  // Check which of the two are highest value
{
//Positive
SetLevelValue(1, max * 0.12);  // To get 12% of PriceMax
SetLevelValue(2, max * 0.25);  // 25%
SetLevelValue(3, max * 0.50);  // 50%
SetLevelValue(4, max * 0.75);  // 75%

// Negative
SetLevelValue(5, -(max * 0.12));  // Turn negative to positive
SetLevelValue(6, -(max * 0.25));  // Turn negative to positive

double max7 = -(max * 0.50);  // Turn negative to positive
if(max7 < min)  // if false then don't put lines greater than PriceMin
{
SetLevelValue(7, -(max * 0.50));  // Turn negative to positive
}

double max8 = -(max * 0.75);
if(max8 < min)
{
SetLevelValue(8, -(max * 0.75));
}
}
else
{
//Positive
SetLevelValue(1, min * 0.12);
SetLevelValue(2, min * 0.25);
SetLevelValue(3, min * 0.50);
SetLevelValue(4, min * 0.75);

// Negative
SetLevelValue(5, -(min * 0.12));
SetLevelValue(6, -(min * 0.25));

double min7 = (min * 0.50);
if(min7 < max)
{
SetLevelValue(7, -(min * 0.50));
}

double min8 = (min * 0.75);
if(min8 < max)
{
SetLevelValue(8, -(min * 0.75));
}
}
G_Max = max;  // G_Max is Previous PriceMax value = max is Current PriceMax value
}

return 0;
}
7674

Start declaring your levels with 0 not 1!

As levels are counted like arrays from 0 to (max 31) your counting will create a remaining level 0.

//Positive
SetLevelValue(0, max * 0.12);  // To get 12% of PriceMax
SetLevelValue(1, max * 0.25);  // 25%
SetLevelValue(2, max * 0.50);  // 50%
SetLevelValue(3, max * 0.75);  // 75%

// Negative
SetLevelValue(4, -(max * 0.12));  // Turn negative to positive
SetLevelValue(5, -(max * 0.25));  // Turn negative to positive
340

Carl Schreiber:

Start declaring your levels with 0 not 1!

As levels are counted like arrays from 0 to (max 31) your counting will create a remaining level 0.

//Positive
SetLevelValue(0, max * 0.12);  // To get 12% of PriceMax
SetLevelValue(1, max * 0.25);  // 25%
SetLevelValue(2, max * 0.50);  // 50%
SetLevelValue(3, max * 0.75);  // 75%

// Negative
SetLevelValue(4, -(max * 0.12));  // Turn negative to positive
SetLevelValue(5, -(max * 0.25));  // Turn negative to positive
I thought 0 is for level value 'zero' that's why I don't use it. If I use 0 will my problem solved?
340

It don't work.
48876

Musngi:
It don't work.
You must create one function for your custom setlevelvalue, and call it from OnInit function.
Because setlevelvalue is custom indicators property, which should be set through OnInit.
340

Roberto Jacobs:
You must create one function for your custom setlevelvalue, and call it from OnInit function.
Because setlevelvalue is custom indicators property, which should be set through OnInit.
I can't understand why I need to create user defined function for setlevelvalue to put in OnInit function then call it.
48876

Musngi:
I can't understand why I need to create user defined function for setlevelvalue to put in OnInit function then call it.

maybe you have time to read

https://docs.mql4.com/customind

https://www.mql5.com/en/forum/125574#312042

Custom Indicators - MQL4 Reference
• docs.mql4.com
Custom Indicators - MQL4 Reference