I do not know how to save a variable outside of my if statement in my code:
the variables I wish to save are
double buyzone;
double selltp;
Code is:
You are declaring them before any other code, so the values are saved and available outside of the if's until OnTick() returns.
If you want to access the values in subsequent ticks declare them as static variables.
if(Ask==PriceInfo[1].high){Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum
You are declaring them before any other code, so the values are saved and available outside of the if's until OnTick() returns.
If you want to access the values in subsequent ticks declare them as static variables.
the code doesnt work if I do static double buyzone
I dont know what I am meant to do
the code doesnt work if I do static double buyzone
I dont know what I am meant to do
First, do not equate doubles.
Second, don't die with a single code. Just explain to us what you are trying to do, then maybe we can advice on the best approach to use.
First, do not equate doubles.
Second, don't die with a single code. Just explain to us what you are trying to do, then maybe we can advice on the best approach to use.
I am trying to save the low value of a candle and when another candle crosses over it completely it will initiate a trade. Something like
candle 1 is doji
next candle is doji therefore save the lowest of candle 2
candle 1 is doji next candle is doji therefore save the lowest of candle 2
- Unless you can define your condition concretely, it can't be coded. E.g. define Doji
double body = MathAbs(C-O), range = H-L; bool doji = body < 10/100.*range;
- What does a Doji have to do with your "trying to save … when …?"
- Where do you define "crosses over it completely?" Where do you save the low? Show us your attempt (using the CODE button)
and state the nature of your problem.
No free help 2017.04.21
- Unless you can define your condition concretely, it can't be coded. E.g. define Doji
- What does a Doji have to do with your "trying to save … when …?"
- Where do you define "crosses over it completely?" Where do you save the low? Show us your attempt (using
the CODE button)
and state the nature of your problem.
No free help 2017.04.21
I am simply trying to save the low value of a candle outside an if statement
When I type static int saveval=PriceInfo[1].low I get an error
I am simply trying to save the low value of a candle outside an if statement
When I type static int saveval=PriceInfo[1].low I get an error
static int saveval=PriceInfo[1].low
You must initialize a static variable with a constant.
Also PriceInfo sounds like it would probably be a double, so why are you trying to store it in an integer variable.
I am simply trying to save the low value of a candle outside an if statement
When I type static int saveval=PriceInfo[1].low I get an error
My suggestion would be to do the following:
//at the top of your program, where you define global variables double saveval = -1.0; //in the OnItick() function: void OnTick() { //collect the data you need. //then assign value to saveval, but only if it is a valid value: if(PriceInfo[1].low > 0) saveval = PriceInfo[1].low; //by the time you want to use saveval: if (saveval > 0) { //insert here the code which uses saveval } }
I assume that the value you will store in saveval will always be a positive value. I initialize saveval with a negative value so that I can check on the first run that it has received a valid value from PriceInfo[1].low This may help to avoid your program using saveval with an invalid value. For example if an error occurred and no prices have been received.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I do not know how to save a variable outside of my if statement in my code:
the variables I wish to save are
double buyzone;
double selltp;
Code is: