timeframe instruction inside an if block

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #147300 quote
    pableitorpableitor
    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
    robertogozzirobertogozzi
    Moderator
    Legend

    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
    pableitorpableitor
    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
    robertogozzirobertogozzi
    Moderator
    Legend

    Correct!

    Maa thanked this post
    #147340 quote
    GraHalGraHal
    Participant
    Legend

    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 GraHalGraHal
5 years, 12 months ago.

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