PlotSymbolTrades

Modified on 2013/05/11 13:59 by Eugene — Categorized as: Community Components

Syntax


public static void PlotSymbolTrades(this WealthScript obj, Bars symbol, ChartPane pane)

public void PlotSymbolTrades(Bars symbol, ChartPane pane)

Parameter Description

symbolThe Bars object of an external symbol
paneChartPane to plot the trades on

Description

Visualizes trades made on external symbols. Helpful for pair trading strategies and in general, for any strategy that makes trades on an external symbol.

Example

Image

Here is an example illustrating how to use the method in your Strategy code. Make sure you have "KO" in one of your DataSets and run the example on another symbol:

Example using C# extension methods:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class PlotSymbolTradesDemo : WealthScript { protected override void Execute() { for(int bar = 40; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; SetContext( "KO", true ); if( p.PositionType == PositionType.Long ) SellAtStop( bar+1, p, Lowest.Series( Low,20 )[bar] ); else CoverAtStop( bar+1, p, Highest.Series( High,20 )[bar] ); RestoreContext(); } else { SetContext( "KO", true ); Position p = BuyAtStop( bar+1, Highest.Series( High,40 )[bar] ); if( p == null ) ShortAtStop( bar+1, Lowest.Series( Low,40 )[bar] ); RestoreContext(); } } const string SymbolPair = "KO"; if( Bars.Symbol != SymbolPair ) { ChartPane pane = CreatePane( 100, false, true ); this.PlotSymbolTrades( GetExternalSymbol( SymbolPair, true ), pane ); HideVolume(); } } } }

Legacy syntax example:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components; /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/

namespace WealthLab.Strategies { public class PlotSymbolTradesDemo : WealthScript { protected override void Execute() { Utility u = new Utility( this ); for(int bar = 40; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; SetContext( "KO", true ); if( p.PositionType == PositionType.Long ) SellAtStop( bar+1, p, Lowest.Series( Low,20 )[bar] ); else CoverAtStop( bar+1, p, Highest.Series( High,20 )[bar] ); RestoreContext(); } else { SetContext( "KO", true ); Position p = BuyAtStop( bar+1, Highest.Series( High,40 )[bar] ); if( p == null ) ShortAtStop( bar+1, Lowest.Series( Low,40 )[bar] ); RestoreContext(); } } const string SymbolPair = "KO"; if( Bars.Symbol != SymbolPair ) { ChartPane pane = CreatePane( 100, false, true ); u.PlotSymbolTrades( GetExternalSymbol( SymbolPair, true ), pane ); HideVolume(); } } } }