- 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
91
Solved
3 Answers

Reply

Bookmark

Sort
Cone7
- 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
Cone7
- 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

Reply

Bookmark

Sort