using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;//Requires CandlePattern Rules Classnamespace WealthLab.Strategies { public class TASC201710 : WealthScript { private StrategyParameter paramSL; private StrategyParameter paramTP; private StrategyParameter paramStops; public TASC201710() { paramStops = CreateParameter("Activate SL/PT",1,0,1,1); paramSL = CreateParameter("Stop %",3,1,10,1); paramTP = CreateParameter("Profit %",5,1,20,1); } protected override void Execute() { var sto = StochK.Series( Bars, 14 ); var rsi = RSI.Series( Close, 14 ); bool enableStopAndProfit = paramStops.ValueInt == 1 ? true : false; for(int bar = GetTradingLoopStartBar( 50 ); bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; if( p.PositionType == PositionType.Long ) { var twoLowerLows = CumDown.Series( Low, 1)bar - 1 >= 2; var overbot = (stobar >= 80) || (rsibar >= 70); double Stop = p.EntryPrice * (1 - paramSL.Value / 100d); double Profit = p.EntryPrice * (1 + paramTP.Value / 100.0d); if( twoLowerLows ) SellAtMarket( bar+1, p, "2 lows" ); else if( overbot ) SellAtMarket( bar+1, p, "Overbought" ); else if(enableStopAndProfit) { if(!SellAtStop( bar + 1, p, Stop, "Stop") ) SellAtLimit( bar + 1, p, Profit, "Profit" ); } } else { var twoHigherHighs = CumUp.Series( High ,1)bar - 1 >= 2; var oversold = (stobar <= 20) || (rsibar <= 30); double Stop = p.EntryPrice * (1 + paramSL.Value / 100d); double Profit = p.EntryPrice * (1 - paramTP.Value / 100.0d); if( twoHigherHighs ) CoverAtMarket( bar+1, p, "2 highs" ); else if( oversold ) CoverAtMarket( bar+1, p, "Oversold" ); else if (enableStopAndProfit) { if(!CoverAtStop( bar + 1, p, Stop, "Stop") ) CoverAtLimit( bar + 1, p, Profit, "Profit" ); } } } else { //trend definition (define your own one) var trendBearish = CumDown.Series( Close, 1 )bar - 1 >= 3; var trendBullish = CumUp.Series( Close, 1 )bar - 1 >= 3; //50-day average volume is greater than 100,000 var volume = SMA.Series( Volume, 50 )bar > 100000; //Bullish one white soldier scan var soldier = this.isBullishOneWhiteSoldier(bar); var price1 = Closebar > 1.0; //Bearish one black crow scan var crow = this.isBearishOneBlackCrow(bar); var price10 = Closebar > 10.0; //Scans var BullishScan = trendBearish && volume && soldier && price1; var BearishScan = trendBullish && volume && crow && price10; doublebar-1" title=" rectangle = { bar-4, Highest.Series(High, 3)">bar-1"> rectangle = { bar-4, Highest.Series(High, 3)bar-1, bar-4, Lowest.Series(Low, 3)[bar-1, bar, Lowest.Series(Low, 3)bar-1, bar, Highest.Series(High, 3)bar-1 }; if( BullishScan ) { DrawPolygon( PricePane, Color.Transparent, Color.FromArgb(30, Color.Green), LineStyle.Solid, 2, true, rectangle ); BuyAtMarket(bar+1, "Bullish one white soldier"); } else if( BearishScan ) { DrawPolygon( PricePane, Color.Transparent, Color.FromArgb(30, Color.Red), LineStyle.Solid, 2, true, rectangle ); ShortAtMarket(bar+1, "Bearish one black crow"); } } } } } }