ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to shift the financial indicator to the right x period
Posted by Andy Deng on Aug-20-2019 23:17
Attachments:
Hi Peter,
I wanted to design a custom financial indicator similar to bollingerBands, but I use my own custom data series. I have a C# code attached below.
I have to questions :  1. could you translate the C# code to Java and chartDirector code? when I look at the main code portion is simple, my I have no C# knowledge now.
2. How could I displace the indicator 1 period to the right relative to the candlestick price chart? means the indicator line shift to the right side 1 period compare to the price chart.
if you are difficult to understand this point, there's a chart attached below.
I hope to hear from you soon.
Regards,
Andy
OscillatorPredictor.cs
OscillatorPredictor.cs

9.10 Kb
    
OscillatorPredictor.PNG

  Re: How to shift the financial indicator to the right x period
Posted by Peter Kwan on Aug-21-2019 16:29
Hi Andy,

The code you attached seems unrelated to ChartDirector. It seems most of the code is not written by a human being. (The comment mentioned that it is generated by another script.) The code uses third party libraries that I have never used before, the third party library possibly has no Java counterpart.

I am worry if you decide to translate the code, you would need to translate it yourself. C# and Java are very similar languages, and the code should be easy to translate, provided you are familar the third part library and the script that generate the code.

Another method is to simply write your own code to compute the indicator. Most financial indicators are based on simple formulas that can be implemented without much effort. If also avoids any copyright issues, if any.

In the case of ChartDirector, the indicator you have computed should be stored as two double[] arrays. These two arrays are the points at the top and bottom lines of the band. You can then add the band to the chart using FinanceChart.addBand.

https://www.advsofteng.com/doc/cdjava.htm#FinanceChart.addBand.htm

To shift an indicator to the right, please shift your data array to the right. You would also need to an entry to your timeStamp array so there is a timeStamp beyond the last OHLC bar.

For example, suppose the double[] array contains  { 1, 3, 5, 7, 9 }. To shift the data to the right, change it to : { ??, 1, 3, 5, 7, 9 }. The last value 9 will be shifted to the position beyond the original OHLC bar. The ?? depends on how your indicator is defined. If there is no such value, just use Chart.NoValue as the value.

Regards
Peter Kwan

  Re: How to shift the financial indicator to the right x period
Posted by Andy Deng on Aug-26-2019 23:58
Hi Peter,
Thanks a lot for your reply! I managed to write my own java code based on the little information from the C# code. But I'm doubt about the precision of the indicator. The indicator could show up on the chart anyway.
I have another question: In Java or chartDirector, how could I get the 3 maximum elements within an array, those 3 max elements are not consecutive.  For example , I would like to get the 3 max values of DPO indicator  for the past 6 months, and those 3 numbers shouldn't be one after another.  Could you give me some advice to do this?
I hope to hear from you soon!
Regards,
Jianhua

  Re: How to shift the financial indicator to the right x period
Posted by Peter Kwan on Aug-27-2019 01:36
Hi Andy,

There are many methods. For example, you can just sort your array and get the top 3 values. Another method is to scan your array to get the maximum value. Then set the element that contains the maximum value to -1E100 (so that is no longer have the maximum). The scan your array for the maximum value again. Because the original maximum value is removed, so you get the 2nd maximum value. Then set it to -1E100 and scan the array again to get the 3rd maximum value.

Regards
Peter Kwan

  Re: How to shift the financial indicator to the right x period
Posted by Andy Deng on Aug-27-2019 08:43
Hi Peter,
Thanks for your reply! I got it. I have a question regarding to ChartDirector's ArrayMath method. I want to design a custom indicator, the calculation is like this : DPO= close of current - simple moving average of past 7 trading days.  Then get the 3 maximum value of DPO array for further calculation.  Can you provide some sample code to do that in Java version? I have read the ChartDirector docoments for ArrayMath method, but I still can't make it.
I hope to hear from you soon.
Thanks and Regards,
Jianhua

  Re: How to shift the financial indicator to the right x period
Posted by Peter Kwan on Aug-27-2019 19:15
Hi Andy,

The code to compute the DPO is:

double[] dpo = new ArrayMath(closeData).movAvg(7).mul(-1).add(closeData).result();

You can then use the dpo array to compute the indicator you want.

Hope this can help.

Regards
Peter Kwan

  Re: How to shift the financial indicator to the right x period
Posted by Andy Deng on Aug-31-2019 10:17
Hi Peter,
Thanks a lot for reply!

Regards,
Jianhua


cix porn hard porn kostenlose porn amateur xxx love porn amateur sex hd porn free 3 xxx moblie porn