Help take position quickly!?

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #107316 quote
    Stefanb
    Participant
    Senior

    Have a question about how to code so that position is taken faster than the next candle (if possible).

    According to the ring in the chart.

    The price breaks above the blue MA10.

    Right there I want algo take position for buy.

    If it takes position at the next candle it is too late as the course has increased 70 points since.

     

    Is this possible?

    c.jpg c.jpg
    #107318 quote
    Vonasi
    Moderator
    Master

    Use a pending STOP order. You have to place it every bar you want it on the market as they only last one bar. x is whatever price (worse price than the current one) that you want it to be.

    Buy 1 contract at x stop

    STOP (pending)

    #107319 quote
    jebus89
    Participant
    Master

    Simple answer is both yes and no:

    No its not possible, because you would need to anticipate that move. You need to buy before that big candle happens.

    Yes it is possible, if you go down to a smaller timeframe and start trading it as its breaking out upwards.

     

    Edit: Price breaks over the MA 10 line, but it dosnt actually break above it until the candle finishes, right?

    You dont know if price will close above or below, until the candle finishes.

    #107320 quote
    robertogozzi
    Moderator
    Master

    You need to use Multi Time Frame support and launch your strategy from a very short TF, say 1 minute or even less, to be able to detect such occurrences almost as soon as they happen.

    The drawback is that your lowest TF becomes the default TF, the one on the chart, thus reducing the number of data history available for backtests.

    #107321 quote
    Vonasi
    Moderator
    Master
    if not onmarket and close < average[10](close) then
    buy 1 contract at average[10] stop
    endif

    Something like the above achieves what you are saying you want to do.

    #107325 quote
    robertogozzi
    Moderator
    Master

    Something like the above achieves what you are saying you want to do.

    How can he know when there will be a crossover and at what price?

    #107327 quote
    Vonasi
    Moderator
    Master

    You and Jebus 89 are correct Roberto – I was forgetting that we do not know what the MA[10] level will be in the next candle when we place the pending order at the end of the current candle. MTF is the only way then by checking the time frame we want the MA[10] in using DEFAULT and then for the trade to be opened in a faster time frame such as 1 second. more coffee needed!

    #107329 quote
    Stefanb
    Participant
    Senior

    The code look like this.

    Tick by tick.

    Spread=1

    Timeframe 15 min

    I am just started with the code and run a WF just for fun..

    Optimized only om 2019 data.

    The result?

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    indicator1 = Average[10](close)
    c1 = (close CROSSES OVER indicator1)
    
    IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator2 = Average[d](close)
    c2 = (close CROSSES UNDER indicator2)
    
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    // Stops and targets
    SET STOP pLOSS a pTRAILING b
    SET TARGET pPROFIT c
    
    dax.jpg dax.jpg
    #107331 quote
    Stefanb
    Participant
    Senior

    Thanks for all the answers 🙂

    #107333 quote
    Vonasi
    Moderator
    Master

    I think that you will find that the 2 pip trailing stop level will not be allowed by any broker. Check the minimum stop distances for the market you are trading.

    #107334 quote
    robertogozzi
    Moderator
    Master

    This is the MTF version, try launching it from a 1-minute or 10-second TF:

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    //
    TIMEFRAME (15 minute, default)
    // Conditions to enter long positions
    indicator1 = Average[10](close)
    c1 = (close CROSSES OVER indicator1)
    // Conditions to exit long positions
    indicator2 = Average[d](close)
    c2 = (close CROSSES UNDER indicator2)
    //
    TIMEFRAME (default)
    IF c1 AND Not OnMarket THEN
       BUY 1 CONTRACT AT MARKET
    ENDIF
    IF c2 AND LongOnMarket THEN
       SELL AT MARKET
    ENDIF
    // Stops and targets
    // --- NOT ALLOWED --->  SET STOP pLOSS a pTRAILING b
    //uncomment one of the following lines
    //SET STOP pLOSS a
    //SET STOP pTRAILING b
    #107335 quote
    Stefanb
    Participant
    Senior

    @Vonasi

    True, my mistake..

     


    @Robert

    Thanks for the code 🙂

    See that you have removed SL and TP.

    Don’t you think it’s a good idea to bring them or..

    Saw in my backtest that tickmode was over 500 resulting in an incorrect result.

    It might not work with TP and SL in that code?

    #107337 quote
    Stefanb
    Participant
    Senior

    @robert

     

    saw your comment in the code now.

    Be a little quick there 

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

Help take position quickly!?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Stefanb @stefanb Participant
Summary

This topic contains 12 replies,
has 4 voices, and was last updated by Stefanb
6 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/12/2019
Status: Active
Attachments: 2 files
Logo Logo
Loading...