I am having an issue with plotting data I am generating via equations of variable type double. My equation has 27 variables which get assigned values as each bar is closed out. I am then manipulating this data and want to plot my results. So far it looks like I can only plot via DataSeries. But I am getting an error when I compile saying "cannot implicitly convert type double to WealthLab.DataSeries. I have tried creating a DataSeries, but because I am using variables in my equation and they need to be given a type (like double or float) I can't seem to make it work. Is there another option for plotting data that I am missing?
Any help would be greatly appreciated.
Thanks,
Brian
Size:
Color:
Brian, try copying and pasting your code when replying and we'll sort it out.
Size:
Color:
I copied the portion of my code that is giving me grief and pasted it below. Here is my basic goal. I am calculating the slope of the 15 minute MACD curve. The reason I am not using the canned MACD curve is because it only updates every 15 minutes. Withing that time frame the stock price can swing wildly and change an investment from very profitable and turn it into a loss. I want to run an algorithm on the current active bar and identify the price at which the slope of the MACD curve will change sign and thus indicate a signal to buy/sell. All of this can be done without plotting the curve, but I want to plot the curve on top of my canned MACD curve to ensure that my calculations of the curve itself are accurate. And there in lies my issue. I have initialized my variables as double but then I can't use them to plot the series. If there is a way around this it would be great.
Thanks for your help.
P.S. I know I could probably make use an array to assign my variable values, but this seemed to be a good starting point to me. If I can sort out the equations then I can move into better code.
CODE:
Please log in to see this code.
Size:
Color:
Let me kindly suggest that the optimal support strategy is to express a question straight rather than from a distance so to say and also to provide a sample code. Now I'm renaming the thread from a very distant "Plotting data acquired from my own equations" to something else that reflects the idea better and closely: "Identify the price at which the slope of MACD changes sign intra-bar". Knowing the goal you're trying to approach (reverse engineering MACD and/or its signal line), I can say that it has already been done - and more than once:
Reversing MACD (RevEngMACD)RevEngMACDReversing MACD: The SequelRevEngMACDSignalThe RevEngMACD indicator returns the price value required for the MACD to move to the zero value on the following bar and the RevEngMACDSignal indicator returns the price required for the MACD line to cross its signal line on the following bar. You'll find these helpful indicators in the TASCIndicators library. Since they've been there for years (since 2013) I don't think that your installation would require update but if it's not up to date you can do it by switching to "Other" extensions in the Extension Manager.
P.S. I don't think that your code is required but nonetheless here's a couple of remarks to better understand WealthScript:
1) To make it compile, you'd change from the double to DataSeries the following way:
CODE:
Please log in to see this code.
2) This placement is usually incorrect for the creation of DataSeries and always for plotting. Not many systems have to define DataSeries dynamically in the main loop so I'm even short of a strategy example. Just move the entire code out of the main (trading) loop.
Size:
Color:
Eugene,
Thanks for the reply and changing the title of the thread is OK too, although while my goal may be to calculate some aspects of the MACD curve, my question actually revolved around how to plot data that I have calculated outside of a DataSeries. I appreciate that you pointed out the two existing programs as well. While they are both interesting and could be very helpful if I could see the code behind them, neither of them are actually doing what I want to do. Both of them relate to the actual value of the MACD for instance the required value that will make the MACD curve = zero or pass zero and thus change sign, or cross over the trend line. I am interested in calculating the value at which the SLOPE of the MACD curve will change sign. In my particular case it is a much more valuable characteristic as it indicates a stock price directional change.
That being said, is there any way for me to see the code behind RevEngMACD or RevEngMACDSignal? That would be very helpful for me. I have tried pushing the indicator to my code but that doesn't actually push the code, just the plot statement.
I will also try what you suggested above, but would love to see how others have achieved a similar task.
Brian
Size:
Color:
Hi Brian,
QUOTE:
That being said, is there any way for me to see the code behind RevEngMACD or RevEngMACDSignal?
Sure, they're open source. Please create a
support ticket to verify your WLP entitlement and we'll grant access to the source code in the Wiki. Then you'd register a new Wiki account, log in, and download the "attachment" containing the
TASCIndicators library code by clicking on green "Attachments" button.
QUOTE:
I am interested in calculating the value at which the SLOPE of the MACD curve will change sign.
Alas, among our indicators you could find
RevEngRSI, RevEngBBandCross or
RevEngSMA but no "RevEngSlope" exists. You'd have to build it as a DIY project. However, I still don't see how the MACD code what you have would help you with your task of reverse engineering the slope (is LinearRegSlope on your mind?)
Size:
Color:
Eugene,
Great, I will sign up in order to access the source code. Thanks for the info.
Agreed that the code I provided was incomplete for calculating the slope of the MACD. According to the equations I have found online for calculating an EMA, it should have been adequate to calculate the MACD itself. I implemented the "DataSeries" suggestions you provided above and was able to generate a curve that was roughly equivalent to the MACD curve provided by WL. Seeing the source code from a number of WL solutions will be very helpful in refining my understanding of coding within the WL environment.
I will certainly keep you posted as my program evolves. Thanks again for your help and prompt responses.
Brian
Size:
Color: