missing code for closing order @ next bar open

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #78080 quote
    Marc
    Participant
    Average

    Hi together,

    I’d like to close a position at the open of the next bar. As i found out nextbaropen can not be used to close positions. Am I right?

    Perhaps somebody can help me with the snippet.

    DEFPARAM CumulateOrders = FALSE
    
    A = ABS(Dclose(1))-ABS(Dopen(1)) //inner Range
    B = ABS(dhigh(1))-ABS(Dlow(1)) //outer Range
    
    C = 0.25 //Faktor
    n = 1//Lotsize
    
    // Conditions to enter long positions
    IF NOT LongOnMarket AND CLOSE > OPEN AND (A/B) < C THEN
    BUY 1 SHARES AT HIGH STOP
    ENDIF
    
    // Conditions to exit long and short positions
    IF LongOnMarket THEN
    SELL n SHARES AT NextBarOpen
    ENDIF
    
    // Conditions to enter short positions
    IF NOT LongOnMarket AND CLOSE < OPEN AND (A/B) < C THEN
    SELLSHORT n SHARES AT LOW STOP 
    ENDIF
    
    // Conditions to exit short long positions
    IF ShortOnMarket THEN
    EXITSHORT AT NextBarOpen
    ENDIF
    
    #78081 quote
    Vonasi
    Moderator
    Master

    All you need is:

    if onmarket then
    sell at market
    exitshort at market
    endif
    Marc thanked this post
    #78088 quote
    Marc
    Participant
    Average

    Here is the amended code…

    It’s ony working for long positions. Short didn’t work well.

    A = Close[1]-Open[1] //inner Range
    B = High[1]-Low[1] //outer Range
    C = y //Faktor
    n = 1//Lotsize
    
    // Conditions to enter long positions
    IF NOT OnMarket AND (A/B) < C THEN
    BUY n SHARES AT MARKET
    ENDIF
    
    // Conditions to exit long and short positions
    IF OnMarket THEN
    SELL AT Market
    ENDIF

    For C =  0,43 worked best

    BACKTEST-DJ30.jpg BACKTEST-DJ30.jpg
    #78099 quote
    Vonasi
    Moderator
    Master

    When you say ‘Short didn’t work well’ you mean the strategy not the code.

    If you look at the Wall Street chart then only a fool would try to short it! The trend is your friend! That is your first edge!

    #78100 quote
    GraHal
    Participant
    Master

    // Conditions to exit long and short positions

    IF OnMarket THEN 
    SELL AT Market
    ENDIF

    Enter short keyword is SellShort

    Exit short keyword is ExiShort

    Do you need above to get your code working because in the Marc version code you have no SellShort??  (Vonasi version code does have SellShort / ExitShort).

    #78102 quote
    Vonasi
    Moderator
    Master

    I think GraHal that he means that he has removed the short side of the strategy because it does not work on the DJI. Which is not surprising if you look at the DJI chart – low on the left and high on the right and virtually a straight line in between!

    GraHal thanked this post
    #78104 quote
    Marc
    Participant
    Average

    Hi GraHal,

     

    I forgot to delete or amend the phrase after //.

    This strategy currently works only for long positions and doesn’t allow short positions…

    GraHal thanked this post
    #78105 quote
    Marc
    Participant
    Average

    This system shall refer a litle bit to Andrea Unger’s pattern strategy. The biggest difference is that the rules for this strategy here enters market orders and not orders at high or low…

    Perhaps I will add a MA for trend direction

    #78148 quote
    Marc
    Participant
    Average

    Hi together,

    I have a suggestion regarding this system…perhaps somebody can help me amending this code.

    I thought about following thing.
    Each day I have a reference candle for example at 8 o’clock.
    I enter a long trade (either at market or as High Stop order) when close of a following candle is above open of reference candle and range of High and Low is bigger compared with Open and Close (bigger than variable factor)
    I enter a short trade (either at market or as Low Stop order) when close of a following candle is below open of reference candle and range of High and Low is bigger compared with Open and Close (bigger than variable factor)

    Exit shall be at open of next bar Open or Close of current bar after order was placed.

     

    Can anybody help me?

     

    Thank you in advance

    Marc

    #78371 quote
    Nicolas
    Keymaster
    Master

    Hi Marc, I think that it could be a good idea to learn to code a bit. What you request is easy to add to your strategy.

    Learn to program for ProRealTime

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

missing code for closing order @ next bar open


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Marc @mast83 Participant
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by Nicolas
7 years, 6 months ago.

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