# Variable's value in Function is set to 0

21

Hello I hope someone can help me find an "error" in this function.

The Problem: I want to calculate the high of the last 31 daily candles if Line4CandleHL == false.

The number of days is returned until the point where I put the Print(). If I move it below LineH, LineL the variable LineTFBars does not return 31 but 0.

I have tried all I could think of but just can't find the mistake. I hope someone can help.

```...
extern bool    Line4CandleHL=false;
extern int     Line4TFBars=31;
...

...
CalcLine(Line4CandleHL, Line4TFselected, Line4TFBars, Line4ShiftCandleHL, Line4ShiftBars, Line4Enable, Line4HLabel, Line4Style, Line4Width, Line4HColor,Line4ShowLabel,Line4ShowValue, Line4LLabel, Line4LColor);
...

...
int CalcLine(bool LineCandleHL, int LineTFselected,int LineTFBars, int LineShiftCandleHL, string LineShiftBarsSelected, bool LineEnable, string LineHLabel, int LineStyle, int LineWidth, color LineHColor, bool LineShowLabel,bool LineShowValue, string LineLLabel, color LineLColor){

double LineH;
double LineL;

// Find current daily high
if(LineCandleHL)
{
Print("LineTFBars: "+LineTFBars); -----------------------<<--------<<----<<--
LineH = iHigh(0,LineTFselected,LineShiftCandleHL);
LineL = iLow(0,LineTFselected,LineShiftCandleHL);

}
else
{
LineH = iHigh(NULL,PERIOD_D1,iHighest(NULL,PERIOD_D1,MODE_HIGH,LineTFBars,LineShiftBarsSelected));
LineL = iLow(NULL,PERIOD_D1,iLowest(NULL,PERIOD_D1,MODE_LOW,LineTFBars,LineShiftBarsSelected));
}
...```
17921

vincent ole: The Problem: I want to calculate the high of the last 31 daily candles if Line4CandleHL == false.

The number of days is parsed until the point where I put the Print(). If I move it below LineH, LineL the variable LineTFBars does not return 31 but 0.

1. That's not a problem that's a want.
2. Where you show the Print is when the boolean is true. But you are posting about when it is false. Makes no sense.
3. LineTFBars is a variable, it doesn't return anything. Your code doesn't parse anything. Moving a print statement changes nothing. Makes no sense.
4. On MT4: Unless the current chart is that specific pair/TF referenced (LineTFselected or PERIOD_D1,) you must handle 4066/4073 errors.
Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum
21

whroeder1:
1. That's not a problem that's a want.
2. Where you show the Print is when the boolean is true. But you are posting about when it is false. Makes no sense.
3. LineTFBars is a variable, it doesn't return anything. Your code doesn't parse anything. Moving a print statement changes nothing. Makes no sense.
4. On MT4: Unless the current chart is that specific pair/TF referenced (LineTFselected or PERIOD_D1,) you must handle 4066/4073 errors.
Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

1. The problem I want to solve.

2. As I wrote.. I put the Print there because this is the line I have identified where the variable does not return 31 anymore. Not in the "ture" nor in the "false" area.

3. Probably parse was the wrong word.

4. I don't quite get the code. Which parts do I have to adjust?

I did implement your code and changed the PERIOD_M15 in the function within OnCalculate to PERIOD_D1 but that didnt help and gave me an erro Failed:0 and not showing my indicator anymore.

Also I don't understand why I can hardcode 31 into iHighest but the variable does not work. Can you give an explanation?

Your help is very appreciated.
748

vincent ole:

Hello I hope someone can help me find an "error" in this function.

The Problem: I want to calculate the high of the last 31 daily candles if Line4CandleHL == false.

The number of days is returned until the point where I put the Print(). If I move it below LineH, LineL the variable LineTFBars does not return 31 but 0.

I have tried all I could think of but just can't find the mistake. I hope someone can help.

iHighest

21

Mehmet Bastem:

iHighest

?
To add comments, please log in or register