Hello,
can someone check this for me please and set correctly a Priority or give me a hint. I am not a programmer, but I give my best.
I couldn't set a Priority because i didn't found one as in WL 6. I saw in the QuickRef in WL Priority under Transaction, there should be the Priority. Unfortunately I didn't find any.
WL6
WL7
can someone check this for me please and set correctly a Priority or give me a hint. I am not a programmer, but I give my best.
I couldn't set a Priority because i didn't found one as in WL 6. I saw in the QuickRef in WL Priority under Transaction, there should be the Priority. Unfortunately I didn't find any.
WL6
CODE:
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; namespace WealthLab.Strategies { public class MyStrategy2 : WealthScript { private StrategyParameter slider1; private StrategyParameter slider2; private StrategyParameter slider3; private StrategyParameter slider4; private StrategyParameter slider5; private StrategyParameter slider6; private StrategyParameter slider7; private StrategyParameter slider8; private StrategyParameter slider9; private StrategyParameter slider10; private StrategyParameter slider11; private StrategyParameter slider12; private StrategyParameter slider13; private StrategyParameter slider14; private StrategyParameter slider15; private StrategyParameter slider16; public MyStrategy2() { slider1 = CreateParameter("NoB_LG",3,1,10,1); slider2 = CreateParameter("LB_LG",1,1,5,1); slider3 = CreateParameter("StochD_LB_LG",5,1,10,1); slider4 = CreateParameter("StochD_Smoothing_LG",2,1,10,1); slider5 = CreateParameter("Stochd_LV_LG",20,16,30,1); slider6 = CreateParameter("ATR_LB_LG",5,1,50,1); slider7 = CreateParameter("ATR_Multiplier_LG",1.8,1.5,5,0.1); slider8 = CreateParameter("TBX_LG",4,1,10,1); slider9 = CreateParameter("NoB_ST",4,1,10,1); slider10 = CreateParameter("LB_ST",1,1,5,1); slider11 = CreateParameter("StochD_LB_ST",5,1,10,1); slider12 = CreateParameter("StochD_Smoothing_ST",3,1,10,1); slider13 = CreateParameter("Stochd_Level_ST",80,70,90,1); slider14 = CreateParameter("ATR_LB_ST",5,1,50,1); slider15 = CreateParameter("ATR_Multiplier_ST",1,0.5,2,0.1); slider16 = CreateParameter("TBX_ST",3,1,10,1); } protected override void Execute() { // Anlegen von DataSeries zur Berechnung des StochD DataSeries StochdLong = StochD.Series(Bars, slider3.ValueInt, slider4.ValueInt); DataSeries StochdShort = StochD.Series(Bars, slider11.ValueInt, slider12.ValueInt); // Anlegen von DateSeries zur Berechnung des ATR DataSeries TgtAtrLG = ATR.Series( Bars, slider6.ValueInt); //ATR_LG DataSeries TgtAtrST = ATR.Series( Bars, slider14.ValueInt); //ATR_ST // Grafische anzeige des Stochd ChartPane paneStoch = CreatePane(75,true,true); PlotSeries(paneStoch, StochdLong, Color.Black, LineStyle.Dotted, 2); DrawHorzLine(paneStoch, slider5.Value, Color.Green, LineStyle.Solid, 1); PlotSeries(PricePane, (Close + ATR.Series(Bars, slider6.ValueInt) * slider7.Value) >> 1, Color.Green, LineStyle.Solid, 1); PlotSeries(paneStoch, StochdShort, Color.Black, LineStyle.Dotted, 2); DrawHorzLine(paneStoch, slider13.Value, Color.Red, LineStyle.Solid, 1); PlotSeries(PricePane, (Close - ATR.Series(Bars, slider14.ValueInt) * slider15.Value) >> 1, Color.Red, LineStyle.Solid, 1); var startbar = 1 * Math.Max(slider6.ValueInt, slider14.ValueInt);//Unstable ATR for(int bar = GetTradingLoopStartBar(startbar); bar < Bars.Count; bar++) // for(int bar = Bars.Count - 1; bar < Bars.Count; bar++) // Signalschleife { if (IsLastPositionActive) { Position p = LastPosition; if (p.PositionType == PositionType.Short) { if (bar - p.EntryBar >= slider16.ValueInt) { CoverAtMarket(bar + 1, p); } CoverAtLimit(bar + 1, p, Close[bar] - ATR.Value(bar, Bars, slider14.ValueInt) * slider15.Value); } else { if (bar - p.EntryBar >= slider8.ValueInt) { SellAtMarket(bar + 1, p); } SellAtLimit(bar + 1, p, Close[bar] + ATR.Value(bar, Bars, slider6.ValueInt) * slider7.Value); } } else { if (CumUp.Value(bar, Close, slider10.ValueInt) >= slider9.ValueInt) { if (StochdShort[bar] > slider13.Value) { double prio = StochdShort[bar]; string prioString = string.Format ("{0:0.00} / Limit={1:0.00} / Close={2:0.00}",prio, Close [bar] - TgtAtrST[bar] * slider15.Value, Close[bar]); // Ueberpruefe ob Position tatsaechlich eroeffnet wurde if (ShortAtMarket(bar + 1, prioString) != null ) { LastActivePosition.Priority = prio; } } } if (CumDown.Value(bar, Close, slider2.ValueInt) >= slider1.ValueInt) { //Uberpruefe die Long-Entry-Bedingung if (StochdLong[bar] < slider5.Value) { double prio = 100 - StochdLong[bar]; string prioString = string.Format("{0:0.00} / Limit={1:0.00} / Close={2:0.00} ", prio, Close [bar] + TgtAtrLG[bar] * slider7.Value, Close[bar]); // Ueberpruefe ob Position tatsaechlich eroeffnet wurde if (BuyAtMarket(bar + 1, prioString) != null ) { LastActivePosition.Priority = prio; } } } } } } } }
WL7
CODE:
using System; using System.Drawing; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace MunichStrategy { public class Munich : UserStrategyBase { public Munich() : base() { AddParameter("NoB_LG", ParameterTypes.Int32, 3, 1, 10, 1); // Index start at 0 AddParameter("LB_LG", ParameterTypes.Int32, 1, 1, 5, 1); AddParameter("StochD_LB_LG", ParameterTypes.Int32, 5, 1, 10, 1); AddParameter("StochD_Smoothing_LG", ParameterTypes.Int32, 2, 1, 10, 1); AddParameter("Stochd_LV_LG", ParameterTypes.Int32, 40, 16, 30, 1); AddParameter("ATR_LB_LG", ParameterTypes.Int32, 5, 1, 50, 1); AddParameter("ATR_Multiplier_LG", ParameterTypes.Int32, 1.8, 1.5, 5, 0.1); AddParameter("TBX_LG", ParameterTypes.Int32, 4, 1, 10, 1); AddParameter("NoB_ST", ParameterTypes.Int32, 4, 1, 10, 1); AddParameter("LB_ST", ParameterTypes.Int32, 1, 1, 5, 1); AddParameter("StochD_LB_ST", ParameterTypes.Int32, 5, 1, 10, 1); AddParameter("StochD_Smoothing_ST", ParameterTypes.Int32, 3, 1, 10, 1); AddParameter("Stochd_Level_ST", ParameterTypes.Int32, 70, 70, 90, 1); AddParameter("ATR_LB_ST", ParameterTypes.Int32, 5, 1, 50, 1); AddParameter("ATR_Multiplier_ST", ParameterTypes.Int32, 1, 0.5, 2, 0.1); AddParameter("TBX_ST", ParameterTypes.Int32, 3, 1, 10, 1); } //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { TimeSeries atrCalcPlus = (bars.Close + ATR.Series(bars, Parameters[5].AsInt) * Parameters[6].AsInt) >> 1; TimeSeries atrCalcMinus = (bars.Close - ATR.Series(bars, Parameters[13].AsInt) * Parameters[14].AsInt) >> 1; //TimeSeries upIndicator = (UpDown.Value(bars.Close, Parameters[0].AsInt) >= Parameters[1].AsInt; _levelLong = Parameters[4].AsInt; _levelShort = Parameters[12].AsInt; //Calc StochD for long and short _stochDLong = StochD.Series(bars, Parameters[2].AsInt, Parameters[3].AsInt); PlotIndicator(_stochDLong, Color.OrangeRed, PlotStyles.DottedLine, true); DrawHorzLine(_levelLong, Color.Green, 3, LineStyles.Dotted, _stochDLong.PaneTag); _stochDShort = StochD.Series(bars, Parameters[10].AsInt, Parameters[11].AsInt); PlotIndicator(_stochDShort, Color.Black, PlotStyles.DashedLine, true); DrawHorzLine(_levelShort, Color.Red, 3, LineStyles.Dotted, _stochDShort.PaneTag); //Calc ATR for long and short _tgtAtrLong = ATR.Series(bars, Parameters[5].AsInt); PlotTimeSeries(atrCalcPlus, "AtrCalcPlus", "AtrCalcPlus", Color.Aqua); _tgtAtrShort = ATR.Series(bars, Parameters[13].AsInt); PlotTimeSeries(atrCalcMinus, "AtrCalcMinus", "AtrCalcMinus", Color.Coral); StartIndex = 3 * Math.Max(Parameters[5].AsInt, Parameters[13].AsInt); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { var isLastPositionActive = HasOpenPosition(bars, PositionType.Long) || HasOpenPosition(bars, PositionType.Short); if (isLastPositionActive) { Position p = LastPosition; if (p.PositionType == PositionType.Short) { if (idx - p.EntryBar >= Parameters[15].AsInt) ClosePosition(p, OrderType.Market); else ClosePosition(p, OrderType.Limit, _tgtAtrShort[idx]); } else { if (idx - p.EntryBar >= Parameters[7].AsInt) ClosePosition(p, OrderType.Market); else ClosePosition(p, OrderType.Limit, _tgtAtrLong[idx]); } } else { if (!HasOpenPosition(bars, PositionType.Long)) { if (UpDown.Value(idx, bars.Close, Parameters[9].AsInt) >= Parameters[8].AsInt) { if (_stochDShort[idx] > Parameters[12].AsInt) { _prio = _stochDShort[idx]; string prioString = string.Format("{0:0.00} / Limit={1:0.00} / Close={2:0.00} ", _prio, bars.Close[idx] + _tgtAtrShort[idx] * Parameters[14].AsInt, bars.Close); { PlaceTrade(bars, TransactionType.Short, OrderType.Market); } } } if (UpDown.Value(idx, bars.Close, Parameters[1].AsInt) >= Parameters[0].AsInt) { if (_stochDLong[idx] < Parameters[4].AsInt) { _prio = 100 - _stochDLong[idx]; string prioString = string.Format("{0:0.00} / Limit={1:0.00} / Close={2:0.00} ", _prio, bars.Close[idx] + _tgtAtrLong[idx] * Parameters[6].AsInt, bars.Close); { PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } } } } } } //declare private variables below private int _levelShort, _levelLong; private double _prio; private IndicatorBase _stochDLong; private IndicatorBase _stochDShort; private IndicatorBase _tgtAtrLong; private IndicatorBase _tgtAtrShort; private IndicatorBase indicator; } }
Rename
Hello,
Click the magnifier icon to activate full text search. Then, searching for "priority weight" for example, you can find topics with helpful code examples and explanations by Glitch like this:
https://www.wealth-lab.com/Discussion/How-to-use-Weight-with-multiple-limits-5850
Click the magnifier icon to activate full text search. Then, searching for "priority weight" for example, you can find topics with helpful code examples and explanations by Glitch like this:
https://www.wealth-lab.com/Discussion/How-to-use-Weight-with-multiple-limits-5850
Hello Eugene,
Thanks.
I set the priority, it seems it works for Short. I can't see where the error is, because I don't get any Long Trades?
Can someone check this for me please?
Thanks.
I set the priority, it seems it works for Short. I can't see where the error is, because I don't get any Long Trades?
Can someone check this for me please?
CODE:
using System; using System.Drawing; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace MunichStrategy { public class Munich : UserStrategyBase { public Munich() : base() { AddParameter("NoB_LG", ParameterTypes.Int32, 3, 1, 10, 1); // Index start at 0 AddParameter("LB_LG", ParameterTypes.Int32, 1, 1, 5, 1); AddParameter("StochD_LB_LG", ParameterTypes.Int32, 5, 1, 10, 1); AddParameter("StochD_Smoothing_LG", ParameterTypes.Int32, 2, 1, 10, 1); AddParameter("Stochd_LV_LG", ParameterTypes.Int32, 40, 16, 30, 1); AddParameter("ATR_LB_LG", ParameterTypes.Int32, 5, 1, 50, 1); AddParameter("ATR_Multiplier_LG", ParameterTypes.Int32, 1.8, 1.5, 5, 0.1); AddParameter("TBX_LG", ParameterTypes.Int32, 4, 1, 10, 1); AddParameter("NoB_ST", ParameterTypes.Int32, 4, 1, 10, 1); AddParameter("LB_ST", ParameterTypes.Int32, 1, 1, 5, 1); AddParameter("StochD_LB_ST", ParameterTypes.Int32, 5, 1, 10, 1); AddParameter("StochD_Smoothing_ST", ParameterTypes.Int32, 3, 1, 10, 1); AddParameter("Stochd_Level_ST", ParameterTypes.Int32, 70, 70, 90, 1); AddParameter("ATR_LB_ST", ParameterTypes.Int32, 5, 1, 50, 1); AddParameter("ATR_Multiplier_ST", ParameterTypes.Int32, 1, 0.5, 2, 0.1); AddParameter("TBX_ST", ParameterTypes.Int32, 3, 1, 10, 1); } //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { TimeSeries atrCalcPlus = (bars.Close + ATR.Series(bars, Parameters[5].AsInt) * Parameters[6].AsInt) >> 1; TimeSeries atrCalcMinus = (bars.Close - ATR.Series(bars, Parameters[13].AsInt) * Parameters[14].AsInt) >> 1; //TimeSeries upIndicator = (UpDown.Value(bars.Close, Parameters[0].AsInt) >= Parameters[1].AsInt; _levelLong = Parameters[4].AsInt; _levelShort = Parameters[12].AsInt; //Calc StochD for long and short _stochDLong = StochD.Series(bars, Parameters[2].AsInt, Parameters[3].AsInt); PlotIndicator(_stochDLong, Color.OrangeRed, PlotStyles.DottedLine, true); DrawHorzLine(_levelLong, Color.Green, 3, LineStyles.Dotted, _stochDLong.PaneTag); _stochDShort = StochD.Series(bars, Parameters[10].AsInt, Parameters[11].AsInt); PlotIndicator(_stochDShort, Color.Black, PlotStyles.DashedLine, true); DrawHorzLine(_levelShort, Color.Red, 3, LineStyles.Dotted, _stochDShort.PaneTag); //Calc ATR for long and short _tgtAtrLong = ATR.Series(bars, Parameters[5].AsInt); PlotTimeSeries(atrCalcPlus, "AtrCalcPlus", "AtrCalcPlus", Color.Aqua); _tgtAtrShort = ATR.Series(bars, Parameters[13].AsInt); PlotTimeSeries(atrCalcMinus, "AtrCalcMinus", "AtrCalcMinus", Color.Coral) StartIndex = 3 * Math.Max(Parameters[5].AsInt, Parameters[13].AsInt); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { var isLastPositionActive = HasOpenPosition(bars, PositionType.Long) || HasOpenPosition(bars, PositionType.Short); if (isLastPositionActive) { Position p = LastPosition; if (p.PositionType == PositionType.Short) { if (idx - p.EntryBar >= Parameters[15].AsInt) ClosePosition(p, OrderType.Market); else ClosePosition(p, OrderType.Limit, _tgtAtrShort[idx]); } else { if (idx - p.EntryBar >= Parameters[7].AsInt) ClosePosition(p, OrderType.Market); else ClosePosition(p, OrderType.Limit, _tgtAtrLong[idx]); } } else { if (!HasOpenPosition(bars, PositionType.Short)) { if (UpDown.Value(idx, bars.Close, Parameters[9].AsInt) >= Parameters[8].AsInt) { if (_stochDShort[idx] > Parameters[12].AsInt) { _prioShort = _stochDShort[idx]; string prioString = string.Format("{0:0.00} / Limit={1:0.00} / Close={2:0.00} ", _prioShort, bars.Close[idx] - _tgtAtrShort[idx] * Parameters[14].AsInt, bars.Close[idx]); var t = PlaceTrade(bars, TransactionType.Short, OrderType.Market, _prioShort, prioString); if (t != null) { t.Weight = _prioShort; } } } else { if (UpDown.Value(idx, bars.Close, Parameters[1].AsInt) >= Parameters[0].AsInt) { if (_stochDLong[idx] < Parameters[4].AsInt) { _prioLong = 100 - _stochDLong[idx]; string prioString = string.Format("{0:0.00} / Limit={1:0.00} / Close={2:0.00} ", _prioLong, bars.Close[idx] + _tgtAtrLong[idx] * Parameters[6].AsInt, bars.Close[idx]); var t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, _prioLong, prioString); if (t != null) { t.Weight = _prioLong; } } } } } } } //declare private variables below private int _levelShort, _levelLong; private double _prioLong, _prioShort; private IndicatorBase _stochDLong; private IndicatorBase _stochDShort; private IndicatorBase _tgtAtrLong; private IndicatorBase _tgtAtrShort; private IndicatorBase indicator; } }
Hello Damir,
Firstly, it won't compile because of line #72. Also made a change to the way you check for HasOpenPosition:
Firstly, it won't compile because of line #72. Also made a change to the way you check for HasOpenPosition:
CODE:
using System; using System.Drawing; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace MunichStrategy { public class Munich : UserStrategyBase { public Munich() : base() { AddParameter("NoB_LG", ParameterTypes.Int32, 3, 1, 10, 1); // Index start at 0 AddParameter("LB_LG", ParameterTypes.Int32, 1, 1, 5, 1); AddParameter("StochD_LB_LG", ParameterTypes.Int32, 5, 1, 10, 1); AddParameter("StochD_Smoothing_LG", ParameterTypes.Int32, 2, 1, 10, 1); AddParameter("Stochd_LV_LG", ParameterTypes.Int32, 40, 16, 30, 1); AddParameter("ATR_LB_LG", ParameterTypes.Int32, 5, 1, 50, 1); AddParameter("ATR_Multiplier_LG", ParameterTypes.Int32, 1.8, 1.5, 5, 0.1); AddParameter("TBX_LG", ParameterTypes.Int32, 4, 1, 10, 1); AddParameter("NoB_ST", ParameterTypes.Int32, 4, 1, 10, 1); AddParameter("LB_ST", ParameterTypes.Int32, 1, 1, 5, 1); AddParameter("StochD_LB_ST", ParameterTypes.Int32, 5, 1, 10, 1); AddParameter("StochD_Smoothing_ST", ParameterTypes.Int32, 3, 1, 10, 1); AddParameter("Stochd_Level_ST", ParameterTypes.Int32, 70, 70, 90, 1); AddParameter("ATR_LB_ST", ParameterTypes.Int32, 5, 1, 50, 1); AddParameter("ATR_Multiplier_ST", ParameterTypes.Int32, 1, 0.5, 2, 0.1); AddParameter("TBX_ST", ParameterTypes.Int32, 3, 1, 10, 1); } //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { TimeSeries atrCalcPlus = (bars.Close + ATR.Series(bars, Parameters[5].AsInt) * Parameters[6].AsInt) >> 1; TimeSeries atrCalcMinus = (bars.Close - ATR.Series(bars, Parameters[13].AsInt) * Parameters[14].AsInt) >> 1; //TimeSeries upIndicator = (UpDown.Value(bars.Close, Parameters[0].AsInt) >= Parameters[1].AsInt; _levelLong = Parameters[4].AsInt; _levelShort = Parameters[12].AsInt; //Calc StochD for long and short _stochDLong = StochD.Series(bars, Parameters[2].AsInt, Parameters[3].AsInt); PlotIndicator(_stochDLong, Color.OrangeRed, PlotStyles.DottedLine, true); DrawHorzLine(_levelLong, Color.Green, 3, LineStyles.Dotted, _stochDLong.PaneTag); _stochDShort = StochD.Series(bars, Parameters[10].AsInt, Parameters[11].AsInt); PlotIndicator(_stochDShort, Color.Black, PlotStyles.DashedLine, true); DrawHorzLine(_levelShort, Color.Red, 3, LineStyles.Dotted, _stochDShort.PaneTag); //Calc ATR for long and short _tgtAtrLong = ATR.Series(bars, Parameters[5].AsInt); PlotTimeSeries(atrCalcPlus, "AtrCalcPlus", "AtrCalcPlus", Color.Aqua); _tgtAtrShort = ATR.Series(bars, Parameters[13].AsInt); PlotTimeSeries(atrCalcMinus, "AtrCalcMinus", "AtrCalcMinus", Color.Coral); StartIndex = 3 * Math.Max(Parameters[5].AsInt, Parameters[13].AsInt); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { var isLastPositionActive = HasOpenPosition(bars, PositionType.Long) || HasOpenPosition(bars, PositionType.Short); if (isLastPositionActive) { Position p = LastPosition; if (p.PositionType == PositionType.Short) { if (idx - p.EntryBar >= Parameters[15].AsInt) ClosePosition(p, OrderType.Market); else ClosePosition(p, OrderType.Limit, _tgtAtrShort[idx]); } else { if (idx - p.EntryBar >= Parameters[7].AsInt) ClosePosition(p, OrderType.Market); else ClosePosition(p, OrderType.Limit, _tgtAtrLong[idx]); } } else { if (!HasOpenPosition(bars, PositionType.Short)) { if (UpDown.Value(idx, bars.Close, Parameters[9].AsInt) >= Parameters[8].AsInt) { if (_stochDShort[idx] > Parameters[12].AsInt) { _prioShort = _stochDShort[idx]; string prioString = string.Format("{0:0.00} / Limit={1:0.00} / Close={2:0.00} ", _prioShort, bars.Close[idx] - _tgtAtrShort[idx] * Parameters[14].AsInt, bars.Close[idx]); var t = PlaceTrade(bars, TransactionType.Short, OrderType.Market, _prioShort, prioString); t.Weight = _prioShort; } } } if (!HasOpenPosition(bars, PositionType.Long)) { if (UpDown.Value(idx, bars.Close, Parameters[1].AsInt) >= Parameters[0].AsInt) { if (_stochDLong[idx] < Parameters[4].AsInt) { _prioLong = 100 - _stochDLong[idx]; string prioString = string.Format("{0:0.00} / Limit={1:0.00} / Close={2:0.00} ", _prioLong, bars.Close[idx] + _tgtAtrLong[idx] * Parameters[6].AsInt, bars.Close[idx]); var t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, _prioLong, prioString); t.Weight = _prioLong; } } } } } //declare private variables below private int _levelShort, _levelLong; private double _prioLong, _prioShort; private IndicatorBase _stochDLong; private IndicatorBase _stochDShort; private IndicatorBase _tgtAtrLong; private IndicatorBase _tgtAtrShort; private IndicatorBase indicator; } }
Your Response
Post
Edit Post
Login is required