timeframe instruction inside an if block

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #147300 quote
    pableitor
    Participant
    Master

     

    I’d like to use the timeframe(n) instruction inside an if  block, like the code below but it throws an error:

    htf=1
    if htf then
    timeframe(15mn)
    x = ExponentialAverage[9](close)
    endif

    Is there any workaround ?

    Thx

    #147306 quote
    robertogozzi
    Moderator
    Master

    It’s not allowed.

    TIMEFRAME must be used outside IF…ENDIF as well as outside iterations and the number and type of units (minute, hours,….) CANNOT be a variable.

    #147323 quote
    pableitor
    Participant
    Master

    OK ,  there’s an easy workaround:

    htf = 1 //flag
    timeframe(15mn)
    y = ExponentialAverage[9](close)
    timeframe(default)
    if htf then
    x = y
    endif
    Maa thanked this post
    #147332 quote
    robertogozzi
    Moderator
    Master

    Correct!

    Maa thanked this post
    #147340 quote
    GraHal
    Participant
    Master

    Link to above logged as 254 here …

    Snippet Link Library

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

timeframe instruction inside an if block


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
pableitor @pableitor Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by GraHal
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/13/2020
Status: Active
Attachments: No files
Logo Logo
Loading...