how to use the same variable in different timeframes

Forums ProRealTime English forum ProOrder support how to use the same variable in different timeframes

Viewing 5 posts - 1 through 5 (of 5 total)
  • #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:

    Thank you 🙂

    #239333

    In 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.

    2 users thanked author for this post.
    #239343

    So you can see a simple example of how using arrays does not work, even though it does not give you an error.

    #239345

    Never 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

     

    #239387

    Thank 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)

    Or 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

    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!

Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login