using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using TASCIndicators;namespace WealthLab.Strategies { public class HACOLTStrategy : WealthScript { private StrategyParameter period; private StrategyParameter candlesize; private StrategyParameter ltaverage; public HACOLTStrategy() { period = CreateParameter("TEMA Period",55,2,100,10); candlesize = CreateParameter("Candle Size",1.1,0.01,5,0.5); ltaverage = CreateParameter("Shorting LT Average",60,1,200,20); } protected override void Execute() { HACOLT hacolt = HACOLT.Series(Bars, period.ValueInt, candlesize.Value, 2, ltaverage.ValueInt); ChartPane paneHACOLT = CreatePane(30,true,true); PlotSeries(paneHACOLT, hacolt, Color.FromArgb(255,138,43,226), LineStyle.Solid, 2); HideVolume(); for(int bar = hacolt.FirstValidValue; bar < Bars.Count; bar++) { bool buyLong = hacolt[bar] == 100; bool closeLong = hacolt[bar] == 0 || CrossUnder(bar, hacolt, 50); bool goShort = hacolt[bar] == 0; bool coverShort = hacolt[bar] == 100; // The first trade if (Positions.Count == 0){ if ( buyLong ) BuyAtMarket( bar + 1 ); else if( goShort ) ShortAtMarket( bar + 1 ); } // Subsequent trades else { Position p = LastPosition; if ( p.PositionType == PositionType.Long ) { if ( closeLong ) { SellAtMarket( bar + 1, p ); if( goShort ) if( ShortAtMarket( bar+1 ) != null ) LastPosition.Priority = Close[bar]; } } else if ( coverShort ) { CoverAtMarket( bar + 1, p ); if( buyLong ) if( BuyAtMarket( bar+1 ) != null ) LastPosition.Priority = -Close[bar]; } } } } } }