Only one trade/trend

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #159504 quote
    LASSETASSELASSETASSE
    Participant
    Junior

    How can i limit the code to only do one trade per trend? Lets say im following supertrend and after take profit or loss i want to stay flat till next direction on supertrend.

    BR. Lasse

    #159506 quote
    NicolasNicolas
    Keymaster
    Legend

    To take an order only when the Supertrend turn from green to red or red to green, use that code snippet:

    st=supertrend[3,10]
    if close crosses over st then 
     buy at market 
    endif 
    
    if close crosses under st then 
     sellshort at market 
    endif
    LASSETASSE thanked this post
    #159509 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I moved the topic from ProBuilder to ProOrder support, as it deals with a strategy.

    Please make sure you have carefully read the rules highlighted below (in yellow) in order to correctly use this forum. Thank you šŸ™‚

    LASSETASSE thanked this post
    #159515 quote
    LASSETASSELASSETASSE
    Participant
    Junior

    Hi Nicolas

    I attach the code for better understanding. For an example i want to the sell 25-jan 11:00 then take profit 13:37. Then i want the system to stay flat til 25-jan 22:10 when the upptrend starts and after stopploss 26-jan 02:25 stay flat again til next downtrend.
    I only want one trade per trend (trend =30min supertrend 3:10)

    Open itf in 1minute 5k units and Wall street cash.

    Many Thanks.

    #159518 quote
    NicolasNicolas
    Keymaster
    Legend

    This is what the code I prodived is doing šŸ™‚

    Please copy/paste your code and by using the ‘insert prt code’ button. Better than attaching the itf file, thank you.

    #159519 quote
    LASSETASSELASSETASSE
    Participant
    Junior

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    timeframe(30 minutes,updateonclose)
    // Conditions to enter long positions
    indicator1 = Average[5](close)
    indicator2 = SuperTrend[3,10]
    c1 = (indicator1 > indicator2)
    
    timeframe(1 minutes,updateonclose)
    indicator3 = Average[1](close)
    indicator4 = Average[5](close)
    c2 = (indicator3 crosses over indicator4)
    
    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    timeframe(30 minutes,updateonclose)
    // Conditions to exit long positions
    indicator5 = Average[5](close)
    indicator6 = SuperTrend[3,10]
    c3 = (indicator5 CROSSES UNDER indicator6)
    
    IF c3 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    timeframe(30 minutes,updateonclose)
    indicator7 = Average[5](close)
    indicator8 = SuperTrend[3,10]
    c4 = (indicator7 < indicator8)
    
    timeframe(1 minutes,updateonclose)
    indicator9 = Average[1](close)
    indicator10 = Average[5](close)
    c5 = (indicator9 crosses under indicator10)
    
    
    IF c4 AND c5 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    timeframe(30 minutes,updateonclose)
    
    indicator11 = Average[5](close)
    indicator12 = SuperTrend[3,10]
    c6 = (indicator11 > indicator12)
    
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    // Stops and targets
    SET STOP pLOSS 100
    SET TARGET pPROFIT 100
    
    #159521 quote
    VonasiVonasi
    Moderator
    Master

    You need to set a flag every time you send an entry order to market and not reset that flag until the trend changes direction. The flag not being set is a condition for allowing entry.

    LASSETASSE thanked this post
    #159524 quote
    LASSETASSELASSETASSE
    Participant
    Junior

     

    sounds right, but i don’t know how to do it. flag?

    #159536 quote
    VonasiVonasi
    Moderator
    Master

    flag = just a variable that you set to 1 or 0. If it is 1 then you have already opened a trade. If it is zero then no trade has been opened since the last change in supertrend direction. I don’t have time to amend your code for you right now.

    #159537 quote
    LASSETASSELASSETASSE
    Participant
    Junior

     

    OK please help me when you have time.
    Thanks.

    #159541 quote
    VonasiVonasi
    Moderator
    Master

    Something like this (not tested and coded after a couple of glasses of wine!):

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    timeframe(30 minutes,updateonclose)
    // Conditions to enter long positions
    indicator1 = Average[5](close)
    indicator2 = SuperTrend[3,10]
    c1 = (indicator1 > indicator2)
    
    newtrend = (SuperTrend[3,10] > SuperTrend[3,10](close[1]) and SuperTrend[3,10](close[1]) < SuperTrend[3,10](close[2])) or (SuperTrend[3,10] < SuperTrend[3,10](close[1]) and SuperTrend[3,10](close[1]) > SuperTrend[3,10](close[2])) 
    
    if newtrend then 
    flag = 0
    endif
    
    timeframe(1 minutes,updateonclose)
    indicator3 = Average[1](close)
    indicator4 = Average[5](close)
    c2 = (indicator3 crosses over indicator4)
    
    IF c1 AND c2 and not flag THEN
    BUY 1 CONTRACT AT MARKET
    flag = 1
    ENDIF
    
    timeframe(30 minutes,updateonclose)
    // Conditions to exit long positions
    indicator5 = Average[5](close)
    indicator6 = SuperTrend[3,10]
    c3 = (indicator5 CROSSES UNDER indicator6)
    
    IF c3 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    timeframe(30 minutes,updateonclose)
    indicator7 = Average[5](close)
    indicator8 = SuperTrend[3,10]
    c4 = (indicator7 < indicator8)
     
    timeframe(1 minutes,updateonclose)
    indicator9 = Average[1](close)
    indicator10 = Average[5](close)
    c5 = (indicator9 crosses under indicator10)
    
    
    IF c4 AND c5 and not flag THEN
    SELLSHORT 1 CONTRACT AT MARKET
    flag = 1 
    ENDIF
    
    // Conditions to exit short positions
    timeframe(30 minutes,updateonclose)
    
    indicator11 = Average[5](close)
    indicator12 = SuperTrend[3,10]
    c6 = (indicator11 > indicator12)
    
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    // Stops and targets
    SET STOP pLOSS 100
    SET TARGET pPROFIT 100
    LASSETASSE thanked this post
    #159591 quote
    LASSETASSELASSETASSE
    Participant
    Junior

     

    Something is wrong in line 11, im not able to fix it šŸ™‚

    #159652 quote
    VonasiVonasi
    Moderator
    Master

    Try this:

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    timeframe(30 minutes,updateonclose)
    // Conditions to enter long positions
    indicator1 = Average[5](close)
    indicator2 = SuperTrend[3,10]
    c1 = (indicator1 > indicator2)
    
    newtrend = (indicator2 > indicator2[1] and indicator2[1] < indicator2[2]) or (indicator2 < indicator2[1] and indicator2[1] > indicator2[2])
    
    if newtrend then
    flag = 0
    endif
    
    timeframe(default)
    indicator3 = Average[1](close)
    indicator4 = Average[5](close)
    c2 = (indicator3 crosses over indicator4)
    
    if flag = 0 then 
    myflag = 0
    endif
    
    IF c1 AND c2 and not myflag THEN
    BUY 1 CONTRACT AT MARKET
    myflag = 1
    ENDIF
    
    timeframe(30 minutes,updateonclose)
    // Conditions to exit long positions
    indicator5 = Average[5](close)
    indicator6 = SuperTrend[3,10]
    c3 = (indicator5 CROSSES UNDER indicator6)
    
    IF c3 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    timeframe(30 minutes,updateonclose)
    indicator7 = Average[5](close)
    indicator8 = SuperTrend[3,10]
    c4 = (indicator7 < indicator8)
     
    timeframe(default)
    indicator9 = Average[1](close)
    indicator10 = Average[5](close)
    c5 = (indicator9 crosses under indicator10)
    
    
    IF c4 AND c5 and not myflag THEN
    SELLSHORT 1 CONTRACT AT MARKET
    myflag = 1
    ENDIF
    
    // Conditions to exit short positions
    timeframe(30 minutes,updateonclose)
    
    indicator11 = Average[5](close)
    indicator12 = SuperTrend[3,10]
    c6 = (indicator11 > indicator12)
    
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    // Stops and targets
    SET STOP pLOSS 100
    SET TARGET pPROFIT 100
    
    LASSETASSE thanked this post
    #160539 quote
    LASSETASSELASSETASSE
    Participant
    Junior

    Hi Robertogozzi

     

    Can you help me fix a flag or trade limiter i the code, i only want one trade /supertrend timeframe ( 30min)

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    timeframe(30 minutes,updateonclose)
    // Conditions to enter long positions
    indicator1 = Average[5](close)
    indicator2 = SuperTrend[3,10]
    c1 = (indicator1 > indicator2)
    
    timeframe(1 minutes,updateonclose)
    indicator3 = Average[1](close)
    indicator4 = Average[5](close)
    c2 = (indicator3 crosses over indicator4)
    
    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    timeframe(30 minutes,updateonclose)
    // Conditions to exit long positions
    indicator5 = Average[5](close)
    indicator6 = SuperTrend[3,10]
    c3 = (indicator5 CROSSES UNDER indicator6)
    
    IF c3 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    timeframe(30 minutes,updateonclose)
    indicator7 = Average[5](close)
    indicator8 = SuperTrend[3,10]
    c4 = (indicator7 < indicator8)
    
    timeframe(1 minutes,updateonclose)
    indicator9 = Average[1](close)
    indicator10 = Average[5](close)
    c5 = (indicator9 crosses under indicator10)
    
    
    IF c4 AND c5 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    timeframe(30 minutes,updateonclose)
    
    indicator11 = Average[5](close)
    indicator12 = SuperTrend[3,10]
    c6 = (indicator11 > indicator12)
    
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    // Stops and targets
    SET STOP pLOSS 200
    SET TARGET pPROFIT 100
    
    #160549 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Try this (not tested):

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    timeframe(30 minutes,updateonclose)
    BarIndex30 = BarIndex
    // Conditions to enter long positions
    indicator1 = Average[5](close)
    indicator2 = SuperTrend[3,10]
    c1 = (indicator1 > indicator2)
     
    timeframe(1 minutes,updateonclose)
    ONCE MyBar = 0
    indicator3 = Average[1](close)
    indicator4 = Average[5](close)
    c2 = (indicator3 crosses over indicator4)
    
    IF c1 AND c2 AND (MyBar <> BarIndex30) AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    MyBar = BarIndex30
    ENDIF
    
    timeframe(30 minutes,updateonclose)
    // Conditions to exit long positions
    indicator5 = Average[5](close)
    indicator6 = SuperTrend[3,10]
    c3 = (indicator5 CROSSES UNDER indicator6)
     
    IF c3 THEN
    SELL AT MARKET
    ENDIF
     
    // Conditions to enter short positions
    timeframe(30 minutes,updateonclose)
    indicator7 = Average[5](close)
    indicator8 = SuperTrend[3,10]
    c4 = (indicator7 < indicator8)
     
    timeframe(1 minutes,updateonclose)
    indicator9 = Average[1](close)
    indicator10 = Average[5](close)
    c5 = (indicator9 crosses under indicator10)
     
     
    IF c4 AND c5 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
     
    // Conditions to exit short positions
    timeframe(30 minutes,updateonclose)
     
    indicator11 = Average[5](close)
    indicator12 = SuperTrend[3,10]
    c6 = (indicator11 > indicator12)
     
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    // Stops and targets
    SET STOP pLOSS 200
    SET TARGET pPROFIT 100
Viewing 15 posts - 1 through 15 (of 15 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

Only one trade/trend


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
LASSETASSE @lassetasse Participant
Summary

This topic contains 14 replies,
has 4 voices, and was last updated by robertogozzirobertogozzi
5 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/26/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...