A chronologically dependant condition?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #187402 quote
    julopax
    Participant
    New

    Hello everyone! I’m basically a noobie when it comes to coding so I’m expecting that my problem is “easily” solvable for some coders here.

    My problem is that I want to make a condition for my strategy that is chronologically dependant. Meaning this indicator needs to be at a value at FIRST and then cross a line thereafter and then after it crossed the line the indicator do not need to be at that value later since it already was there. I know my english is severly incomprehensible but I’m trying my best. Sincerely//julopax

    #187408 quote
    JS
    Participant
    Senior

    You can use the statement “ONCE”
    Your code is executed at the end of each bar, but “once” is only executed the first time hence “once”

    Example from the documentation:

    ONCE myfirstlowest = lowest[10](low)
     
    IF(low < myfirstlowest OR low < recentlow) THEN
       recentlow = low
    ELSE
       recentlow = recentlow
    ENDIF
     
    RETURN recentlow 
    #187411 quote
    julopax
    Participant
    New

    Well… I did read the documentation on the ONCE instruction and it turns out it’s not my case at all. The ONCE instruction is only going to run a command ONCE. And in my case I need my condition to follow a chronological order meaning it can repeat indefinitely but only in a specific order

    #187413 quote
    robertogozzi
    Moderator
    Master

    Can you post an example?

    #187426 quote
    JS
    Participant
    Senior

    You’re welcome, noobie?

    #187488 quote
    julopax
    Participant
    New

    I’m going to post an example since it’s too hard to explain in plain text.

    Let’s say my strategy is based off the Adaptive Moving Average indicator and the Stochastic indicator exclusively.

    The first screenshot is what it looks like in a 30min chart (1k candles)

    My code (example, used probuilder):

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated

    // Conditions to enter long positions
    indicator1 = AdaptiveAverage[20,2,3000](close)
    indicator2 = AdaptiveAverage[70,2,3000](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = Stochastic[100,50](close)
    c2 = (indicator3 < 20) IF c1 AND c2 THEN BUY 1 CONTRACT AT MARKET ENDIF // Conditions to exit long positions indicator4 = AdaptiveAverage[20,2,3000](close) indicator5 = AdaptiveAverage[70,2,3000](close) c3 = (indicator4 CROSSES UNDER indicator5) IF c3 THEN SELL AT MARKET ENDIF // Conditions to enter short positions indicator6 = AdaptiveAverage[20,2,3000](close) indicator7 = AdaptiveAverage[70,2,3000](close) c4 = (indicator6 CROSSES UNDER indicator7) indicator8 = Stochastic[100,50](close) c5 = (indicator8 > 80)
    My problem lies in c2 and c5 where I only need it the stochastic K% line to be under 20 when the “faster, black” adaptive MA crosses over the “slower, red” one. The K% line doesn’t need to be under 20 if the K% line keeps being over the D% line, meaning if the K% line crosses under the D% line before the K% line hits the value 80 only then can the system halt buying new contracts. If not then the system can solely rely on the adaptive MA indicators as long as the K% line keeps being over the D% line

    IF c4 AND c5 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF

    // Conditions to exit short positions
    indicator9 = AdaptiveAverage[20,2,3000](close)
    indicator10 = AdaptiveAverage[70,2,3000](close)
    c6 = (indicator9 CROSSES OVER indicator10)

    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF

    Skarmbild-2.png Skarmbild-2.png
    #187602 quote
    robertogozzi
    Moderator
    Master

    Your code is a mess, can you tide it up and post it as plain text?

    #187604 quote
    PeterSt
    Participant
    Master

    Just in case it is difficult for julopax with the blue button lacking :

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = AdaptiveAverage[20,2,3000](close)
    indicator2 = AdaptiveAverage[70,2,3000](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = Stochastic[100,50](close)
    c2 = (indicator3 < 20) 
    
    IF c1 AND c2 THEN 
      BUY 1 CONTRACT AT MARKET 
    ENDIF // Conditions to exit long positions 
    
    indicator4 = AdaptiveAverage[20,2,3000](close) 
    indicator5 = AdaptiveAverage[70,2,3000](close) 
    c3 = (indicator4 CROSSES UNDER indicator5) 
    
    IF c3 THEN 
      SELL AT MARKET 
    ENDIF // Conditions to enter short positions 
    
    indicator6 = AdaptiveAverage[20,2,3000](close) 
    indicator7 = AdaptiveAverage[70,2,3000](close) 
    c4 = (indicator6 CROSSES UNDER indicator7) 
    indicator8 = Stochastic[100,50](close) 
    c5 = (indicator8 > 80) 
    
    // My problem lies in c2 and c5 where I only need it the stochastic K% line 
    // to be under 20 when the “faster, black” adaptive MA crosses over the “slower, 
    // red” one. The K% line doesn’t need to be under 20 if the K% line keeps being
    // over the D% line, meaning if the K% line crosses under the D% line before 
    // the K% line hits the value 80 only then can the system halt buying new 
    // contracts. If not then the system can solely rely on the adaptive MA 
    // indicators as long as the K% line keeps being over the D% line
    
    IF c4 AND c5 THEN
      SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator9 = AdaptiveAverage[20,2,3000](close)
    indicator10 = AdaptiveAverage[70,2,3000](close)
    c6 = (indicator9 CROSSES OVER indicator10)
    
    IF c6 THEN
      EXITSHORT AT MARKET
    ENDIF
    #187812 quote
    robertogozzi
    Moderator
    Master

    It’s not clear enough.
    I’ll ask you one question at a time.
    Let’s talk only about LONG trades (Short is just the reverse). Question #1: what are the conditiuons to enter a LONG trade?

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

A chronologically dependant condition?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
julopax @julopax Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by robertogozzi
4 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/02/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...