Here you can search through the pages of this Namespace, their attachments and the files uploaded to the system.
Note: the results will only display the items you have permissions to read.
[...] 1.0);
paramLookbackForStepPattern = CreateParameter("Lookback", 3, 1, 20, 1);
}
bool isInsideBody( int bar, double price ) {
return price bar ,Close bar ) && price >= Math.Min(Open bar ,Close bar );
}
bool Upstep( int bar, int lookback ) {
bool result = false;
bool way1 = (Open bar > Close bar & Open bar+1 bar+1 ) && isInsideBody(bar, Open bar+1 ) && Close bar+1 > Open bar [...]
[...] LineStyle.Solid, 2 );
for(int bar = obj.GetTradingLoopStartBar(1); bar bar bar > avgMAB bar )
obj.BuyAtMarket(bar+1,"Strong Trend"); if( adx bar > adxMult * adxLow bar && obj.CrossOver(bar, adx, crit) & c bar > avgMAB bar )
obj.BuyAtMarket(bar+1,"Trend"); if( obj.CrossOver(bar, adx, adxTrend) && adx bar bar bar )
obj.ShortAtMarket(bar+1,"Strong Dntrend"); if( adx bar > adxMult [...]
[...] DateTime(2003, 4, 23), false);
for(int bar = 0; bar bar = yba stBar ;
// Based calculations from raw data and then synchronize
DataSeries ybaSMA = Synchronize( SMA.Series(yba, 40) );
DataSeries xauROC = Synchronize( ROC.Series(xau, 1) );
DataSeries crbROC = Synchronize( ROC.Series(crb, 1) );
DataSeries ejROC = Synchronize( ROC.Series(ej, 2) );
ej = Synchronize( ej );
yba = Synchronize( yba );
DataSeries sec1BOL = SecBol( Close, per );
DataSeries [...]
[...] );
EMA ema = EMA.Series( Close, 60, EMACalculation.Modern );
for(int bar = period; bar bar = Math.Sign( Close bar - Close bar-1 ) * Close bar ;
}
DataSeries VP = EMA.Series( R, period, EMACalculation.Modern );
for(int bar = period; bar bar != 0 )
PZO bar = 100 * VP bar / TV bar ;
}
ChartPane pzoPane = CreatePa
[...] );
EMA ema = EMA.Series( Close, 60, EMACalculation.Modern );
for(int bar = period; bar bar = Math.Sign( Close bar - Close bar-1 ) * Volume bar ;
}
DataSeries VP = EMA.Series( R, period, EMACalculation.Modern );
for(int bar = period; bar bar != 0 )
VZO bar = 100 * VP bar / TV bar ;
}
ChartPane vzoPane = CreatePa
Bars, Loops, and Bar + 1
Original article by Robert Sucher in the legacy Knowledge Base here .
Wealth-Lab Developer has features such as order slippage and variable commissions to bring trading simulation as close to reality as possible. Likewise, your task as a trading system designer is to express your system in C# code that validly recreates security orders as they would have been and will be executed in real life. Bar Definition
A bar is any interval of time that has an open, high, low, and closing [...]
[...] atrPeriod);
var trendFilter = SMA.Series(Close, maPeriod);
for(int bar = GetTradingLoopStartBar(Math.Max(atrPeriod,maPeriod)); bar bar > High bar - 1 && Low bar bar - 1 && Close bar bar - 1 ;
bool keyRevBull = High bar > High bar - 1 && Low bar bar - 1 && Close bar > High bar - 1 ; //island reversal
bool islRevBear = Low bar > [...]
[...] from recent peaks or troughs. System rules Once a bullish divergence is detected, enter long next bar at open if MFO is below its centerline Exit long next bar at open when MFO crosses above the centerline Trades from the short side are deliberately not taken as their performance seems poor. Figure 1. Bullish divergence between the MFO and price formed in June 2015 triggered a long trade in KO (Coca Cola). After updating the TASCIndicators library to v2015.09 or later, the MoneyFlowOscillator indicator can be found under the TASC [...]
[...] to create a Pullback in an Uptrend entry. For instance, in an established uptrend, wait for a three bar pullback and
enter at stop $0.10 above prior bar high. However, the Rule Wizard doesn't seem to have "Buy at Stop" rule desired. Solution:
You can get pretty close by starting with these rules: BuyAtLimit (High)
- Moving Average is trending up (Moving Average group)
- Price decreases a consecutive number of bars (Price (or Volume) group) ..and add an exit (if you only want a screen, see Techniques > Creating a Screener in the WealthScript [...]
[...] );
DrawHorzLine(adxPane,thresholdForTrend,Color.Blue,LineStyle.Dashed,1); for(int bar = GetTradingLoopStartBar(period); bar bar-1 == Highest.Series( High, high ) bar-1 )
& ( srsi bar-1 == Highest.Series( srsi, high ) bar-1 )
& TurnDown( bar, High ) & TurnDown( bar, srsi ) )
{
peak = true; peakBar = bar-1;
}
}
if( peak == true )
{
if( ( High bar != Highest.Series( High, high ) bar )
& ( srsi bar == [...]
[...] low );
for(int bar = GetTradingLoopStartBar(130); bar bar-1 == Highest.Series( High, high ) bar-1 )
& ( WM bar-1 == Highest.Series( WM, high ) bar-1 )
& TurnDown( bar, High ) & TurnDown( bar, WM ) )
{
peak = true; peakBar = bar-1;
}
}
if( peak == true )
{
if( ( High bar != Highest.Series( High, high ) bar )
& ( WM bar == Highest.Series(
[...] Line divided by its period
private double LRLineROCdivPeriod(int bar, DataSeries ds, int period)
{
int n = bar - period + 1;
double y1 = LinearRegLine(ds, n, bar, bar);
double y2 = LinearRegLine(ds, n, bar, n);
double per = period;
return 100 * ( y1 / y2 - 1d ) / per;
}
protected override void Execute()
{
HideVolume();
int buyMonth = 9; int sellMonth = 6;
// Access external data
Bars dxy = GetExternalSymbol("DXY", [...]
Syntax
public static int GetTime(this WealthScript obj, int bar)
public static int GetTime(this Bars bars, int bar) // For use when using a non-synchronized Bars object public int GetTime(int bar)
public int GetTime(Bars bars, int bar) // For use when using a non-synchronized Bars object
Parameter Description bar Bar number bars Bars object GetTime returns 24-hour time as an integer. Example: 4pm = 1600
Syntax [...]
[...] PricePane, daily.Close, Color.Black, LineStyle.Dashed, 1 ); for(int bar = 20; bar bar .Hour == 10)
if ( Bars.IntradayBarNumber(bar) == 0 )
if (Open bar > daily.Close bar-1 )
if (Close bar > Open bar )
if( BuyAtClose(bar) != null )
Stop = daily.Close bar-1 ;
}
}
} else
DrawLabel( PricePane, "For use on intraday data", Color.Red );
}
}
}
[...] determine and compare time of day
public class MyStrategy : WealthScript
{
public int GetTime(int bar)
{
return Date bar .Hour * 100 + Date bar .Minute;
}
protected override void Execute()
{
// Specifically, I use a strategy that buys stocks only in the time period between 9:55 am and 13:00. for(int bar = 1; bar = 0955 ) & ( GetTime(bar) Identify the Open price of the day when working with intraday data
Here's [...]
[...] MA: Blue int Tier1 = 0, Tier2 = 0, Tier3 = 0, Tier4 = 0; for (int bar = GetTradingLoopStartBar(Math.Max(period * 3, 30)); bar bar >= Med bar && Med bar >= Slow bar && Slow bar >= Vslow bar ) ? 10 : 0;
Tier2 = (Fast bar >= Med bar && Med bar >= Slow bar && Slow bar bar ) ? 9 : 0;
Tier3 = (Fast bar bar && Med bar >= Slow [...]
[...] DataSeries(b, "TrendsStop(" + period + "," + factor + ")");
for (int bar = 0; bar bar = b.Low bar ;
for (int bar = period; bar bar-2 ;
double prev = trends bar-1 ;
if( (b.Low bar >= [...]
[...] above the 2nd one and the previous value was less than or equal to the target value at the previous bar. Motivated traders can compare approaches by commenting and uncommenting these lines:
if( CrossUnder( bar, tpEma, haEma ) )
//if( tpEma bar bar )
...
if( CrossOver( bar, tpEma, haEma ) )
//if( tpEma bar > haEma bar )
To run the sample Strategy in Wealth-Lab, you'll need the TASCIndicators [...]
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, [...]
[...] the average MTR by 3 standard deviations of MTR or greater. An entry is triggered when: Buy next bar at market if today's close price has declined. Short next bar at market if today's close price has increased. A position is exited with a simple trailing channel exit: Exit long when today's low price has broke below the 3-day lowest price. Cover short when today's high price has broke above the 3-day highest price. This system is merely a proof-of-concept. Among possible enhancements to this barebone system, the following can be [...]
[...] bar = 0; bar bar = bar;
RestoreScale();
dailyBars = Synchronize(dailyBars);
DataSeries GetDailyBar = Synchronize(CompBar); // Initialize an instance of the CamarillaPoint class
Camarilla c = new Camarilla();
double tick = Bars.SymbolInfo.Tick;
bool enterTrades = true;
bool canTrade = true;
Entry e = paramEntryType.ValueInt == 0 ? Entry.Inside : paramEntryType.ValueInt == 1 ? Entry.Outside : Entry.Breakout;
// [...]
[...] LineStyle.Solid;
PlotSeries(PricePane,sma,Color.Red,ls,1);
for(int bar = Math.Max(riseBars, GetTradingLoopStartBar(paramSMA.ValueInt)); bar i > sma i ) ? ba += 1 : 0;
whiteSpace bar = ba / (double)riseBars;
}
if (IsLastPositionActive)
{
SellAtStop( bar+1, LastPosition, Lowest.Series(Low,paramTrail.ValueInt) bar );
}
else
{
// 1. Detecting pivot
if( !pivot )
{
// Uptrend: price > SMA, momentum % > 100, "white [...]
[...] override void Execute()
{
for(int bar = 21; bar bar bar-20 )
SellAtMarket( bar+1, LastPosition );
}
else
{
if ( Close bar > Close bar-20 )
if( BuyAtMarket( bar+1 ) != null )
LastPosition.Priority = Close bar ;
}
}
}
}
}
Let's analyze step by step what does the code do? A complete trading strategy is included in the Wea
[...] changed from 12 to 51, and DataSeries initializations have been simplified. // WAS:
double Trend = ds bar - ds cycPeriod ;
// SHOULD BE (IS):
double Trend = ds bar - ds bar - cycPeriod ; /* Strategy Code revised 20090611 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators; namespace WealthLab.Strategies
{
public class CoronaCharts : WealthScript
{
public const double twoPi = 2 * Math.PI;
public const [...]
[...] almost any entry style without adding prejudice. Entry rules Pullback entry: Buy at open next bar if the DMI Oscillator is above 0 and the DMI Stochastic crosses above 10. Short at open next bar if the DMI Oscillator is below 0 and the DMI Stochastic crosses below 90. Countertrend entry: Short at open next bar if the DMI Oscillator crosses under -20. Buy at open next bar if the DMI Oscillator crosses above 20.
Exit rules Fixed bars: exit at open next bar [...]
[...] //Determine the first valid bar
var start = Math.Max(sto_60.FirstValidValue,
Math.Max(sto_d.FirstValidValue,
Math.Max(sto_w.FirstValidValue,
Math.Max(sto_m.FirstValidValue,
Math.Max(sto_q.FirstValidValue, sto_y.FirstValidValue))))); ChartPane sPane = CreatePane( 20, false, true);
PlotSeries( sPane, sto_60, Color.Peru, ls, 1);
PlotSeries( sPane, sto_d, Color.Chartreuse, ls, 1);
PlotSeries( sPane, sto_w, Color.Gainsboro, ls, 1);
PlotSeries( sPane, sto_m, Color.Sienna, ls, 1);
PlotSeries( sPane, sto_q, Color.IndianRed, ls, [...]
[...] GetTradingLoopStartBar(60); bar if( barssinceentry>= EXIT )
ExitAtClose(bar,Position.AllPositions,"TIME");
else
if( p.PositionType == PositionType.Long )
{
if( barssinceentry>3 && Close bar bar-barssinceentry *(1.0-STP/100d) && STOC bar >OS)
SellAtMarket(bar+1,p,"STOP"); if( barssinceentry>7 && Close bar bar *(1.0-STP/100d) )
SellAtMarket(bar+1,p,"TRAIL");
}
else
{
if( barssinceentry>3 && Close bar >Close [...]
[...] double alpha = gamma - Math.Sqrt(gamma * gamma - 1d);
for (int bar = 2; bar bar = 0.5 * (1 - alpha) * (ds bar - ds bar - 2 )
+ beta * (1 + alpha) * res bar - 1 - alpha * res bar - 2 ;
}
return res;
}
protected override void Execute()
{
int per = _period.ValueInt;
double delta = _delta.Value;
double [...]
[...] the following in a single position strategy:
if( IsLastPositionActive )
{
// exit on the last bar of the day
if( Bars.IsLastBarOfDay(bar) )
ExitAtClose( bar, LastPosition, "Last Bar" );
}
Or in a multiple open positions strategy that translates to:
for(int p = ActivePositions.Count - 1; p >= 0; p--)
{
Position pos = ActivePositions p ;
// exit on the last bar of the day
if( Bars.IsLastBarOfDay(bar) )
ExitAtClose( bar, [...]
Syntax
public static double ChandelierStop(this Position p, Bars bars, int bar, int period, double coefficient ) public double ChandelierStop(Bars bars, int bar, Position p, int period, double coefficient )
Parameter Description p Position to apply Chandelier stop to period TR period for Chandelier stop calculation coefficient ATR factor for Chandelier stop calculation bars Bars object bar Bar number Description
The Chandelier Stop is a trailing stop that [...]