Wealth-Lab Wiki

API ChartStyles Community Components Community Indicators IndexDefinitions Knowledge Base Misc Optimizers Pending Deletion PosSizers Providers Standard Indicators TASC Traders Tips TASCIndicators Tutorial Videos Visualizers
RSS

Navigation


Quick Search
»
Advanced Search »


Syntax

public static void SaveTrades(this WealthScript obj, string path, bool open, bool closed)

public void SaveTrades( string path, bool open, bool closed )

Parameter Description

pathPath to the resulting CSV file
openSave open trades
closedSave closed trades

Description

A simple procedure that dumps closed and/or open position data to a CSV (comma-separated) file.

The format is:

SymbolName,EntryDate,EntryPrice,EntrySignal,ExitDate,ExitPrice,ExitSignal,Tag

  • The Position.Tag property allows to store any object with a Position. It can be left empty, or be used, for example, to hold the value of an indicator of choice at EntryDate.
  • It's possible to introduce custom output formats by modifying the method body and re-compiling the assembly on your own.

This method supersede SaveClosedTrades.

Example

This is an example code that illustrates how to call the procedure inside your Strategy:

Example using C# extension methods:


using System;
using System.Text;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { for(int bar = 50; bar < Bars.Count; bar++) { if (IsLastPositionActive) { if ( CrossUnder( bar, RSI.Series( Close, 14 ), 70 ) ) SellAtMarket( bar+1, LastPosition, "exit" ); } else { if ( CrossOver( bar, RSI.Series( Close, 14 ), 50 ) ) if( BuyAtMarket( bar+1, "RSI" ) != null ) // Store indicator data in the position's Tag property LastPosition.Tag = Bars.FormatValue( RSI.Series( Close, 14 )[bar] ); } } // Specify destination file string path = @"C:\temp\SaveTrades.csv"; // Call SaveTrades, passing the destination file to save both the open and closed trades this.SaveTrades( path, true, true ); } } }

Legacy syntax example:


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

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { // Create an instance of the Utility class and pass WealthScript as "this" Utility u = new Utility( this ); for(int bar = 50; bar < Bars.Count; bar++) { if (IsLastPositionActive) { if ( CrossUnder( bar, RSI.Series( Close, 14 ), 70 ) ) SellAtMarket( bar+1, LastPosition, "exit" ); } else { if ( CrossOver( bar, RSI.Series( Close, 14 ), 50 ) ) if( BuyAtMarket( bar+1, "RSI" ) != null ) // Store indicator data in the position's Tag property LastPosition.Tag = Bars.FormatValue( RSI.Series( Close, 14 )[bar] ); } } // Specify destination file string path = @"C:\temp\SaveTrades.csv"; // Call SaveTrades, passing the destination file to save both the open and closed trades u.SaveTrades( path, true, true ); } } }

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.

Used under license from FMR Corp. Copyright 2008 FMR Corp. All rights reserved.


ScrewTurn Wiki. Some of the icons created by FamFamFam.