SaveTrades

Modified on 2018/06/26 17:38 by Eugene — Categorized as: Community Components

Syntax

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

public void SaveTrades( string path, bool open, bool closed, bool savePositionType = false )

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


This method supersedes 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 ); } } }