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
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 ..
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.