Log in to see Cloud of Tags

Wealth-Lab Wiki

Stop/Limit Orders

RSS

Syntax

public static Position BuyAtStopLimit(this WealthScript ws, int bar, double price)
public static Position BuyAtStopLimit(this WealthScript ws, int bar, double price, string signalName)
public static Position ShortAtStopLimit(this WealthScript ws, int bar, double price)
public static Position ShortAtStopLimit(this WealthScript ws, int bar, double price, string signalName)
public static bool SellAtStopLimit(this WealthScript ws, int bar, Position p, double price)
public static bool SellAtStopLimit(this WealthScript ws, int bar, Position p, double price, string signalName)
public static bool CoverAtStopLimit(this WealthScript ws, int bar, Position p, double price)
public static bool CoverAtStopLimit(this WealthScript ws, int bar, Position p, double price, string signalName)

public Position BuyAtStopLimit(int bar, double price) public Position BuyAtStopLimit(int bar, double price, string signalName) public Position ShortAtStopLimit(int bar, double price) public Position ShortAtStopLimit(int bar, double price, string signalName) public bool SellAtStopLimit(int bar, Position p, double price) public bool SellAtStopLimit(int bar, Position p, double price, string signalName) public bool CoverAtStopLimit(int bar, Position p, double price) public bool CoverAtStopLimit(int bar, Position p, double price, string signalName)

Parameter Description

barBar
priceLimit price
signalName(optional) Entry/exit signal name

Description

This is a set of four overloaded functions that implement Stop/Limit order types. Original WL4 code created by Dion Kurczek.

Warning: all the methods can be used for backtesting only. They are N/A for real trading and will trigger an index out of bounds exception when attempted to use for Alert generation.

Example

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 MyStrategy : WealthScript { protected override void Execute() { for(int bar = GetTradingLoopStartBar(40); bar < Bars.Count; bar++) { if( bar < Bars.Count-1 ) // for backtesting only { if (IsLastPositionActive) { if( !this.SellAtStopLimit( bar+1, LastPosition, Lowest.Series(Low,40)[bar] ) ) this.CoverAtStopLimit( bar+1, LastPosition, Highest.Series(High,40)[bar] ); } else { if( this.BuyAtStopLimit( bar+1, Highest.Series(High,40)[bar] ) == null ) this.ShortAtStopLimit( bar+1, Lowest.Series(Low,40)[bar] ); } } } } } }

Legacy syntax example:

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

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { PositionHelper ps = new PositionHelper( this ); // Pass WealthScript for(int bar = GetTradingLoopStartBar(40); bar < Bars.Count; bar++) { if( bar < Bars.Count-1 ) // for backtesting only { if (IsLastPositionActive) { if( !ps.SellAtStopLimit( bar+1, LastPosition, Lowest.Series(Low,40)[bar] ) ) ps.CoverAtStopLimit( bar+1, LastPosition, Highest.Series(High,40)[bar] ); } else { if( ps.BuyAtStopLimit( bar+1, Highest.Series(High,40)[bar] ) == null ) ps.ShortAtStopLimit( bar+1, Lowest.Series(Low,40)[bar] ); } } } } } }

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.