Silly Q exit x points after entry not working

Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #7876 quote
    Cosmic1
    Participant
    Senior
    indicator1 = close
    
    c1 = (indicator1>25)
    
    indicator2 = close
    
    c2 = (indicator2<25)
    
    IF SHORTONMARKET AND C1 OR C2 THEN
    EXITSHORT AT MARKET
    ENDIF
    #7877 quote
    Nicolas
    Keymaster
    Master

    Hmm i’m not sure what you want to do with this code. You are trying to close a short trade if the price is > to 25 and also if price is < 25 , so obviously your conditions are always met.

    What is the exact question please?

    #7885 quote
    Cosmic1
    Participant
    Senior

    Sorry Nicolas, still learning.

    I want to close the trade if it either hits 25 points profit or 25 points loss from the entry price.

    #7886 quote
    Nicolas
    Keymaster
    Master

    Ok, don’t be sorry, there is no stupid question 🙂

    So, just add these instructions to your code:

    SET STOP PLOSS 25
    SET TARGET PPROFIT 25

    You can have a look at all the Probacktest/ProOrder instruction here in the prorealtime documentation: http://www.prorealcode.com/documentation/category/probacktest/ , if you need more assistance to program your trading strategy, or just ask!

    #7888 quote
    Cosmic1
    Participant
    Senior

    Thanks but I want to exit long positions at different targets and stops to short ones. What I’m after would come in handy for many strategy’s I’m testing.

    #7889 quote
    Nicolas
    Keymaster
    Master

    Ok so test if you are in long or short conditions and then set your different values like this:

    if longonmarket then  
     SET STOP PLOSS 25 
     SET TARGET PPROFIT 25
    endif
    
    if shortonmarket then 
     SET STOP PLOSS 35
     SET TARGET PPROFIT 42
    endif
    #7896 quote
    Cosmic1
    Participant
    Senior

    Aha so simple when you know how 🙂 Will test soon.

    #7899 quote
    Cosmic1
    Participant
    Senior

    Still no dice?

    IF Time = 173000 then
    
    cashhigh = highest[180](high)
    cashlow = lowest[180](low)
    
    ENDIF
    
    //Enter Longs
    IF Time > 173000 AND Time <= 193000 THEN
    BUY 1 PERPOINT AT cashhigh-5 STOP
    ENDIF
    
    //Enter Shorts
    IF Time > 173000 AND Time <= 193000 THEN
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    ENDIF
    
    if longonmarket then
    SET STOP PLOSS 40
    SET TARGET PPROFIT 25
    endif
    
    if shortonmarket then
    SET STOP PLOSS 30
    SET TARGET PPROFIT 25
    endif
    #7902 quote
    Nicolas
    Keymaster
    Master

    I’m sorry? On what instrument do you test this automated strategy?

    #7903 quote
    Cosmic1
    Participant
    Senior

    The major indices and it only takes one trade per day, sorry didn’t include that bit. Basically everything works the way I want it apart from the fact I can’t adjust the long and short, stop and limit separately.

     

    I could of course separate the code in to long and short positions but would be nice to have it in one code.

    #7910 quote
    Nicolas
    Keymaster
    Master

    So you want to only let the current order go to profit or loss and avoid another one to initiate?

    #7914 quote
    Cosmic1
    Participant
    Senior

    Sorry I have not been clear, been too long at the screen.

    This is working the way I want it, just need to achieve separate stops and limits for long and short positions.

     

    DEFPARAM CUMULATEORDERS = FALSE
    DEFPARAM FLATAFTER = 205500
    
    
    // One Trade Per Day
    Once nbTrades = 0
    Once tradesPerDay = 1
    
    If Day<>Day[1] then
    nbTrades = 0
    Else
    If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
    nbTrades = nbTrades + 1
    Endif
    Endif
    
    If nbTrades < tradesPerDay then
    
    //End One Trade Per Day Code
    
    cashhigh = highest[180](high)
    cashlow = lowest[180](low)
    
    ENDIF
    
    //Enter Longs
    IF Time > 173000 AND Time <= 193000 THEN
    BUY 1 PERPOINT AT cashhigh-5 STOP
    ENDIF
    
    //Enter Shorts
    IF Time > 173000 AND Time <= 193000 THEN
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    
    ENDIF
    
    set stop ploss 25
    set target pprofit 50
    
    //ENDIF below is to finish off the one trades per day code at the start.
    ENDIF
    
    #8042 quote
    Cosmic1
    Participant
    Senior

    Been playing around with this today but still no joy, any help appreciated 🙂

    #8050 quote
    Adolfo
    Participant
    Senior
    DEFPARAM CUMULATEORDERS = FALSE
    DEFPARAM FLATAFTER = 205500
    
    
    // One Trade Per Day
    Once nbTrades = 0
    Once tradesPerDay = 1
    
    If Day<>Day[1] then
    nbTrades = 0
    Else
    If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
    nbTrades = nbTrades + 1
    Endif
    Endif
    
    If nbTrades < tradesPerDay then
    
    //End One Trade Per Day Code
    
    cashhigh = highest[180](high)
    cashlow = lowest[180](low)
    
    ENDIF
    
    //Enter Longs
    IF Time > 173000 AND Time <= 193000 THEN
    BUY 1 PERPOINT AT cashhigh-5 STOP
    ENDIF
    
    //Enter Shorts
    IF Time > 173000 AND Time <= 193000 THEN
    SELLSHORT 1 PERPOINT at cashlow+5 STOP
    
    ENDIF
    
    if longonmarket then
    set stop ploss 40
    set target pprofit 25
    endif
    
    if shortonmarket then
    set stop ploss 30
    set target profit 25
    endif
    
    //ENDIF below is to finish off the one trades per day code at the start.
    ENDIF
    #8057 quote
    Cosmic1
    Participant
    Senior

    Hi,

    Thanks for the reply but it doesn’t work unfortunately. Did it work for you? The results never come to any stop or limit on any trade when I test it.

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

Silly Q exit x points after entry not working


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Cosmic1 @cosmic1 Participant
Summary

This topic contains 25 replies,
has 3 voices, and was last updated by Cosmic1
9 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/24/2016
Status: Active
Attachments: No files
Logo Logo
Loading...