|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
Indicator - Reading Bar Value and Tick Value .. |
Federro
|
Post subject: Indicator - Reading Bar Value and Tick Value .. |
Post rating: 0
|
Posted: Thu 19 Jul, 2012, 08:45
|
|
User rating: 2
Joined: Tue 08 Nov, 2011, 15:23 Posts: 29 Location: Slovenia,
|
... I would like to make an indicator that is reading bar and tick values and than makes calculation on that data. My problem is reading bar and tick data..
In startegy bellow works fine. In Indicator code reports problem ..
public void ReadBarValue(int shift) throws JFException { IBar bar = history.getBar(Instrument.EURUSD, Period.FIFTEEN_MINS, OfferSide.ASK, shift); double barValue_Open = bar.getOpen(); double barValue_Close = bar.getClose(); double barValue_High = bar.getHigh(); double barValue_Low = bar.getLow(); double barVolume = bar.getVolume(); }
The idea is: //Main Indicator Calculation int i, j; for (i = startIndex, j = 0; i <= endIndex; i++, j++) { double value = 0; for (int k = timePeriod; k > 0; k--) { //timePeriod doloci na koliko barov se izvede izracun! // Read Bar Value - Call is not Working - debug problem ... // The best will be to read bars and ticks directly here - no function call ... ReadBarValue(i); value += (barValue_Open - barValue_Close); } outputs[0][j] = value; }
plus ... 1.) WHAT COMMAND has to be used in the Strategy to read custom indicator - named: BasicIndicator_TV indicatorInfo = new IndicatorInfo("BasicIndicator_TV", "Sums previous values", "My indicators", false, false, false, 1, 1, 1); 2.) WHERE Custom Indicator CODE has to be placed that strategy running on VIRTUAL SERVER is able to read custom indicator DATA
|
|
|
|
 |
API Support
|
Post subject: Re: Indicator - Reading Bar Value and Tick Value .. |
Post rating: 0
|
Posted: Thu 19 Jul, 2012, 10:07
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Federro wrote: ... I would like to make an indicator that is reading bar and tick values and than makes calculation on that data. My problem is reading bar and tick data..
In startegy bellow works fine. In Indicator code reports problem ..
public void ReadBarValue(int shift) throws JFException { IBar bar = history.getBar(Instrument.EURUSD, Period.FIFTEEN_MINS, OfferSide.ASK, shift); double barValue_Open = bar.getOpen(); double barValue_Close = bar.getClose(); double barValue_High = bar.getHigh(); double barValue_Low = bar.getLow(); double barVolume = bar.getVolume(); }
The idea is: //Main Indicator Calculation int i, j; for (i = startIndex, j = 0; i <= endIndex; i++, j++) { double value = 0; for (int k = timePeriod; k > 0; k--) { //timePeriod doloci na koliko barov se izvede izracun!
// Read Bar Value - Call is not Working - debug problem ... // The best will be to read bars and ticks directly here - no function call ... ReadBarValue(i); value += (barValue_Open - barValue_Close); } outputs[0][j] = value; }
Could you please recap what do you want the indicator to do, namely: - What is the calculation algorithm.
- What are the outputs of the indicator.
Federro wrote: 1.) WHAT COMMAND has to be used in the Strategy to read custom indicator - named: BasicIndicator_TV indicatorInfo = new IndicatorInfo("BasicIndicator_TV", "Sums previous values", "My indicators", false, false, false, 1, 1, 1); See: https://www.dukascopy.com/wiki/#Use_custom_indicator_in_strategies/Simple_custom_indicatorFederro wrote: 2.) WHERE Custom Indicator CODE has to be placed that strategy running on VIRTUAL SERVER is able to read custom indicator DATA It can't get placed on the cloud servers, hence you need to use the second approach, i.e.: //register custom indicator defined inside a strategy indicators.registerCustomIndicator(Indicator.class);
|
|
|
|
 |
Federro
|
Post subject: Re: Indicator - Reading Bar Value and Tick Value .. |
Post rating: 0
|
Posted: Thu 19 Jul, 2012, 13:02
|
|
User rating: 2
Joined: Tue 08 Nov, 2011, 15:23 Posts: 29 Location: Slovenia,
|
... Let' s keep it simple. Algoritem can be complicated later. At the moment I am unable to read bar values in the indicator calculation.
Let's say that indicator is showing average open price - LINE ..
avreageOpen = (open (0)+open(1)+bar.Open(2))/3
|
|
|
|
 |
API Support
|
Post subject: Re: Indicator - Reading Bar Value and Tick Value .. |
Post rating: 0
|
Posted: Thu 19 Jul, 2012, 14:44
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Find the comments in the code: package jforex.indicators;
import java.util.Arrays;
import com.dukascopy.api.IConsole; import com.dukascopy.api.indicators.IIndicator; import com.dukascopy.api.indicators.IIndicatorContext; import com.dukascopy.api.indicators.IndicatorInfo; import com.dukascopy.api.indicators.IndicatorResult; import com.dukascopy.api.indicators.InputParameterInfo; import com.dukascopy.api.indicators.IntegerRangeDescription; import com.dukascopy.api.indicators.OptInputParameterInfo; import com.dukascopy.api.indicators.OutputParameterInfo;
/** * The indicator accepts PRICE inputs and outputs the average of the last 3 * OPEN prices. For debugging purposes, the indicator also logs input, output * arrays and other parameters. * */ public class InputsOutputsPriceTest implements IIndicator{ private IndicatorInfo indicatorInfo; private InputParameterInfo[] inputParameterInfos; private OptInputParameterInfo[] optInputParameterInfos; private OutputParameterInfo[] outputParameterInfos; private double[][][] inputs = new double[1][][]; private int timePeriod = 2; private double[][] outputs = new double[1][]; private IConsole console; private static final int OPEN=0, CLOSE=1, HIGH=2, LOW=3, VOLUME=4; public void onStart(IIndicatorContext context) { indicatorInfo = new IndicatorInfo("Inputs outputs test", "My custom", "Math Operators", true, false, false, 1, 1, 1); inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)}; optInputParameterInfos = new OptInputParameterInfo[] { new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(timePeriod, 1, 200, 1))}; outputParameterInfos = new OutputParameterInfo[] { new OutputParameterInfo("Average", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE) }; console = context.getConsole(); }
public IndicatorResult calculate(int startIndex, int endIndex) { //lookback adjustment if (startIndex - getLookback() < 0) { startIndex -= startIndex - getLookback(); } if (startIndex > endIndex) { return new IndicatorResult(0, 0); }
for (int i = startIndex, j = 0; i <= endIndex; i++, j++) { //average of the last 3 values - mind that we have no risk of negative index i, because of lookback adjustment above //if you need more values for average, then increase lookback outputs[0][j] = (inputs[0][OPEN][i] + inputs[0][OPEN][i-1] + inputs[0][OPEN][i-2])/3; } //logging for your convenience, to see with what inputs and outputs we work with and what is the lookback effect //change the timePeriod value in the optional parameters to see how the input and output sizes change console.getOut().println(String.format("output length = %s, contents = %s, \ninput[OPEN] length = %s, contents = %s,\n" + "startIndex=%s, endIndex=%s, getLookback()=%s", outputs[0].length, Arrays.toString(outputs[0]), inputs[0][OPEN].length, Arrays.toString(inputs[0][OPEN]), startIndex, endIndex, getLookback())); return new IndicatorResult(startIndex, endIndex-startIndex + 1); }
public IndicatorInfo getIndicatorInfo() { return indicatorInfo; }
public InputParameterInfo getInputParameterInfo(int index) { if (index <= inputParameterInfos.length) { return inputParameterInfos[index]; } return null; }
public int getLookback() { return timePeriod; }
public int getLookforward() { return 0; }
public OptInputParameterInfo getOptInputParameterInfo(int index) { if (index <= optInputParameterInfos.length) { return optInputParameterInfos[index]; } return null; }
public OutputParameterInfo getOutputParameterInfo(int index) { if (index <= outputParameterInfos.length) { return outputParameterInfos[index]; } return null; }
public void setInputParameter(int index, Object array) { inputs[index] = (double[][]) array; }
public void setOptInputParameter(int index, Object value) { timePeriod = (Integer) value; }
public void setOutputParameter(int index, Object array) { outputs[index] = (double[]) array; } }
Attachments: |
InputsOutputsPriceTest.java [4.55 KiB]
Downloaded 288 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|