- ago

is there any way to show the trades for both of the symbols on the same screen? for example adding the relevant trades to the 2nd symbol on a separate screenpanel.
Thank you

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using WealthLab.ChartWPF; using System.Drawing; using System.Collections.Generic; using System.Linq; namespace WealthScript16 { public class PairsTrading : UserStrategyBase {       string _stock1 = "SPY", _stock2 = "QQQ";       BarHistory stock1, stock2;       int MAPeriod = 30;       double upThreshold = 1.5, downThreshold = -1.5;       TimeSeries close1, close2, ActualRatio, ActualRatioSMA, Delta, DeltaSMA, DeltaDifference, DeltaNorm;       public override void Initialize(BarHistory bars) {          stock1 = GetHistory(bars, _stock1);          stock2 = GetHistory(bars, _stock2);          close1 = stock1.Close;          close2 = stock2.Close;          ActualRatio = close1 / close2;          ActualRatioSMA = SMA.Series(ActualRatio, MAPeriod);          Delta = ActualRatio - ActualRatioSMA;          DeltaSMA = SMA.Series(Delta, MAPeriod);          DeltaDifference = Delta - DeltaSMA;          DeltaNorm = DeltaDifference / StdDev.Series(Delta, MAPeriod);          PlotTimeSeries(ActualRatio, "Ratio " + _stock1 + "/" + _stock2, "RatioPane", WLColor.Navy);          PlotTimeSeries(ActualRatioSMA, "Ratio's SMA", "RatioPane", WLColor.Blue);          PlotBarHistory(stock1, "QQQ");          PlotBarHistory(stock2, "QQQ", WLColor.Red, true);          StartIndex = MAPeriod;       } public override void Execute(BarHistory bars, int idx) {          if (GetPositions().Where(p => p.IsOpen == true).Count() == 0)          {             if (DeltaNorm[idx] > upThreshold)             {                PlaceTrade(stock1, TransactionType.Short, OrderType.MarketClose, 0, "Short" + stock1);                PlaceTrade(stock2, TransactionType.Buy, OrderType.MarketClose, 0, "Buy" + stock2);             }             else                if (DeltaNorm[idx] < downThreshold)             {                PlaceTrade(stock2, TransactionType.Short, OrderType.MarketClose, 0, "Short" + stock2);                PlaceTrade(stock1, TransactionType.Buy, OrderType.MarketClose, 0, "Buy" + stock1);             }          }     else          {             PlaceTrade(stock1, TransactionType.Cover, OrderType.MarketClose, 0, "Cover" + stock1);             PlaceTrade(stock2, TransactionType.Sell, OrderType.MarketClose, 0, "Sell" + stock2);                          PlaceTrade(stock2, TransactionType.Cover, OrderType.MarketClose, 0, "Cover" + stock2);             PlaceTrade(stock1, TransactionType.Sell, OrderType.MarketClose, 0, "Sell" + stock1);          } } } }
0
276
Solved
4 Replies

Reply

Bookmark

Sort
Cone8
 ( 24.80% )
- ago
#1
You could probably get most of the way there looping through GetPositionsAllSymbols() and plotting with DrawBarAnnotation, but you could run into problems with synchronization of the indexes. Even so, you wouldn't get the rollover trade information popups.

I think we'll have to turn this into a feature request.
0
- ago
#2
Thank you Cone. I'll support a feature request

Meanwhile - is there a way to select a symbol to show on the Chart (with all signals) whilst running the strategy? .. and change for another symbol to be shown when certain conditions are met?
0
Cone8
 ( 24.80% )
- ago
#3
Select what symbol? what symbol is the strategy running on? when would you change it? I really don't know what you mean.
0
Glitch8
 ( 9.89% )
- ago
#4
There’s no automated way to control which symbol appears on the chart on a strategy window. You can change symbols by entering a symbol manually or double clicking a position in the positions list, or by using the Signals Navigator on the chart.
1
Best Answer

Reply

Bookmark

Sort