using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class MultiLevel : WealthScript { private StrategyParameter paramStop; private StrategyParameter paramTake; public MultiLevel() { paramStop = CreateParameter("Stop, pips", 20, 5, 50, 5); paramTake = CreateParameter("Profit, pips", 30, 5, 100, 5); } protected override void Execute() { try { Bars bEur = GetExternalSymbol( "Eur/Usd", true ); Bars bGbp = GetExternalSymbol( "Gbp/Usd", true ); DataSeries multiGBP = (bEur.Close-bEur.Open) + (bGbp.Close+bGbp.Open) / 10000; multiGBP.Description = "multiGBP"; BBandLower bbl = BBandLower.Series( multiGBP, 100, 2.0 ); BBandUpper bbu = BBandUpper.Series( multiGBP, 100, 2.0 ); bbl.Description = "Adaptive Lower Threshold"; bbu.Description = "Adaptive Higher Threshold"; ChartPane cp = CreatePane( 50,true,true ); PlotSeries( cp, multiGBP, Color.Blue, LineStyle.Solid, 1 ); PlotSeriesFillBand( cp, bbu, bbl, Color.Red, Color.Transparent, LineStyle.Solid, 1 ); DrawHorzLine( cp, 0, Color.Blue, LineStyle.Solid, 1 ); HideVolume(); double SL = paramStop.Value / 10000d; double PT = paramTake.Value / 10000d; for(int bar = GetTradingLoopStartBar( 100 ); bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; double Stop = p.PositionType == PositionType.Long ? p.EntryPrice - SL : p.EntryPrice + SL; double Target = p.PositionType == PositionType.Long ? p.EntryPrice + PT : p.EntryPrice - PT; if( !ExitAtStop(bar + 1, p, Stop, "SL") ) ExitAtLimit(bar + 1, p, Target, "TP"); } else { if( CrossOver( bar, multiGBP, bbl ) ) BuyAtMarket( bar+1 ); else if( CrossUnder( bar, multiGBP, bbu ) ) ShortAtMarket( bar+1 ); } } } catch( Exception e ) { PrintDebug( e.Message ); Abort(); } } } }