Cone8
 ( 24.56% )
- ago
Ref: https://www.wealth-lab.com/Discussion/Push-Indicators-amp-Fundamentals-into-Strategy-Code-5849
"Push Indicators & Fundamentals into Strategy Code" was implemented in Build 26, but like in Version 6 the implementation falls a little short...

For me, pushing indicators into code is a quick way to populate their parameter lists without having to type anything. The problem is that the indicators are not assigned to variables that can be used in the script - you have to do that yourself by cutting and pasting.

The Feature Request is to assign the indicators to local variables to use in the Plot statements and that you could easily start using in your code.

How it is Pushed Now:
CODE:
public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          PlotIndicator(new SMA(bars.Close,200), Color.FromArgb(255,255,0,0), PlotStyles.Line);          PlotIndicator(new SMA(bars.Close,50), Color.FromArgb(255,0,0,255), PlotStyles.Line);          PlotIndicator(new RSI(bars.Close,10), Color.FromArgb(255,0,0,128), PlotStyles.Line); } //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 }


How I'd like to see them Pushed - sure it's more verbose, but it's 10x more useful!
CODE:
public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          _sma1 = new SMA(bars.Close, 200);          _sma2 = new SMA(bars.Close, 50);          _rsi1 = new RSI(bars.Close, 10);          PlotIndicator(_sma1, Color.FromArgb(255,255,0,0), PlotStyles.Line);          PlotIndicator(_sma2, Color.FromArgb(255,0,0,255), PlotStyles.Line);          PlotIndicator(_rsi1, Color.FromArgb(255,0,0,128), PlotStyles.Line); } //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             SMA _sma1;       SMA _sma2;       RSI _rsi1; }
9
1,151
Solved
2 Replies

Reply

Bookmark

Sort
- ago
#1
I agree with being able to push drag & drop indicators to code with C# code that is useful and ready to be used in a script. (Huge time saver and very helpful.)

Push the Indicator & Period. Line size and Line Type, so it’s ready to use.
_rsi14 = new RSI(bars.Close, 14);
//declare private variables below
RSI _rsi14;

Able to push the line color, line size, and Plot style as well would be a bonus.
PlotIndicator(_rsi14, WLColor.FromArgb(255, 0, 0, 128), 3, PlotStyle. Line);


#WL8..Code.


CODE:
public class MyStrategy : UserStrategyBase    {       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          _sma200 = new SMA(bars.Close, 200);          _sma50 = new SMA(bars.Close, 50);          _rsi14 = new RSI(bars.Close, 14);          _rsi2 = new RSI(bars.Close, 2);          PlotIndicator(_sma50, WLColor.FromArgb(255, 255, 0, 0), PlotStyle.Line);          PlotIndicator(_sma200, WLColor.FromArgb(255, 0, 0, 255), PlotStyle.ThickLine);          PlotIndicator(_rsi14, WLColor.FromArgb(255, 0, 0, 128), PlotStyle.ThickLine);          PlotIndicator(_rsi2, WLColor.White, PlotStyle.DashedLine);       }       //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       SMA _sma200;       SMA _sma50;       RSI _rsi14;       RSI _rsi2;    }
0
Glitch8
 ( 7.81% )
- ago
#2
Let's activate this for Build 11 since I completed the Trade History position sizing item and will need something to work on on the flights!
1
Best Answer

Reply

Bookmark

Sort