Timeframe condition not working

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #107626 quote
    AbzAbz
    Participant
    Veteran
    // Definition of code parameters
    DEFPARAM Preloadbars = 10000
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    //DEFPARAM FLATBEFORE = 090000
    //DEFPARAM FLATAFTER = 220000
    
    // indicators
    timeframe(default)
    rs = RSI[7](close)
    ema50 = ExponentialAverage[50](close)
    ema200 = ExponentialAverage[200](close)
    Positions = 1
    
    //Exit Long
    if longonmarket and rs crosses under 75 then
    sell at market
    endif
    
    //Exit Short
    if shortonmarket and rs crosses over 25 then
    exitshort at market
    endif
    //
    
    // Conditions to enter Long positions
    TIMEFRAME (1 hour, updateonclose)
    a = ema50 > ema200
    timeframe(default)
    b = rs crosses over 25
    x1 = ema50 > ema200
    
    IF a and b and x1 THEN
    buy Positions shares AT MARKET
    ENDIF
    
    // Conditions to enter Short positions
    TIMEFRAME (1 hour, updateonclose)
    c = ema50 < ema200
    timeframe(default)
    d = rs crosses under 75
    x2 = ema50 < ema200
    //
    IF c and d and x2 THEN
    sellshort Positions shares AT MARKET
    ENDIF

    anyone have any idea why not the timeframe 1hour condition not working? from the attached screen it is clearly that “c = ema50 < ema200” is not valid and still it is taking a short trade however it is valid on the 15 min timeframe that is default and it looks for me that it is following the default time frame and igonring the 1 hour timeframe.

    1hema.png 1hema.png
    #107628 quote
    AbzAbz
    Participant
    Veteran

    trade attached

    trade.png trade.png
    #107639 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    You’re are absolutely right!

    It ignores your 1-hour TF because no indicator is defined within THAT time frame. You only set conditions based on the indicators written in your default TF.

    Move lines 9-11 to just after line 26.

    Indicators only work in the TF they are declared, though you can read them from anywhere else.

    #107643 quote
    AbzAbz
    Participant
    Veteran

    i only want the ema50 and ema200 to be checked in 1 hour timeframe so it shoud be like this then?

     

    // Definition of code parameters
    DEFPARAM Preloadbars = 10000
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    //DEFPARAM FLATBEFORE = 090000
    //DEFPARAM FLATAFTER = 220000
    
    // indicators
    timeframe(default)
    rs = RSI[7](close)
    Positions = 1
    
    //Exit Long
    if longonmarket and rs crosses under 75 then
    sell at market
    endif
    
    //Exit Short
    if shortonmarket and rs crosses over 25 then
    exitshort at market
    endif
    //
    
    // Conditions to enter Long positions
    TIMEFRAME (1 hour, updateonclose)
    a = ema50 > ema200
    ema50 = ExponentialAverage[50](close)
    ema200 = ExponentialAverage[200](close)
    timeframe(default)
    b = rs crosses over 25
    x1 = ema50 > ema200
    
    IF a and b and x1 THEN
    buy Positions shares AT MARKET
    ENDIF
    
    // Conditions to enter Short positions
    TIMEFRAME (1 hour, updateonclose)
    c = ema50 < ema200
    ema50 = ExponentialAverage[50](close)
    ema200 = ExponentialAverage[200](close)
    timeframe(default)
    d = rs crosses under 75
    x2 = ema50 < ema200
    //
    IF c and d and x2 THEN
    sellshort Positions shares AT MARKET
    ENDIF
    
    
    
    //SET STOP ploss 75
    //SET TARGET pPROFIT 25
    
    #107644 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Line 25 needs to be moved below line 27, before line 28.

    Lines 39-40 can be removed, they are a duplicate of lines  26-27.

    Abz thanked this post
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 condition not working


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Abz @abbas_sadiq Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by robertogozzirobertogozzi
7 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/15/2019
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...