- ago
Problem:
Application TDA Thinkorswim has an order template which allows to submit the entire 3 orders linked together. I was not able to code this template on Wealth-Lab.

Tried using the Auto-profit target tools. But, They did not work in submitting the 2 orders or 3 orders linked together. Strategy needs to be able to submit the entire full order in one submission, Buy Limit, Sell Limit, Sell Limit. This feature is available on TOS and Web TOS. The TDA API might be lacking this order template, lacking this important bracket order feature. There is a chance The API should be able to process this order template - bracket order. If the API does not support this template, what needs to be done from the TDA API team.

Template: Trigger With Bracket
Order[1] = [Buy Limit[1] + Sell Limit[1] + Sell Limit[2] ]




0
335
Solved
6 Replies

Reply

Bookmark

Sort
Cone8
 ( 26.65% )
- ago
#1
You can program a bracket order following any fill using AssignAutoStopTargetPrices, which serves precisely the same purpose. The only difference is that Wealth-Lab controls the order flow after the entry fill.

See AssignAutoStopTargetPrices in the QuickRef for a detailed example.
1
Best Answer
- ago
#2
Thanks Cone. However, I am still Facing difficulty implementing this order template. I have not been able to code it out. The reference example below is not working. Please Forward this problem question to Glitch

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript13 {    public class SameBarAuto : UserStrategyBase    {       TimeSeries _band;       public override void Initialize(BarHistory bars)       {          double pct = 0.95;          _band = SMA.Series(bars.Close, 5) * pct;          PlotTimeSeriesLine(_band, "band", "Price");       }       public override void Execute(BarHistory bars, int idx)       {          if (HasOpenPosition(bars, PositionType.Long))          {             //sell at open next bar             PlaceTrade(bars, TransactionType.Sell, OrderType.Market);          }          else          {             //buy at market if the low goes below the band, but closes above it             if (bars.Low.CrossesUnder(_band[idx], idx) && bars.Close[idx] > _band[idx])                PlaceTrade(bars, TransactionType.Buy, OrderType.Market);          }       }       //same bar exits: 1% profit or loss from execution price       public override void AssignAutoStopTargetPrices(Transaction t, double basisPrice, double executionPrice)       {          t.AutoProfitTargetPrice = executionPrice * 1.03;          t.AutoStopLossPrice = executionPrice * 0.97;       }    } }
0
Cone8
 ( 26.65% )
- ago
#3
Most often, we try to show "minimal" QuickRef examples to highlight a function or keyword. This example creates stop and limit orders on the entry bar only and then sells at the open of the next bar (assuming the stop and limit didn't exit on the entry bar). This is documented in the example's comments.

If you want to keep sending stop and limit orders after the entry bar, then you need to include it in your exit logic just like any other Strategy. Does that make sense?
0
- ago
#4
@Glitch
Important question for you. It is possible to control the sequence of orders on WL sent to an API. Currently WL sends Buy Limits, then if activated, it will send the sell Limits.

TDA API + TOS Platform support Full Bracket Orders. It includes Buy Limit + Sell Limit + Sell Limit

Need a code solution to send Bracket Order. How to Send Full Bracket Order that includes the 3 Orders to TDA API ?





CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript33 {    public class MyStrategy : UserStrategyBase    {       public MyStrategy() : base()       {       }       public override void Initialize(BarHistory bars)       {          StartIndex = 0;       }       public override void Execute(BarHistory bars, int idx)       {          int index = idx;          Position foundPosition0 = FindOpenPosition(0);          //   bool condition0;          if (foundPosition0==null){                       val = bars.AveragePriceOHLC[idx];             _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, val, "Buy At Limit (Bid)");             _transaction.AutoProfitTargetPrice = bars.AveragePriceOHLC[idx]+0.4;             _transaction.AutoStopLossPrice = bars.AveragePriceOHLC[idx]-0.5;             ClosePosition(foundPosition0, OrderType.Limit, val+0.1, "Close Pos Sell At Limit (Bid)");             _transaction = PlaceTrade(bars, TransactionType.Sell, OrderType.Limit, bars.AveragePriceOHLC[idx] +0.04, "Place Sell At Limit (Bid)");             _transaction = PlaceTrade(bars, TransactionType.Sell, OrderType.StopLimit, bars.AveragePriceOHLC[idx] - 0.6, "Place Sell Stop Limit (Bid)");          }       }          public override void NewWFOInterval(BarHistory bars)   { }       private Transaction _transaction;       private double val;    } }


0
Glitch8
 ( 8.38% )
- ago
#5
Currently WL does not support bracket orders with 3 orders, only 2. You'd need to submit a #FeatureRequest for this.
1
- ago
#6
Perhaps you can submit a three-way bracket order on the broker's trading platform. And simply substitute a two-way bracket order on the WL side. That might be close enough for a WL simulation.

And honestly, I've only used a three-way bracket order twice in my life, and that was 20 years ago. I doubt this would be a popular feature request.

I have thought about having a "standing" (GTC) trailing-stop on the broker's side and then adding stop, limit, or bracket orders over the top of that, but I don't "think" my broker supports this configuration.
1

Reply

Bookmark

Sort