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.
Hello, GoodDay all, Please, I need help in finding study materials on how to convert tradingview indicator to an mt5 indicator. Thank you
Although I can sometimes do line-by-line conversions of MQL4 to MQL5, Pine to MQL5 is much more problematic because Pine is rather skeletal. Therefore, "convert" is more like "rewrite" in this case.
The Pine book is at Pine Script Language Reference Manual — TradingView.
The MQL5 book is at MQL5 Programming for Traders – MetaTrader 5 algorithmic/automatic trading language manual.
- 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?