Since C# is Chinese for me, I've used the sample of an SMA code as input into chat gpt and said to use this syntax in order to convert this Metastock formula into a WL formula:
100 * (c - mov(c,20,s) + 2 * stdev(c,20))) / (4 * Stdev(c,20))
Sadly, there is always an error and also, the error code of the compiler cannot be copy/pasted which would be very handy (#FeatureRequest)
This is the result of ChatGPT:
Is this completely false or some minor errors?
100 * (c - mov(c,20,s) + 2 * stdev(c,20))) / (4 * Stdev(c,20))
Sadly, there is always an error and also, the error code of the compiler cannot be copy/pasted which would be very handy (#FeatureRequest)
This is the result of ChatGPT:
CODE:
using WealthLab.Core; using System; using WealthLab.Indicators; namespace WealthLab.MyIndicators { public class CustomIndicator : IndicatorBase { DataSeries close; // Parameterless constructor public CustomIndicator() : base() { Populate(); } // Code-based constructor public CustomIndicator(TimeSeries source, int period) : base() { Parameters[0].Value = source; Parameters[1].Value = period; Populate(); } // Static method to create the indicator public static CustomIndicator Series(TimeSeries source, int period) { return new CustomIndicator(source, period); } // Name of the indicator public override string Name { get { return "Custom Indicator"; } } // Abbreviation public override string Abbreviation { get { return "Custom"; } } // Description public override string HelpDescription { get { return "Custom indicator description."; } } // Price pane public override string PaneTag { get { return "Price"; } } // Is it a smoother? public override bool IsSmoother { get { return true; } } // Populate the indicator values public override void Populate() { TimeSeries source = Parameters[0].AsTimeSeries; int period = Parameters[1].AsInt; DateTimes = source.DateTimes; if (period <= 0) return; close = source; for (int bar = period - 1; bar < source.Count; bar++) { Values[bar] = (100 * (close[bar] - CustomSMA.Value(bar, close, period) + 2 * stdev(bar, close, period))) / (4 * stdev(bar, close, period)); } } // Helper method to calculate standard deviation private double stdev(int bar, TimeSeries source, int period) { if (period <= 0 || bar >= source.Count || (bar - period + 1) < 0) return Double.NaN; double sum = 0; double avg = CustomSMA.Value(bar, source, period); for (int n = 0; n < period; n++) { var i = bar - n; sum += Math.Pow(source[i] - avg, 2); } return Math.Sqrt(sum / period); } // Generate parameters protected override void GenerateParameters() { AddParameter("Source", ParameterType.TimeSeries, PriceComponent.Close); AddParameter("Period", ParameterType.Int32, 20); } } }
Is this completely false or some minor errors?
Rename
Have you heard of GIGO?
https://en.wikipedia.org/wiki/Garbage_in%2C_garbage_out
This formula has its parentheses messed up:
100 * (c - mov(c,20,s) + 2 * stdev(c,20))) / (4 * Stdev(c,20))
https://en.wikipedia.org/wiki/Garbage_in%2C_garbage_out
This formula has its parentheses messed up:
100 * (c - mov(c,20,s) + 2 * stdev(c,20))) / (4 * Stdev(c,20))
With a little fix to the GIGO formula, the indicator can be rewritten like this:
CODE:
using WealthLab.Core; using System; using System.Drawing; using WealthLab.Indicators; namespace WealthLab.MyIndicators { public class BollingerStochastic : IndicatorBase { //parameterless constructor public BollingerStochastic() : base() { } //for code based construction public BollingerStochastic(TimeSeries source, int period) : base() { Parameters[0].Value = source; Parameters[1].Value = period; Populate(); } //static Series method public static BollingerStochastic Series(TimeSeries source, int period) { return new BollingerStochastic(source, period); } //name public override string Name { get { return "Bollinger Stochastic"; } } //abbreviation public override string Abbreviation { get { return "BollingerStochastic"; } } //description public override string HelpDescription { get { return ""; } } //price pane public override string PaneTag { get { return "BS"; } } //default color public override WLColor DefaultColor { get { return WLColor.FromArgb(255,0,0,255); } } //default plot style public override PlotStyle DefaultPlotStyle { get { return PlotStyle.Line; } } //populate public override void Populate() { TimeSeries source = Parameters[0].AsTimeSeries; int period = Parameters[1].AsInt; DateTimes = source.DateTimes; TimeSeries sma = FastSMA.Series(source, period); TimeSeries sd = StdDev.Series(source, period); //modify the code below to implement your own indicator calculation for (int n = 0; n < source.Count; n++) { Values[n] = 100.0 * (source[n] - sma[n] + 2 * sd[n]) / (4 * sd[n]); } } //generate parameters protected override void GenerateParameters() { AddParameter("source", ParameterType.TimeSeries, PriceComponent.Close); AddParameter("period", ParameterType.Int32, 20); } } }
Thanks for the effort Eugene.
Indeed, the parentheses were messed up. Don't know what happened.
It works! :-)
After a restart, the indicator is available.
But know: only in admin mode.
Indeed, the parentheses were messed up. Don't know what happened.
It works! :-)
After a restart, the indicator is available.
But know: only in admin mode.
Glad to see you're up and running. It's soothing to learn that we humans still can be helpful where the almighty ChatGPT stumbles.😃
QUOTE:
But now: only in admin mode.
If you decide to become a real C# programmer and use the Visual Studio IDE to build your indicators, then you can compile a personal DLL library and use it without the admin mode. Then you'll be like the rest of us. My strategies are typically 300 lines long, but my personal DLL library is over 2500 lines long (not counting Math.NET and ScottPlot code). Happy computing.
Once I have more indicators, will consider to look up about the personal DLL Library.
I know some arduino, metastock, multicharts and tradestation programming but mostly I copy/paste the basic and tweak it until it works.
But c# is another level for me and since WL has it own syntax (or how what you say this) it gives an extra steep learning curve.
Don't know what chatgtp needs to do this correctly.
It's probably possible with the latest paid version or at least the next gen of gpt to upload WL documentation so it can at least convert a formula from another language.
I know some arduino, metastock, multicharts and tradestation programming but mostly I copy/paste the basic and tweak it until it works.
But c# is another level for me and since WL has it own syntax (or how what you say this) it gives an extra steep learning curve.
Don't know what chatgtp needs to do this correctly.
It's probably possible with the latest paid version or at least the next gen of gpt to upload WL documentation so it can at least convert a formula from another language.
Your Response
Post
Edit Post
Login is required