Other cancels other orders or connect selling to buying condition

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

    Hi all,

    I’m new to this forum and quite new to quantitative trading, I have however some programming experience in SAS. Luckily i could already find a lot of answers to my question here, but a crucial one remains unaswered:

    I’m trying to create a multiple leg order, more specifically the ‘one cancels the other order’ (https://www.prorealtime.com/nl/help/ordertypes). If I did my research correctly, there doesn’t exist a build-in function for this order type, and hence, I’m trying to create it myself.

    In my stragey I want to trade from pivot point, to resistance 1, to resistance 2 and vice versa. My attached example shows that the strategy indeed enters at the pivot point and sells at resistance 1. After this the strategy enters based on C2, but sells the following bar as the selling condition for the move from the pivot point to resistance 1 is still true. I’m therefore searching for a way to:

    • Create a ‘one cancels the other order’ or;
    • Attach a selling definition to an entry definition. E.g ‘only sell when entered based on condition 1’

    What would the best way to achieve this?

    Many thanks in advance for the answers.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    // The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.
    DEFPARAM FLATBEFORE = 090000
    // Cancel all pending orders and close all positions at the "FLATAFTER" time
    DEFPARAM FLATAFTER = 211800
    
    // Prevents the system from creating new orders to enter the market or increase position size before the specified time
    noEntryBeforeTime = 090000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 170000
    timeEnterAfter = time < noEntryAfterTime
    
    // Prevents the system from placing new orders on specified days of the week
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Conditions to enter long positions//
    
    //Pivots//
    Pivot = (DHigh(1) + DLow(1) + DClose(1))/3
    Sup1=2*((DHigh(1) + DLow(1) + DClose(1))/3) - DHigh(1)
    Res1 = 2*((DHigh(1) + DLow(1) + DClose(1))/3) - DLow(1)
    Res2= Pivot + (Res1-sup1)
    //Sup2= Pivot - (Res1-sup1)//
    
    //Conditions for enter long//
    c1= Average[1](close) CROSSES OVER pivot
    c2= Average[1](close) CROSSES OVER Res1
    
    IF (c1) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1 SHARES AT MARKET 
    ENDIF
    
    IF (c2) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1 SHARES AT MARKET
    ENDIF
    
    // Conditions to exit long positions//
    el1 = high>Res1-3
    IF longonmarket and el1 THEN 
    Sell 1 shares at market
    ENDIF
    
    el2 = high>Res2-3
    IF longonmarket and el2 THEN
    Sell 1 shares at market
    ENDIF
    
    SET STOP pLOSS 8
    Example.png Example.png
    #51070 quote
    Nicolas
    Keymaster
    Master

    In my opinion, the best way would be to calculate a takeprofit according to the order that just been launched at market:

    Calculate a takeprofit at next level (Resistance1), when the buy order triggered because of the pivot point breach:

    IF not longonmarket and (c1) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
     BUY 1 SHARES AT MARKET 
     set target profit (Res1-Close)
    ENDIF

    and so on for each level ..

    #51160 quote
    Harald159
    Participant
    New

    That seems like a simple and elegant solution which i didn’t think about. I will give it a go and post my findings. Thanks for the answer.

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

Other cancels other orders or connect selling to buying condition


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Harald159 @harald159 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Harald159
8 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/29/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...