Take position after initial movement after open

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #215766 quote
    123harry
    Participant
    New

    Hi,

    I am trying to create a code that helps me with placing two orders.

    • One sellshort x1% below the opening price
    • one buy order X2% above the opening price.

    When one of these is opened, the other one should be cancelled.

    The order that is executed should have a SET TARGET %PROFIT of X3
    and a SET STOP %LOSS X4.

    Super grateful for any assistance!

    #215805 quote
    robertogozzi
    Moderator
    Master

    There you go:

    ONCE x1       = 0.20  //0.20%
    ONCE x2       = 0.20  //0.20%
    ONCE x3       = 0.50  //0.50%
    ONCE x4       = 0.25  //0.25%
    ONCE Distance = 0     //distance require by the broker, if any
    IF Not OnMarket THEN
    //
    LongEntry = open + (open * x2 / 100)
    IF close > (LongEntry + Distance*PipSize) THEN
    BUY 1 Contract at LongEntry LIMIT
    ELSIF close < (LongEntry - Distance*PipSize) THEN
    BUY 1 Contract at LongEntry STOP
    ELSE
    //BUY 1 Contract at MARKET            //enter at MARKET when the distance is not enough
    ENDIF
    //
    ShortEntry = open - (open * x1 / 100)
    IF close > (ShortEntry + Distance*PipSize) THEN
    SELLSHORT 1 Contract at ShortEntry STOP
    ELSIF close < (ShortEntry - Distance*PipSize) THEN
    SELLSHORT 1 Contract at ShortEntry LIMIT
    ELSE
    //SELLSHORT 1 Contract at MARKET      //enter at MARKET when the distance is not enough
    ENDIF
    ENDIF
    SET TARGET %PROFIT x3
    SET STOP   %LOSS   x4
    //graphonprice LongEntry  coloured("Green")
    //graphonprice ShortEntry coloured("Red")

    the pending orders that haven’t been triggered are automatically cancelled when a candle closes.

    Be warned that it’s not possible to prevent both of them from being triggered, as PRT has no control over pending orders once they are sent to the broker, until the candle closes. If both pending orders are triggered, the latter one will close the first one triggered, as there cannot be opposite trades open at the same time.

    #215821 quote
    123harry
    Participant
    New

    Many thanks Roberto!

    Seems to be working fine! When using this “live” (i.e. not back testing) I suppose I would be able to define “max position” as 1 contract which would in practice cancel the other pending order thus preventing both to be triggered. Would that be correct?

    #215848 quote
    robertogozzi
    Moderator
    Master

    I never tried it, but I don’t think so, as max positions is a directive to ProRealTime. But PRT loses control over orders as soon as thay are sent to the broker.

    You can have a try…

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

Take position after initial movement after open


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
123harry @123harry Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
2 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/07/2023
Status: Active
Attachments: No files
Logo Logo
Loading...