how to use the same variable in different timeframes
Forums › ProRealTime English forum › ProOrder support › how to use the same variable in different timeframes
- This topic has 4 replies, 3 voices, and was last updated 1 month ago by Vicke1990.
-
-
10/22/2024 at 1:19 PM #239329
Hi fellow traders and coders,
I’m havning an issue where I get an error message when trying to use a the same variable in different timeframes,
Example:
A variable cannot be assigned in multiple different timeframes, you need to use a different variable. Timeframe 3 minutes, line 1, variable “Size” is alredy assigned in timeframe 15 minutes, updateonclose.
Note: the same variable may be read in different timeframes by the code editor as long as it is only assigned in one timeframe.
Is there an easy way to accomplish this? Like with an array or something?
Example of code I would like to be able to use in different timeframe:
1234567IF OnMarket AND Not OnMarket[1] THENEntryLevel = TradepriceBreakEvenLevel = EntryLevel + (PointsToKeep * pipsize)ENDIFIF abs(CountOfPosition) < abs(CountOfPosition)[1] thenSET STOP PRICE BreakEvenLevelENDIFThank you 🙂
10/22/2024 at 2:46 PM #239333In general variables have to have a unique name, and this crops up when using TF and using same variables names.
I usually post fix the timeframe value to the variable , e.g. size15m, size3m, to differentiate between them.
You would have to reference them by their names.
Alternatively you could bring variables out the timeframes and do calculation in default TF if suitable.
If you put values in array you could reference by a single name and the index value which you could have as another variable.
But this would have to be done in default timeframe area I think.
123456789101112131415161718192021222324252627282930timeframe(15mn,updateonclose)size15m = 15timeframe(3mn,updateonclose)size3m = 3timeframe(default)size1m = 10$size[0]=size1m$size[1]=size3m$size[2]=size15mif minute >= 3 and minute < 15 thenidx = 1elsif minute >= 15 and minute < 30 thenidx = 2elseidx = 0endifsize = $size[idx]graph(size15m)coloured("red",60)graph(size3m)coloured("lime",60)graph(size)BUY -1 CONTRACTS AT MARKET2 users thanked author for this post.
10/22/2024 at 6:34 PM #239343So you can see a simple example of how using arrays does not work, even though it does not give you an error.
1234567891011121314timeframe(30mn)if rsi[14](close) crosses over 50 then$rsi[max(0,lastset($rsi))+1]=lastset($rsi)+1drawarrowdown(barindex,max(0,lastset($rsi)))endiftimeframe(5mn)if rsi[14](close) crosses over 50 then$rsi[max(0,lastset($rsi))+1]=lastset($rsi)+1drawarrowup(barindex,max(0,lastset($rsi)))coloured("red")endifreturn $rsi[max(0,lastset($rsi))]10/22/2024 at 6:52 PM #239345Never tried using different elements, of the same array, in different timeframes.
Did a few tests in back-test and it appears that array elements are treated as different variables names, probably due to their index.
I don’t know if there will be any hidden surprises, especially when running a strategy.
But if solution holds up, then same variable name used in different timeframes…ish
12345678910111213141516171819202122232425timeframe(15mn,updateonclose)$size[2]=15timeframe(3mn,updateonclose)$size[1]=3timeframe(default)$size[0]=10if minute >= 3 and minute < 15 thenidx = 1elsif minute >= 15 and minute < 30 thenidx = 2elseidx = 0endifsize = $size[idx]graph($size[2])coloured("red",60)graph($size[1])coloured("lime",60)graph($size[0])coloured("yellow",60)graph(size)BUY -1 CONTRACTS AT MARKET10/24/2024 at 6:57 AM #239387Thank you for your answer!
If I understand correctly, there is no way to use the same code in different timeframes?
The code I want to use is this one in a 15 min timeframe (Entry of position)
1234567IF OnMarket AND Not OnMarket[1] THENEntryLevel = TradepriceBreakEvenLevel = EntryLevel + (PointsToKeep * pipsize)ENDIFIF abs(CountOfPosition) < abs(CountOfPosition)[1] thenSET STOP PRICE BreakEvenLevelENDIFOr is there a way to reference the code above in 3 minutes when the code and buying of position take place in a 15-minute timeframe? More specifically to Entrylevel and traderprice variables.
If not, is it possible to reference to the 1st minute of a 15 minute bar? Found
1DClose(0)yesterday, is there a similar one but for minutes? My goal, and probably the best solution would be if it would be possible to reference to the 1st minute of a 15 min bar. Is this possible?
Thank you!
-
AuthorPosts
Find exclusive trading pro-tools on