How can I store a timeframe value in a variable?
I have tried the following code, but it is not accepted:
tf1 = 5 minutes
tf2 = 15 minutes
//timeframe tf1
timeframe (tf1)
tf1myMACD=exponentialaverage[12]-exponentialaverage[26]
//timeframe tf2
timeframe (tf2)
tf2myMACD=exponentialaverage[12]-exponentialaverage[26]
timeframe (default)
return tf1myMACD, tf2myMACD
Thanks for your support.
Walter
You should create a new topic for that really
However I dont think you can.
You can create a variable within a timeframe and use that, but timeframe code itself can’t be stored differently as far as I’m aware.
Best thread is https://www.prorealcode.com/blog/learning/approach-multi-timeframe-trading-prorealtime/
Generally you have to create your variables within the specified timeframes you want them in, but timeframes themselves are unable to be stored as variables… The logic of coding is to select the timeframe you want to get data from and use the variables within your code. The above thread will help to see how that can be used within the default timeframe being used.
Somehow I don’t think this is possible. I have written a probacktest and indicator (see attached) using 2hr, 1hr,30 minute and 15 minute timeframes. Each time I’m told to use a 5 minute timeframe because all timeframes are divisable by 5 minutes. I’ve also tried using the TIMEFRAME (default) command but alas, no joy.
Is it possible guys?
Many thanks in anticipation.
@geier777
I created a new topic. Do not append different questions to existing topics, as suggested by Philstrading, as this would make it difficult to search the correct infos, when needed. Thanks 🙂
As stated in the prior post, it’s not possible to use variables with the TIMEFRAME keyword.
My apologies Robert.
While off sick today I’ve played with the probacktest and am getting entries on the 15 minute chart, however the issue I’m now having is exit of positions, for some reason the backtest is not recognising the exit conditions.
Many thanks in anticipation.
JSParticipant
Senior
Hi
When I backtest your system “Bolly” on a time frame of 5 minutes then there are no problems…
Both long and short trades…
good afternoon
1st of all many thanks for your reply. The code doesn’t seem to have an issue entering trades, it is the exit criteria. trades should be exited when the hourly close hits 50 RSI?
It’s because of the missing UPDATEONCLOSE keyword (hence the DEFAULT keyword is assumed), as your chart will display a wrong RSI at closing time, while when the 1-hour bar is forming it happened to be in the correct range.