Syntax
public enum AutoStopMode { AsPercent, AsPoint };
public virtual void ApplyAutoStops(int Bar)
public virtual void SetAutoStopMode(AutoStopMode mode)
public virtual void InstallTimeBasedExit(int Bars)
public virtual void InstallStopLoss(double StopLevel)
public virtual void InstallTrailingStop(double Trigger, double StopLevel)
public virtual void InstallReverseBreakEvenStop(double LossLevel)
public virtual void InstallBreakEvenStop(double Trigger)
public virtual void InstallProfitTarget(double TargetLevel)
Parameter Description
| mode |
Select AsPercent (by default) or AsPoint |
| Bar |
Bar number to apply AutoStops
|
Parameters like "Bars", "Trigger" etc. are typical and should be used like you do with Wealth-Lab's built-in exits. See the documentation page for more information:
WealthScript Techniques - AutoStops.
Description
Automated stops aka AutoStops had always existed in legacy Wealth-Lab versions, but were purposefully removed from Version 5 due to possible peaking when incorrectly mixing them with manual stops. These methods can help you program various types of automated exits in your trading systems and reduce the size of your code.
Example
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components; // <-- AutoStops here
namespace WealthLab.Strategies
{
public class AutoStopsDemo : WealthScript
{
protected override void Execute()
{
// Create an instance of PositionHelper (class containing AutoStops),
// passing a WealthScript object as "this"
PositionHelper a = new PositionHelper(this);
// Select AutoStop mode: AsPercent or AsPoint
PositionHelper.AutoStopMode AsPercent = Community.Components.
PositionHelper.AutoStopMode.AsPercent;
//sample calls to auto stop methods
a.SetAutoStopMode(AsPercent); // choose AutoStopMode
a.InstallTimeBasedExit(30);
a.InstallStopLoss(5);
a.InstallProfitTarget(10);
a.InstallBreakEvenStop(5);
a.InstallReverseBreakEvenStop(3);
a.InstallTrailingStop(6, (100 - 70));
for(int Bar = 20; Bar < Bars.Count; Bar++)
{
// Apply auto stops
a.ApplyAutoStops(Bar);
if (!IsLastPositionActive)
{
BuyAtMarket(Bar + 1);
}
}
}
}
}