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 »


EnterAtPrice

RSS

Syntax


public static Position EnterAtPrice(this WealthScript obj, Bars bars, int bar, double price, PositionType pType, string signalName)

public Position EnterAtPrice(Bars bars, int bar, double price, PositionType pType, string signalName)

Parameter Description

BarsBars object
barBar number on which the position is being created
priceEntry price
pTypePositionType.Long or PositionType.Short
signalNameSignal name

Description

This function, created by Robert Sucher, allows to create a new long or short Position at a specified price. It can be helpful in some strategies for backtesting entries made at specific price levels. A key component in Wealth-Lab support for importing real (historical) trades.

Note: The function can't be used to enter trades outside of the bar's range.

Example

Below is a demo Strategy that shows how to use the function.

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 AtPriceDemo : WealthScript { protected override void Execute() { // initialize your average series however you like DataSeries avgSer = 0.5 * Open + 0.5 * Close; /* In the trading loop here's the buy signal that uses your peeking data. It won't create an Alert because they're peeking results. Not a tradeable script! */ for(int bar = 1; bar < Bars.Count; bar++) { if (IsLastPositionActive) { if( true ) // some condition to exit at the average price this month this.ExitAtPrice(Bars, bar, LastPosition, avgSer[bar], "Out"); } else { if( true ) // some condition to buy at the average price this month this.EnterAtPrice(Bars, bar, avgSer[bar], PositionType.Long, "In"); } } } } }

Legacy syntax example:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components; // Support for enter/exit at price here
/*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/

namespace WealthLab.Strategies { public class AtPriceDemo : WealthScript { protected override void Execute() { // Create an instance of the PositionHelper class, passing WealthScript as "this" PositionHelper ph = new PositionHelper( this ); // initialize your average series however you like DataSeries avgSer = 0.5 * Open + 0.5 * Close; /* In the trading loop here's the buy signal that uses your peeking data. It won't create an Alert because they're peeking results. Not a tradeable script! */ for(int bar = 1; bar < Bars.Count; bar++) { if (IsLastPositionActive) { if( true ) // some condition to exit at the average price this month ph.ExitAtPrice(Bars, bar, LastPosition, avgSer[bar], "Out"); } else { if( true ) // some condition to buy at the average price this month ph.EnterAtPrice(Bars, bar, avgSer[bar], PositionType.Long, "In"); } } } } }

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.