Help with setting exit at end of day if profit otherwise sell after 5 days

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15813 quote
    jolln
    Participant
    New

    Hi, i wanna create a really simple exit strategy for stocks and apply it to some other simple strategies i am trying out with stocks.

    What i want to do is create a exit strategy that exits the position if the position is in profit 5 minutes before market closing. It should keep doing this for 4 days and on the 5th day sell either way (despite being in loss) 5 minute before market closes.

    Here is a simple strategy for entering stochastics (2,3) on 30 and exit at 70 (and short the opposite). Now i want to add in the above exit strategy. What code do i write?

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = Stochastic[14,2](close)
    c1 = (indicator1 CROSSES OVER 30)
    
    IF c1 THEN
    BUY 50 SHARES AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator2 = Stochastic[14,2](close)
    c2 = (indicator2 CROSSES UNDER 70)
    
    IF c2 THEN
    SELL  AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator3 = Stochastic[14,2](close)
    c3 = (indicator3 CROSSES OVER 70)
    
    IF c3 THEN
    SELLSHORT 50 SHARES AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator4 = Stochastic[14,2](close)
    c4 = (indicator4 CROSSES OVER 30)
    
    IF c4 THEN
    EXITSHORT  AT MARKET
    ENDIF
    

    I appreciate any help and tips. I am quite new to prorealtime so i am very open to critique and learning.

    Regards,

    Jolln

    #31844 quote
    fredd81
    Participant
    Senior

    Hi

    Did you sort this ?

    I also want to exit the firt day in profit in the end of the day if possible

    Now my algo exit the first bar in profit instantly with this code

    if longonmarket and (barindex=tradeindex+5 or close > tradeprice) then
    sell at market

    #32401 quote
    Nicolas
    Keymaster
    Master

    Because codes are only read once at Close of the bar, and if you are using this code on a daily timeframe, it is not possible to make it do things before the end of the day.  Until we get the multitimeframe support, I do not see any accurate solution I’m sorry!

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

Help with setting exit at end of day if profit otherwise sell after 5 days


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jolln @jolln Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by Nicolas
8 years, 10 months ago.

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