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 < Bars.Count; bar++) { if (IsLastPositionActive) { // exit rule here... } else if( ( GetTime(bar) >= 0955 ) & ( GetTime(bar) <= 1300 ) ) BuyAtMarket( bar+1 ); } } }
int firstBarToday = bar - Bars.IntradayBarNumber(bar);// So the Opening price of the session is then: double openToday = Open[firstBarToday];
int firstBarToday = bar - Bars.IntradayBarNumber(bar);//So it follows that the previous bar is the last bar of the prior day. int lastBarYesterday = firstBarToday - 1;//So, yesterday's close is: Close[lastBarYesterday];
// in the loop double highestHighToday = Highest.Value(bar, High, Bars.IntradayBarNumber(bar) + 1);
double highestHighToday = -1; for(int bar = 20; bar < Bars.Count; bar++) { if (Bars.IntradayBarNumber(bar) == 0) highestHighToday = High[bar]; else if (High[bar] > highestHighToday) highestHighToday = High[bar]; }
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() { // counter of days int cnt = 0; for(int bar = 1; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; // loop backwards from current bar to last position's bar of entry for( int Bar = bar; Bar >= p.EntryBar; Bar-- ) { // when day changes, increment counter if( Bars.IntradayBarNumber( Bar ) == 0 ) { cnt++; break; } } // when counter reaches 3, sell if( cnt >= 3 ) ExitAtMarket( bar+1, LastPosition ); } else { BuyAtMarket( bar+1 ); cnt = 0; } } } } }
if( Bars.IsIntraday ) { int bi = Bars.BarInterval; DataSeries high52week = Highest.Series( High, (int)Math.Truncate( 5 * (60/bi)*6.5 * 52 ) ); PlotSeries( PricePane, high52week, Color.Black, WealthLab.LineStyle.Solid, 1 ); }
public class MyStrategy : WealthScript { protected override void Execute() { /* One entry per day Option 1: at top of loop */ for(int bar = 20; bar < Bars.Count; bar++) { Position p = LastPosition; if (p != null && !p.Active && p.EntryBar > (bar - Bars.IntradayBarNumber(bar))) continue; if (IsLastPositionActive) { //code your exit rules here } else { //code your entry rules here } } /* One entry per day Option 2: as an entry condition */ for(int bar = 20; bar < Bars.Count; bar++) { Position p = LastPosition; if (IsLastPositionActive) { //code your exit rules here } else if (p == null || !p.Active && p.EntryBar < (bar - Bars.IntradayBarNumber(bar))) { //code your entry rules here } } } }