You have two solutions:
1/ Create two separate booleans and update them with every iteration.
bool var; bool prev_var;
2/ You can create a buffer(which has to be double). The buffer keeps the boolean variable for every single bar in the history. Only thing is you set 1=true and 0=false.
buffer[0]==> var buffer[1]==> prev_var
You have two solutions:
1/ Create two separate booleans and update them with every iteration.
2/ You can create a buffer(which has to be double). The buffer keeps the boolean variable for every single bar in the history. Only thing is you set 1=true and 0=false.
That makes a lot of sense. I will give it a try. Thanks!
In Trading View there is a function barssince that counts the amount of bars that the bool was true. Would I create a custom function in MT5 to do this? Would this work?
condition = *
int countTrueBarscross()
{
count = 0;
int totalBars = Bars(_Symbol, _Period);
for (int i = 0; i < totalBars; i++) {
if(condition) {
count++;
}
}
return count;
}
In Trading View there is a function barssince that counts the amount of bars that the bool was true. Would I create a custom function in MT5 to do this? Would this work?
int pine_barssince(double &conditionBuffer[], int index) { for (int i = index; i < Bars; i++) { if(conditionBuffer[i]==1) return (i-index); } return -1; }This is not that simple... I prefer to keep the condition as a buffer(0=false, 1=true). Also you need to pass the index history because in the first call you need to calculate the historical values of indicator.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Here is my current issue: I am trying to recall the Boolean value from a previous bar. I know Boolean values are either true or false. Doesn't Pine Script treat them both ways, as both true/false and 1/0? I am thinking I should turn my bool variable into a int variable in MT5 and work with the numbers or can you store then recall Boolean true/false values from previous bars in MT5?