Coding help - page 195

 
shtopr:
спасибо за ответ.

проверил h1, m30, m15, m5, m1

по-прежнему работает только один цвет, красный.

That is what I told you : for a 3rd color (when both values are falling in te same range of values) you need to modify the code to add an option for the 3rd color

 
mladen:
Here is a version that uses one column. If you wish a third color, you need to add a new option

on a 2min renko live chart, its just 2 green bars at the top and that is it for all pairs i tired it on, is it normal?

 
drunkpips:
on a 2min renko live chart, its just 2 green bars at the top and that is it for all pairs i tired it on, is it normal?

I do not use renko charts

It is using the built in indicators (iBEarsPower() and iBullsPower()) so if some problems is there with it then the problem is already with the built in indicators itself

 
mladen:
That is what I told you : for a 3rd color (when both values are falling in te same range of values) you need to modify the code to add an option for the 3rd color

Ок. Спасибо!!

 

mladen,

I have studied and played around with 'simple mtf' from post #1874.

Note: It is a MA of a MA, and MTF capable.

I have some questions:

No matter what I do with the code, I cannot understand what the 'returnBars' does, if anything.

1. What determines if the number of changed bars in the target time frame is required and why?

2. Regarding this line:

returnBars = TimeFrame == "returnBars"; // check if number of changed bars is asked for

I am not a highly schooled programmer. I do not know this compound construction. I also do not know the rules to mix variable types.

It looks like the string variable Timeframe is getting the value of the boolean returnBars.

Then it is assigning the value to returnBars - again. ??

Since returnBars is boolean, assign '1' if TimeFrame is greater than 0, else assign '0' ?

3. I set the indicator to a higher TF, and test live (forward) many bars, or in the Strategy tester. I can eliminate the line that uses it, and get NO change on the indicator lines:

if (returnBars) Comment("returnBars ",returnBars, " Tick ",Volume(0));

// if (returnBars) { ma1[0] = limit+1; return(0); }

The comment line onscreen will show "returnBars 1".

I don't know where it gets the '1' value.

Without the 'if' part, it always shows '0'.

Same results if put into Init().

Big Be

 
Big Be:
mladen,

I have studied and played around with 'simple mtf' from post #1874.

Note: It is a MA of a MA, and MTF capable.

I have some questions:

No matter what I do with the code, I cannot understand what the 'returnBars' does, if anything.

1. What determines if the number of changed bars in the target time frame is required and why?

2. Regarding this line:

returnBars = TimeFrame == "returnBars"; // check if number of changed bars is asked for

I am not a highly schooled programmer. I do not know this compound construction. I also do not know the rules to mix variable types.

It looks like the string variable Timeframe is getting the value of the boolean returnBars.

Then it is assigning the value to returnBars - again. ??

Since returnBars is boolean, assign '1' if TimeFrame is greater than 0, else assign '0' ?

3. I set the indicator to a higher TF, and test live (forward) many bars, or in the Strategy tester. I can eliminate the line that uses it, and get NO change on the indicator lines:

if (returnBars) Comment("returnBars ",returnBars, " Tick ",Volume(0));

// if (returnBars) { ma1[0] = limit+1; return(0); }

The comment line onscreen will show "returnBars 1".

I don't know where it gets the '1' value.

Without the 'if' part, it always shows '0'.

Same results if put into Init().

Big Be

Big Be

Imagine this :

1. You are working on a 15 minute chart and your indicator is showing 1 hour data. How many bars have changed on the last tick on 15 minute chart and how many on 1 hour chart? Return bars is checking that. That number does not have to be any assumed value (choose a time frame that you have not visited from your charts for a long time and see what will happen when metatrader starts to download data for that time frame - you must check how many new bars have been downloaded or else you will have to jump back and forth through time frames in order to have an accurate state for past bars of a multi time frame indicator)

2. Of returnBars = TimeFrame == "returnBars";

You have one assignment there (the "=") and one logical comparison there (the "==") That means that returnBars should receive the result of the logical comparison of two strings (TimeFrame and "returnBars")

3. Return bars is a boolean type variable. It can have two values : 0 which equals "false" and 1 which equals "true". That is why you are getting 1 for returnBars (meaning returnBars is set to "true")

______________

PS: if it was for C/C++ rules for boolean, then any value different than 0 would be considered true, and you can test metatrader variables the same way (for example if(someDoubleValue) would test if someDoubleValue is different than 0), but metatrader assignes 0 and 1 to a boolean type variables

 

Dear Mladen

I can not get the point how Poalln indicator repaints. I know iRSI(NULL,0,RSI,PRICE_TYPICAL,i-8) or iCCI(NULL,0,CCI,PRICE_TYPICAL,i-8) means future values, however when calculating last bar there is no data for i-8.

It would be zero I think. So how Pollan repaints?

Best,

 
-IXI-:
Dear Mladen

I can not get the point how Poalln indicator repaints. I know iRSI(NULL,0,RSI,PRICE_TYPICAL,i-8) or iCCI(NULL,0,CCI,PRICE_TYPICAL,i-8) means future values, however when calculating last bar there is no data for i-8.

It would be zero I think. So how Pollan repaints?

Best,

IXI

At a current bar it gets values 0 for those bars. At a first past bar it gets 1 future value and 7 zeroes. And so on.

As new bars form, the bars that were getting zeroes for results of future values are actually getting real future results and then those values are changed according to those "new" future values

 

How can i get this indicator to work on JPY pairs

Hi,

This indi makes a line with every round number and one line 15 pips on each side of the round number.

But it doesn't works with JPY pairs.

What need to be changed in order for this to work?

#property indicator_chart_window

extern color UpperLineColor = Red;

extern color MainLineColor = Red;

extern color LowerLineColor = Red;

extern double HighOffset = 150;

extern double LowOffset = 150;

extern int LineStyle = 2;

extern string LineStyleInfo = "0=Solid,1=Dash,2=Dot,3=DashDot,4=DashDotDot";

double LineSpaceOld;

double Hoch;

double Tief;

bool FirstRun = true;

double LineSpace = 1.0; // 1 unit = 0.01 of basic value (e.g. 1 USD cent)

string LineText = "RoundNr ";

string LineText1 = "RoundNr1 ";

string LineText2 = "RoundNr2 ";

int deinit()

{

double AbSpace = 0.01*LineSpace;

double Oben = MathRound(110*Hoch)/100;

double Unten = MathRound(80*Tief)/100;

for(double i=0; i<=Oben; i+=AbSpace)

{

if(i<Unten) { continue; }

ObjectDelete(LineText+DoubleToStr(i,2));

ObjectDelete(LineText1+DoubleToStr(i,2));

ObjectDelete(LineText2+DoubleToStr(i,2));

}

return(0);

}

int start()

{

if(FirstRun)

{

Hoch = NormalizeDouble( High, 2 );

Tief = NormalizeDouble( Low, 2 );

FirstRun = false;

}

else if(LineSpace != LineSpaceOld)

{

deinit();

Hoch = NormalizeDouble( High, 2 );

Tief = NormalizeDouble( Low, 2 );

}

DrawLines();

LineSpaceOld = LineSpace;

return(0);

}

void DrawLines()

{

double AbSpace = 0.01*LineSpace;

double Oben = MathRound(110*Hoch)/100;

double Unten = MathRound(80*Tief)/100;

for(double i=0; i<=Oben; i+=AbSpace)

{

if(i<Unten) { continue; }

string StringNr = DoubleToStr(i,2); // 2 digits number in object name

if (ObjectFind(LineText+StringNr) != 0) // HLine not in main chartwindow

{

ObjectCreate(LineText+StringNr, OBJ_HLINE, 0, 0, i);

ObjectSet(LineText+StringNr, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText+StringNr, OBJPROP_COLOR, MainLineColor);

}

else // Adjustments

{

ObjectSet(LineText+StringNr, OBJPROP_PRICE1, i);

ObjectSet(LineText+StringNr, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText+StringNr, OBJPROP_COLOR, MainLineColor);

}

//#######################################################################

if(i<Unten) { continue; }

string StringNr1 = DoubleToStr(i,2); // 2 digits number in object name

if (ObjectFind(LineText1+StringNr1) != 0) // HLine not in main chartwindow

{

ObjectCreate(LineText1+StringNr1, OBJ_HLINE, 0, 0, i+(HighOffset/100000));

ObjectSet(LineText1+StringNr1, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText1+StringNr1, OBJPROP_COLOR, UpperLineColor);

}

else // Adjustments

{

ObjectSet(LineText1+StringNr1, OBJPROP_PRICE1, i+(HighOffset/100000));

ObjectSet(LineText1+StringNr1, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText1+StringNr1, OBJPROP_COLOR, UpperLineColor);

}

//#######################################################################

if(i<Unten) { continue; }

string StringNr2 = DoubleToStr(i,2); // 2 digits number in object name

if (ObjectFind(LineText2+StringNr2) != 0) // HLine not in main chartwindow

{

ObjectCreate(LineText2+StringNr2, OBJ_HLINE, 0, 0, i-(LowOffset/100000));

ObjectSet(LineText2+StringNr2, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText2+StringNr2, OBJPROP_COLOR, LowerLineColor);

}

else // Adjustments

{

ObjectSet(LineText2+StringNr2, OBJPROP_PRICE1, i-(LowOffset/100000));

ObjectSet(LineText2+StringNr2, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText2+StringNr2, OBJPROP_COLOR, LowerLineColor);

}

}

WindowRedraw();

}
 
Georgebaker:
Hi,

This indi makes a line with every round number and one line 15 pips on each side of the round number.

But it doesn't works with JPY pairs.

What need to be changed in order for this to work?

#property indicator_chart_window

extern color UpperLineColor = Red;

extern color MainLineColor = Red;

extern color LowerLineColor = Red;

extern double HighOffset = 150;

extern double LowOffset = 150;

extern int LineStyle = 2;

extern string LineStyleInfo = "0=Solid,1=Dash,2=Dot,3=DashDot,4=DashDotDot";

double LineSpaceOld;

double Hoch;

double Tief;

bool FirstRun = true;

double LineSpace = 1.0; // 1 unit = 0.01 of basic value (e.g. 1 USD cent)

string LineText = "RoundNr ";

string LineText1 = "RoundNr1 ";

string LineText2 = "RoundNr2 ";

int deinit()

{

double AbSpace = 0.01*LineSpace;

double Oben = MathRound(110*Hoch)/100;

double Unten = MathRound(80*Tief)/100;

for(double i=0; i<=Oben; i+=AbSpace)

{

if(i<Unten) { continue; }

ObjectDelete(LineText+DoubleToStr(i,2));

ObjectDelete(LineText1+DoubleToStr(i,2));

ObjectDelete(LineText2+DoubleToStr(i,2));

}

return(0);

}

int start()

{

if(FirstRun)

{

Hoch = NormalizeDouble( High, 2 );

Tief = NormalizeDouble( Low, 2 );

FirstRun = false;

}

else if(LineSpace != LineSpaceOld)

{

deinit();

Hoch = NormalizeDouble( High, 2 );

Tief = NormalizeDouble( Low, 2 );

}

DrawLines();

LineSpaceOld = LineSpace;

return(0);

}

void DrawLines()

{

double AbSpace = 0.01*LineSpace;

double Oben = MathRound(110*Hoch)/100;

double Unten = MathRound(80*Tief)/100;

for(double i=0; i<=Oben; i+=AbSpace)

{

if(i<Unten) { continue; }

string StringNr = DoubleToStr(i,2); // 2 digits number in object name

if (ObjectFind(LineText+StringNr) != 0) // HLine not in main chartwindow

{

ObjectCreate(LineText+StringNr, OBJ_HLINE, 0, 0, i);

ObjectSet(LineText+StringNr, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText+StringNr, OBJPROP_COLOR, MainLineColor);

}

else // Adjustments

{

ObjectSet(LineText+StringNr, OBJPROP_PRICE1, i);

ObjectSet(LineText+StringNr, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText+StringNr, OBJPROP_COLOR, MainLineColor);

}

//#######################################################################

if(i<Unten) { continue; }

string StringNr1 = DoubleToStr(i,2); // 2 digits number in object name

if (ObjectFind(LineText1+StringNr1) != 0) // HLine not in main chartwindow

{

ObjectCreate(LineText1+StringNr1, OBJ_HLINE, 0, 0, i+(HighOffset/100000));

ObjectSet(LineText1+StringNr1, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText1+StringNr1, OBJPROP_COLOR, UpperLineColor);

}

else // Adjustments

{

ObjectSet(LineText1+StringNr1, OBJPROP_PRICE1, i+(HighOffset/100000));

ObjectSet(LineText1+StringNr1, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText1+StringNr1, OBJPROP_COLOR, UpperLineColor);

}

//#######################################################################

if(i<Unten) { continue; }

string StringNr2 = DoubleToStr(i,2); // 2 digits number in object name

if (ObjectFind(LineText2+StringNr2) != 0) // HLine not in main chartwindow

{

ObjectCreate(LineText2+StringNr2, OBJ_HLINE, 0, 0, i-(LowOffset/100000));

ObjectSet(LineText2+StringNr2, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText2+StringNr2, OBJPROP_COLOR, LowerLineColor);

}

else // Adjustments

{

ObjectSet(LineText2+StringNr2, OBJPROP_PRICE1, i-(LowOffset/100000));

ObjectSet(LineText2+StringNr2, OBJPROP_STYLE, LineStyle);

ObjectSet(LineText2+StringNr2, OBJPROP_COLOR, LowerLineColor);

}

}

WindowRedraw();

}

Georgebaker,

Why don't you use some of the indicators like this : https://www.mql5.com/en/forum/180648/page307 as a basis for your indicator? It might save you some coding time