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 @@ + \ 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 @@ + \ 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 @@ + \ 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 @@ + \ 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 @@ +

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 FormatTickTypeOrder Direction + Stop ConditionFill Price
TickQuoteBuyquote price > stop pricemax(stop price, quote price + slippage)
TickQuoteSellquote price < stop pricemin(stop price, quote price - slippage)
TickTradeBuytrade price > stop pricemax(stop price, last trade price + slippage)
TickTradeSelltrade price < stop pricemin(stop price, last trade price - slippage)
QuoteBar
Buyask high price > stop pricemax(stop price, ask close price + slippage)
QuoteBar
Sellbid low price < stop pricemin(stop price, bid close price - slippage)
TradeBar
Buyhigh price > stop pricemax(stop price, close price + slippage)
TradeBar
Selllow price < stop pricemin(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 FormatTickTypeOrder DirectionUpdate ConditionStop Price
TickQuoteBuystop price - quote price <= trailing amountquote price + trailing amount
TickQuoteSellquote price - stop price <= trailing amountquote price - trailing amount
TickTradeBuystop price - trade price <= trailing amounttrade price + trailing amount
TickTradeSelltrade price - stop price <= trailing amounttrade price - trailing amount
QuoteBar
Buystop price - ask low price <= trailing amountask low price + trailing amount
QuoteBar
Sellbid high price - stop price <= trailing amountbid high price - trailing amount
TradeBar
Buystop price - low price <= trailing amountlow price + trailing amount
TradeBar
Sellhigh price - stop price <= trailing amounthigh price - trailing amount
+ +

The following table shows the update condition and stop price value for the percentage trailing amount.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Data FormatTickTypeOrder DirectionUpdate ConditionStop Price
TickQuoteBuystop price - quote price <= quote price * trailing amountquote price * (1 + trailing amount)
TickQuoteSellquote price - stop price <= quote price * trailing amountquote price * (1 - trailing amount)
TickTradeBuystop price - trade price <= trade price * trailing amounttrade price * (1 + trailing amount)
TickTradeSelltrade price - stop price <= trade price * trailing amounttrade price * (1 - trailing amount)
QuoteBar
Buystop price - ask low price <= ask low price * trailing amountask low price * (1 + trailing amount)
QuoteBar
Sellbid high price - stop price <= bid high price * trailing amountbid high price * (1 - trailing amount)
TradeBar
Buystop price - low price <= stop price * trailing amountlow price * (1 + trailing amount)
TradeBar
Sellhigh price - stop price <= high price * trailing amounthigh price * (1 - trailing amount)
+ +

The model only fills trailing stop orders when the exchange is open.

+ \ No newline at end of file