diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/07 Trailing Stop Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/07 Trailing Stop Orders.php new file mode 100644 index 0000000000..b77757cc92 --- /dev/null +++ b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/07 Trailing Stop Orders.php @@ -0,0 +1,4 @@ + +$includeIntro = true; +include(DOCS_RESOURCES."/reality-modeling/trade-fills/trailing-stop-orders.php"); +?> \ No newline at end of file diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/07 Market on Open Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/08 Market on Open Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/07 Market on Open Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/08 Market on Open Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/08 Market on Close Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/10 Market on Close Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/08 Market on Close Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/10 Market on Close Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/09 Combo Market Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/11 Combo Market Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/09 Combo Market Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/11 Combo Market Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/10 Combo Limit Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/12 Combo Limit Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/10 Combo Limit Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/12 Combo Limit Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/11 Combo Leg Limit Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/13 Combo Leg Limit Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/11 Combo Leg Limit Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/02 Future Model/13 Combo Leg Limit Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/07 Trailing Stop Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/07 Trailing Stop Orders.php new file mode 100644 index 0000000000..b77757cc92 --- /dev/null +++ b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/07 Trailing Stop Orders.php @@ -0,0 +1,4 @@ + +$includeIntro = true; +include(DOCS_RESOURCES."/reality-modeling/trade-fills/trailing-stop-orders.php"); +?> \ No newline at end of file diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/07 Market on Open Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/09 Market on Open Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/07 Market on Open Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/09 Market on Open Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/08 Market on Close Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/10 Market on Close Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/08 Market on Close Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/10 Market on Close Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/09 Combo Market Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/11 Combo Market Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/09 Combo Market Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/11 Combo Market Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/10 Combo Limit Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/12 Combo Limit Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/10 Combo Limit Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/12 Combo Limit Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/11 Combo Leg Limit Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/13 Combo Leg Limit Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/11 Combo Leg Limit Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/03 Future Option Model/13 Combo Leg Limit Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/07 Trailing Stop Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/07 Trailing Stop Orders.php new file mode 100644 index 0000000000..b77757cc92 --- /dev/null +++ b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/07 Trailing Stop Orders.php @@ -0,0 +1,4 @@ + +$includeIntro = true; +include(DOCS_RESOURCES."/reality-modeling/trade-fills/trailing-stop-orders.php"); +?> \ No newline at end of file diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/07 Market on Open Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/09 Market on Open Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/07 Market on Open Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/09 Market on Open Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/08 Market on Close Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/10 Market on Close Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/08 Market on Close Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/10 Market on Close Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/09 Combo Market Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/11 Combo Market Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/09 Combo Market Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/11 Combo Market Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/10 Combo Limit Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/12 Combo Limit Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/10 Combo Limit Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/12 Combo Limit Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/11 Combo Leg Limit Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/13 Combo Leg Limit Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/11 Combo Leg Limit Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/04 Immediate Model/13 Combo Leg Limit Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/07 Trailing Stop Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/07 Trailing Stop Orders.php new file mode 100644 index 0000000000..b77757cc92 --- /dev/null +++ b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/07 Trailing Stop Orders.php @@ -0,0 +1,4 @@ + +$includeIntro = true; +include(DOCS_RESOURCES."/reality-modeling/trade-fills/trailing-stop-orders.php"); +?> \ No newline at end of file diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/07 Market on Open Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/09 Market on Open Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/07 Market on Open Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/09 Market on Open Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/08 Market on Close Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/10 Market on Close Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/08 Market on Close Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/10 Market on Close Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/09 Combo Market Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/11 Combo Market Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/09 Combo Market Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/11 Combo Market Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/10 Combo Limit Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/12 Combo Limit Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/10 Combo Limit Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/12 Combo Limit Orders.php diff --git a/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/11 Combo Leg Limit Orders.php b/03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/13 Combo Leg Limit Orders.php similarity index 100% rename from 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/11 Combo Leg Limit Orders.php rename to 03 Writing Algorithms/24 Reality Modeling/02 Trade Fills/02 Supported Models/05 Latest Price Model/13 Combo Leg Limit Orders.php diff --git a/Resources/reality-modeling/trade-fills/trailing-stop-orders.php b/Resources/reality-modeling/trade-fills/trailing-stop-orders.php new file mode 100644 index 0000000000..f3af692544 --- /dev/null +++ b/Resources/reality-modeling/trade-fills/trailing-stop-orders.php @@ -0,0 +1,221 @@ + if ($includeIntro) { ?>
The following table describes the fill logic of trailing stop orders for each data format and order direction. Once the stop condition is met, the model fills the orders and sets the fill price.
} ?> + +Data Format | +TickType |
+ Order Direction + | Stop Condition | +Fill Price | +
---|---|---|---|---|
Tick |
+ Quote |
+ Buy | +quote price > stop price | +max(stop price, quote price + slippage) | +
Tick |
+ Quote |
+ Sell | +quote price < stop price | +min(stop price, quote price - slippage) | +
Tick |
+ Trade |
+ Buy | +trade price > stop price | +max(stop price, last trade price + slippage) | +
Tick |
+ Trade |
+ Sell | +trade price < stop price | +min(stop price, last trade price - slippage) | +
QuoteBar |
+ Buy | +ask high price > stop price | +max(stop price, ask close price + slippage) | +|
QuoteBar |
+ Sell | +bid low price < stop price | +min(stop price, bid close price - slippage) | +|
TradeBar |
+ Buy | +high price > stop price | +max(stop price, close price + slippage) | +|
TradeBar |
+ Sell | +low price < stop price | +min(stop price, close price - slippage) | +
While the stop condition is not met, the model updates the stop price under certain conditions. The following table shows the update condition and stop price value for the nominal trailing amount.
} ?> + +Data Format | +TickType |
+ Order Direction | +Update Condition | +Stop Price | +
---|---|---|---|---|
Tick |
+ Quote |
+ Buy | +stop price - quote price <= trailing amount | +quote price + trailing amount | +
Tick |
+ Quote |
+ Sell | +quote price - stop price <= trailing amount | +quote price - trailing amount | +
Tick |
+ Trade |
+ Buy | +stop price - trade price <= trailing amount | +trade price + trailing amount | +
Tick |
+ Trade |
+ Sell | +trade price - stop price <= trailing amount | +trade price - trailing amount | +
QuoteBar |
+ Buy | +stop price - ask low price <= trailing amount | +ask low price + trailing amount | +|
QuoteBar |
+ Sell | +bid high price - stop price <= trailing amount | +bid high price - trailing amount | +|
TradeBar |
+ Buy | +stop price - low price <= trailing amount | +low price + trailing amount | +|
TradeBar |
+ Sell | +high price - stop price <= trailing amount | +high price - trailing amount | +
The following table shows the update condition and stop price value for the percentage trailing amount.
} ?> + +Data Format | +TickType |
+ Order Direction | +Update Condition | +Stop Price | +
---|---|---|---|---|
Tick |
+ Quote |
+ Buy | +stop price - quote price <= quote price * trailing amount | +quote price * (1 + trailing amount) | +
Tick |
+ Quote |
+ Sell | +quote price - stop price <= quote price * trailing amount | +quote price * (1 - trailing amount) | +
Tick |
+ Trade |
+ Buy | +stop price - trade price <= trade price * trailing amount | +trade price * (1 + trailing amount) | +
Tick |
+ Trade |
+ Sell | +trade price - stop price <= trade price * trailing amount | +trade price * (1 - trailing amount) | +
QuoteBar |
+ Buy | +stop price - ask low price <= ask low price * trailing amount | +ask low price * (1 + trailing amount) | +|
QuoteBar |
+ Sell | +bid high price - stop price <= bid high price * trailing amount | +bid high price * (1 - trailing amount) | +|
TradeBar |
+ Buy | +stop price - low price <= stop price * trailing amount | +low price * (1 + trailing amount) | +|
TradeBar |
+ Sell | +high price - stop price <= high price * trailing amount | +high price * (1 - trailing amount) | +
The model only fills trailing stop orders when the exchange is open.
+ +$orderType = "trailing stop"; +include(DOCS_RESOURCES."/reality-modeling/trade-fills/fill-with-stale-data.php"); +?> \ No newline at end of file