Log in to see Cloud of Tags

Wealth-Lab Wiki

PlotSymbolTrades

RSS

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(); } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.


ScrewTurn Wiki. Some of the icons created by FamFamFam.