- ago
I would like to have a zero horizontal line to show in the chart pane every time I bring up my created indicator.
CODE:
DrawHorzLine(0.0, Color.Red, 1, LineStyles.Solid, "MyPane");
Can I use this code line in the Indicator Code Builder? If I can how and where would I put the code line in? Here is my indicator code.
CODE:
using WealthLab.Core; using System; using System.Drawing; using WealthLab.Indicators; namespace WealthLab.Indicators {    public class My310 : IndicatorBase    {       //parameterless constructor       public My310() : base()       {       }       //for code based construction       public My310(TimeSeries source, Int32 len1, Int32 len2)          : base()       {          Parameters[0].Value = source;          Parameters[1].Value = len1;          Parameters[2].Value = len2;          Populate();       }       //static Series method       public static My310 Series(TimeSeries source, Int32 len1, Int32 len2)       {          return new My310(source, len1, len2);       }       //name       public override string Name       {          get          {             return "My310";          }       }       //abbreviation       public override string Abbreviation       {          get          {             return "My310";          }       }       //description       public override string HelpDescription       {          get          {             return "Differance between two SMA";          }       }       //price pane       public override string PaneTag       {          get          {             return "310Pane";          }       }       //default color       public override Color DefaultColor       {          get          {             return Color.FromArgb(255, 0, 0, 255);          }       }       //default plot style       public override PlotStyles DefaultPlotStyle       {          get          {             return PlotStyles.Line;          }       }       //populate       public override void Populate()       {          TimeSeries source = Parameters[0].AsTimeSeries;          Int32 len1 = Parameters[1].AsInt;          Int32 len2 = Parameters[2].AsInt;          DateTimes = source.DateTimes;          SMA sma3 = new SMA(source, len1);          SMA sma10 = new SMA(source, len2);          //modify the code below to implement your own indicator calculation          for (int n = 0; n < source.Count; n++)          {             Values[n] = sma3[n] - sma10[n];          }       }       //generate parameters       protected override void GenerateParameters()       {          AddParameter("Source", ParameterTypes.TimeSeries, PriceComponents.Close);          AddParameter("Len1", ParameterTypes.Int32, 3);          AddParameter("Len2", ParameterTypes.Int32, 10);       }    } }
0
1,372
Solved
7 Replies

Closed

Bookmark

Sort
- ago
#1
No, DrawHorzLine and other WealthScript methods cannot be used in an indicator.
0
- ago
#2
Ok Thanks
0
- ago
#3
But once you have your indicator displayed in it's pane, you can add your zero line.
0
mrsic8
 ( 19.50% )
- ago
#4
Why i can't see the DrawHorzLine. I've tried many ways, but without success. Can anyone help me?

CODE:
public class Munich : UserStrategyBase { private IndicatorBase _stochDLong; private IndicatorBase _stochDShort; private IndicatorBase _tgtAtrLong; private IndicatorBase _tgtAtrShort; public Munich() : base() { AddParameter("NoB_LG", ParameterTypes.Int32, 3, 1, 10, 1); 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, 20, 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, 80, 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[6].AsInt) * Parameters[7].AsInt) >> 1 ; TimeSeries atrCalcMinus = (bars.Close - ATR.Series(bars, Parameters[14].AsInt) * Parameters[15].AsInt) >> 1; levelLong = Parameters[5].AsInt; levelShort = Parameters[14].AsInt; //Calc StochD for long and short _stochDLong = StochD.Series(bars, Parameters[3].AsInt, Parameters[4].AsInt); PlotIndicator(_stochDLong, Color.Bisque, PlotStyles.DottedLine, true); DrawHorzLine(levelLong, Color.Green, 1, LineStyles.Dotted, "StochD"); //No Lines. Check it!! _stochDShort = StochD.Series(bars, Parameters[11].AsInt, Parameters[12].AsInt); PlotIndicator(_stochDShort, Color.Black, PlotStyles.Dots, true); DrawHorzLine(levelShort, Color.Red, 2, LineStyles.Dotted, "StochD"); //No Lines. Check it!! //Calc ATR for long and short _tgtAtrLong = ATR.Series(bars, Parameters[6].AsInt); PlotTimeSeries(atrCalcPlus, "AtrCalcPlus", "AtrCalcPlus", Color.Aqua); _tgtAtrShort = ATR.Series(bars, Parameters[14].AsInt); PlotTimeSeries(atrCalcMinus, "AtrCalcMinus", "AtrCalcMinus", Color.Coral); StartIndex = 3 * Math.Max(Parameters[6].AsInt, Parameters[14].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) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below private int levelShort, levelLong; } }
0
- ago
#5
Because the array indexes are all wrong. Remember, the count is zero-based:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript111 {    public class Munich : UserStrategyBase    {       private IndicatorBase _stochDLong;       private IndicatorBase _stochDShort;       private IndicatorBase _tgtAtrLong;       private IndicatorBase _tgtAtrShort;       public Munich() : base()       {          AddParameter("NoB_LG", ParameterTypes.Int32, 3, 1, 10, 1);          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;          levelLong = Parameters[4].AsInt;          levelShort = Parameters[12].AsInt;          //Calc StochD for long and short          _stochDLong = StochD.Series(bars, Parameters[3].AsInt, Parameters[3].AsInt);          PlotIndicator(_stochDLong, Color.Bisque, PlotStyles.DottedLine, true);          DrawHorzLine(levelLong, Color.Green, 3, LineStyles.Dotted, _stochDLong.PaneTag); //No Lines. Check it!!          _stochDShort = StochD.Series(bars, Parameters[11].AsInt, Parameters[11].AsInt);          PlotIndicator(_stochDShort, Color.Black, PlotStyles.Dots, true);          DrawHorzLine(levelShort, Color.Red, 3, LineStyles.Dotted, _stochDShort.PaneTag); //No Lines. Check it!!          //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)       {          if (!HasOpenPosition(bars, PositionType.Long))          {             //code your buy conditions here          }          else          {             //code your sell conditions here          }       }       //declare private variables below       private int levelShort, levelLong;    } }
0
Best Answer
mrsic8
 ( 19.50% )
- ago
#6
Hi Eugene,
I completely overlooked it. Thanks.
0
- ago
#7
You're welcome Damir.

I have to say that topic starter's specific case has been answered from the start. Further general question re: DrawHorzLine may look confusing in this context. Let's lock the thread for replies then.
0

Closed

Bookmark

Sort