Dukascopy
 
 
Wiki JStore Search Login

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.

Pulling values from an indicator - Problems with my array
 Post subject: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Sun 15 Dec, 2013, 10:40 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
Hi

I am starting to rebuild my strategy from MT4 in java.

I think i may have not constructed the array correctly to pull the correct values from the ZigZag indicator.

I have referenced the indicator section in the wiki and also looked at these two threads, but I still need a little help.

https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=50104&p=75080&hilit=zigzag#p75080
https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=85&t=48970

I was using my code from MT4 as a guide, and just trying to modify the syntax, but this may not always work I guess.

Having run the code I get Strategy tester: java.lang.NullPointerException, which I think suggests that I am not collecting the values I need?

Could someone enlighten my as to how I get the previous values from ZigZag so that I can populate my variable for SwingValue [0],[1] which will help define my trend.
PLease see screenshot of a chart to see which values I would like.

I also tried to just output the value of Zigzag without an array and the result was NaN???? Why would there be no value?

here is my code attempt:
package MyStrategies;

import com.dukascopy.api.Configurable;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.MaType;
import com.dukascopy.api.indicators.IIndicator;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Simon
 */
public class TestStrategy implements IStrategy {
    private IConsole console;
   private IIndicators indicators;
   private IChart chart;
   private IEngine engine;
   
    //External Variables
    @Configurable("Instrument")
    public Instrument instrument  = Instrument.EURUSD;
    @Configurable ("ExtZZDepth")
    public int ExtZZDepth=3;
    @Configurable ("ExtZZDeviation")
    public int ExtZZDeviation=7;
    @Configurable ("ExtZZBackStep")
    public int ExtZZBackStep=6;
     @Configurable ("ExtSwingTF")
    public Period ExtSwingTF=Period.ONE_HOUR;
   
    //Swing Variables
    public double[] SwingValue;
    static boolean newZigZag = false;
    static double prevZigZag = 0;
    static int Trend = 0;
    private static final int UpTrend = 1;
    private static final int DownTrend = -1;
   
   
     
   
   
   


   
    @Override
    public void onStart(IContext context) throws JFException {
       this.engine =  context.getEngine();
       this.indicators  = context.getIndicators();
       this.console = context.getConsole();
       this.chart = context.getChart(instrument);
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
       
        if (!instrument.equals(this.instrument) || !period.equals(ExtSwingTF))
         return;
       
       int Found = 2;
       int k = 0;
      while(Found >= 0)
      {
       
            if (indicators.zigzag(instrument, ExtSwingTF, OfferSide.BID, ExtZZDepth, ExtZZDeviation, ExtZZBackStep,k) != 0)
            {
                SwingValue[Found] = indicators.zigzag(instrument, ExtSwingTF, OfferSide.BID, ExtZZDepth, ExtZZDeviation, ExtZZBackStep,k ); //report back the 2 swingvalues as set by found
                Found--;
                //SwingDate[Found]=iTime(Symbol(),ExtZZSwingTF,k); // report back the 2 swing dates in the array as set by found
               
               
            }
            console.getOut().println("Swingvalue 0: " + SwingValue[0]);
            console.getOut().println("Swingvalue 1: " + SwingValue[1]);
        }
       
         k++;
   
     

   
    if (prevZigZag != SwingValue[1])
      {
         newZigZag = true;
         prevZigZag = SwingValue[1];
         
         
      }
 if (newZigZag) // is always a new zigzag so not sure exactly why this is needed
      {
         
           // define the uptrend and downtrend       
           
         if(SwingValue[0] < SwingValue[1])
         {
            Trend = UpTrend;
         }
         else Trend = DownTrend;
 console.getOut().println("Trend: " + Trend);
}
    }


Image


Attachments:
swingvalue example.png [28.51 KiB]
Downloaded 364 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.
 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Mon 16 Dec, 2013, 10:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
There are multiple issues with your strategy:
  1. The NPE you get is because you have not initialized your array, e.g.:
       public double[] SwingValue = new double[3];
  2. Your counter k, does not get incremented within the while cycle - the iteration goes on forever.
  3. You should be comparing the ZigZag value by using the Double.isNaN method.
  4. You should not calculate the same zigzag value twice - it not only is code copying, but also worsens the performance. Moreover, consider calculating the zigzag over candle interval, which is more efficient than calculation by shift multiple times. Besides when you calculate by shift you are implicitly using the Filter.NO_FILTER, see the second to last paragraph in https://www.dukascopy.com/wiki/#Indicator_Calculation/Candlestick_price_feed. Also consider reusing the previously calculated indicator values - now you are going back by increasing the shift indefinitely, although already on the previous onBar you already calculated the same values. Thus, it may suffice for you to calculate by candle interval on the first onBar call and then calculate by shift=1 on all the following onBar calls.
  5. There is no reason for newZigZag and prevZigZag to be stratic. And the rest of your static variables don't follow the all caps convention.
We addressed some of the issues when updating your example strategy (see it in attachments).


Attachments:
TestStrategyZigZag.java [2.99 KiB]
Downloaded 113 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.
 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Tue 17 Dec, 2013, 10:28 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
thanks

I am slowly working through your comments.

1. - yup still going through a java tutorial on youtube and haven't got to arrays yet. I am trying to do the tutorial in parallel to my coding.
2. my bad
3. - I have read up up about Double.isNAN, but i don't understand why to do this check? why would the result of the indicator be NaN anyway? surely it will only be NaN before the indicator is initialized?
4. - this is going to take me some time to read through and try to understand - i will revert
5. ok thanks

I wanted to see your code run so I could visually see the output of the indicator in the historical tester along with the messages.
I tried to add the indicator to your code, but I must have done something wrong. Could you please have a look? I wanted the parameters of the indicator to use the global variables that I select.
 @Override
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.indicators = context.getIndicators();
        this.console = context.getConsole();
        this.chart = context.getChart(instrument);
         
        IChart chart = context.getChart(instrument);
IIndicator indZigZag = indicators.getIndicator("ZigZag");
for (int i = 0; i < indZigZag.getIndicatorInfo().getNumberOfInputs(); i++) {
  InputParameterInfo inputParameterInfo = indZigZag.getInputParameterInfo(i);
  inputParameterInfo.setAppliedPrice(AppliedPrice.CLOSE);
}                                                   
         
chart.add(indZigZag, new Object[]{instrument, ExtSwingTF, OfferSide.BID, ExtZZDepth, ExtZZDeviation, ExtZZBackStep}, new Color[]{Color.RED},
  new DrawingStyle[]{DrawingStyle.LINE}, new int[]{1});
       
        }


Attachments:
TestStrategyZigZag.java [4.31 KiB]
Downloaded 118 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.
 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 1   New post Posted: Tue 17 Dec, 2013, 12:59 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Quote:
3. - I have read up up about Double.isNAN, but i don't understand why to do this check?

This is how ZigZag implemented on the platform. As not every candle have a 'real' ZigZag value, there must be something that identifies these candles.
If you have a candle with NAN as ZigZag value, that means that at this particular candle there is no ZigZag section ending/starting, but the previous section continues (or there is no section at all, if this is one of the latest candle of the instrument).

I've played around with ZigZag a couple of months ago. Maybe this topic will help you (there is a code example in it as well):
viewtopic.php?f=85&t=48970

And, as we talk about ZigZag, there are still some open questions about the functionality of the indicator:
viewtopic.php?f=85&t=48974&p=70195&hilit=zigzag#p70195
viewtopic.php?f=81&t=49096&p=70651&hilit=zigzag#p70651

edit: typo


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Tue 17 Dec, 2013, 21:19 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
thanks tcsabina - now i understand why to use isNAN in this case :) - i will look at those posts.

I notice you have also made the journey from MT4?

Are you aware of a collection of help notes / comparisons between Mql4 and java? If not I might start a topic that others can add to, and maybe get support to add a sticky or add to the wiki. There must be a lot of people that have been through this process, and as a non-coder by profession, I myself find it difficult.
I have loads of code in my MT4 strategies which compensates for the poor platform design, and it would be good to know if any of this is still required, or whether "new workarounds" are needed. eg error message handling, creating variables for bid/ask to use in calculations,normalizedoubles,refreshrates, different digits on different brokers, modify orders on ECN's etc etc.

Have you found the jforex optimizations run quicker than MT4? (that is my main hope)


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Tue 17 Dec, 2013, 21:42 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hi PhoenixProject,

Unfortunately I haven't been using mq4 before JForex. (Or maybe that is fortunate instead? :)).
But here are some thoughts, that might be useful.

First, I dropped you a private message couple of days ago. ;).
Secondly, the code base (or article base) about mq4->JForex is not existing. I agree that it could come handy for a lot of people, so if you willing to spend time with it, the community will benefit from it for sure.
Thirdly, I cannot compare the two platform's optimization process, as I only used JForex's Historical Tester. And mostly just 'single' testing of strategies, not overall optimizations. But I can say that get the most powerful PC that you can get, as the tester is a CPU eater.
And at last, you might take a look on the Visual JForex platform. This is quite new development of the Dukascopy team, which make strategy creation easier. Probably you cannot create a very sophisticated code with Visual JForex, and you cannot 'import' mq4 stuff in it, but it is creating a java source code out from your strategy, which (the java source) could be useful to learn the basic aspects of a strategy.


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Tue 17 Dec, 2013, 22:19 
User avatar

User rating: 96
Joined: Mon 09 Sep, 2013, 07:09
Posts: 287
Location: Ukraine, SHostka
PhoenixProject wrote:
Have you found the jforex optimizations run quicker than MT4? (that is my main hope)
It depends on Historical Tester settings.
But reliability of JForex Historical Tester results are much higher due to tick data. Although Dukascopy's tick data are not 100% reliable.

Some people try to do things like this one:
https://dukascopy-mt4.fairtradingtech.com/about/newsletter/february-2012/utilizing-dukascopy-tick-data-for-back-testing-in-mt4/


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Wed 18 Dec, 2013, 08:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
PhoenixProject wrote:
I tried to add the indicator to your code, but I must have done something wrong. Could you please have a look? I wanted the parameters of the indicator to use the global variables that I select.
You should pass only the optional input parameters, not the feed parameters, i.e.
new Object[] {ExtZZDepth, ExtZZDeviation, ExtZZBackStep}


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Wed 18 Dec, 2013, 10:44 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
great thanks, that solved it!!
so where does the visual mode zigzag pick up the timeframe to apply on the chart? this is one of my input variables "ExtSwingTF". does it just display the zigzag based on the current chart timeframe? I am having a hard time marrying up the visual swings with the messages.


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Wed 18 Dec, 2013, 12:10 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
PhoenixProject wrote:
does it just display the zigzag based on the current chart timeframe?
Yes it does, in JForex in principle the indicator only works with the on-chart feed, unless it is specially designed to user other feeds.


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Wed 18 Dec, 2013, 23:20 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
ok thanks.
will that affect my optimization testing though? I want to use the ExtSwingTF (Swing Periods) variable in the optimization settings, otherwise I need to run optimization on each timeframe separatly which is time consuming.


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Thu 19 Dec, 2013, 03:57 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
I have been testing the zigzag some more and trying to get the values that I want, but I don't seem to be able to output them. I think the reason for this may be a difference in the way that the indicator works in comparison the MT4.
As per the screen shot above in my previous post, I want to get SwingValue 0 and 1. Even though price has move past Swingvalue 1 and a new swing appears to be forming the values stil remain constant, until the new swing is confirmed. Now this may repaint/redraw but then Swingvalue 1 just becomes Swing value 0.
I have attached two more images that represent this. (You can see the values for the Swingvalues in the top left of the screen) Example 2 if the first screenshot and then in Example 3 you can see the new swing and the values change. Swing value 1 becomes swing value 0.

So to try to see this on Jforex, I changed the code - i put the Zigzag indicator in the OnTick section so that I could see what was happening clearer. It seemed to me that Swingvalue 0 was calculated at the latest price. Therefore I thought maybe I could just make the array bigger and have Swingvalue 0,1,2. and then use values 1 and 2 instead. But this didn't seem to work either. I think as the indicator starts to redraw it alters all the values in the array, so that none of them represent the previous swing at all.
I have attached an example from Jforex (in the next post) - I have labelled the last two swings with the swing values, and you can compare these to the last values printed in the messages. You can see they don't relate at all.
Also is it necessary to have 4 messages per hour period? I guess this is related to the Array somehow, but is there a way to stop this?

I also started looking at your recommendation for doing the calculation on candle interval etc, but couldn't really see how I would code for this. Can you please show me how to achieve this? I would like to optimize the performance of the strategy as that is one of my main issues in MT4 - the testing is too slow. I can't see how you know the period to lookback?

Image
Image


Attachments:
TestStrategyZigZagOnTick.java [4.48 KiB]
Downloaded 113 times
swingvalue example 3.png [27.47 KiB]
Downloaded 338 times
swingvalue example 2.png [26.77 KiB]
Downloaded 353 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.
 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Thu 19 Dec, 2013, 05:00 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
jforex image for previous post

Image


Attachments:
Swingvalues jforex.png [73.59 KiB]
Downloaded 544 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.
 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Thu 19 Dec, 2013, 16:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
What we told you about using the previous value usage applies to indicators which are neither recalculate all nor unstable period. ZigZag is the former, hence you have to go with calculating all values at once. Your best shot is picking an optimal lookback value, such that 90% of the times it will return sufficient amount of ZigZag values, then, however, if the values don't suffice, you simply increase the lookback and calculate once again. Consider the following strategy:

@Configurable("")
public int InitialIntervalSize = 50;
@Configurable("")
public int swingHistory = 10;

private Object[] optInputs;
private final Deque<Double> swings = new ArrayDeque<Double>();
private final Deque<Long> swingTimes = new ArrayDeque<Long>();
private char[] symbols = new char[] {10102, 10103, 10104, 10105, 10106, 10107, 10108, 10109, 10110, 10111};

@Override
public void onStart(IContext context) throws JFException {
    this.indicators = context.getIndicators();
    this.history = context.getHistory();
    this.console = context.getConsole();
    this.chart = context.getChart(feedDescriptor.getInstrument());

    IIndicator indZigZag = indicators.getIndicator("ZigZag");
    optInputs = new Object[] { ExtZZDepth, ExtZZDeviation, ExtZZBackStep };

    if (chart != null) {
        chart.add(indZigZag, optInputs, new Color[] { Color.RED }, new DrawingStyle[] { DrawingStyle.LINE }, new int[] { 1 });
    }
    context.subscribeToFeed(feedDescriptor, this);
}

@Override
public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {

    try {
        int candlesBefore = InitialIntervalSize;
        int processedCandles = 0;
        swings.clear();
        while (swings.size() < swingHistory) {
            double[] zigzag = (double[]) indicators.calculateIndicator(feedDescriptor, new OfferSide[] { OfferSide.BID }, "ZIGZAG",
                    new AppliedPrice[] { AppliedPrice.CLOSE }, optInputs, candlesBefore, feedData.getTime(), 0)[0];
            List<ITimedData> feedElements = history.getFeedData(feedDescriptor, candlesBefore, feedData.getTime(), 0);
            for (int i = zigzag.length - 1 - processedCandles; i >=0; i--) {
                if (!Double.isNaN(zigzag[i])) {
                    swings.addFirst(zigzag[i]);
                    swingTimes.addFirst(feedElements.get(i).getTime());
                    if(chart != null){
                        ITextChartObject text = chart.getChartObjectFactory().createText("swing"+swings.size(), feedElements.get(i).getTime(), zigzag[i]);
                        int index = (swings.size() - 1) % (symbols.length);
                        text.setText(String.valueOf( symbols[index]), new Font(Font.DIALOG, Font.PLAIN, 20));
                        text.setColor(Color.BLUE);
                        chart.add(text);
                    }
                    if (swings.size() >= swingHistory) {
                        break;
                    }
                }
            }
            if (swings.size() >= swingHistory) {
                break;
            }
            candlesBefore+=InitialIntervalSize;
            processedCandles+=InitialIntervalSize;
            console.getOut().println("Not sufficient swing history, increasing candlesBefore to " + candlesBefore);
        }
        console.getOut().println(DateUtils.format(feedData.getTime()) + " swings: " + swings);
    } catch (JFException e) {
        e.printStackTrace(console.getErr());
    }

}


Attachments:
ZigZagSwingPrinter100.java [5.35 KiB]
Downloaded 126 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.
 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Mon 23 Dec, 2013, 10:46 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
thanks support, on face value that seems to be what I am looking for. I will go through your code over the Xmas break to understand it better.

Is using this format good performance wise? Is it any better than your previous suggestions?


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Thu 02 Jan, 2014, 09:49 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
PhoenixProject wrote:
Is using this format good performance wise? Is it any better than your previous suggestions?
There are multiple configurable parts such that you calculate the unnecessary values as little as possible. Simply play around with the strategy and see how it does with different parameters. Of course the strategy will perform faster if you will remove the chart visualizations, so consider adding an additional parameter which determines if you work with charts or not.


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Wed 08 Jan, 2014, 11:58 

User rating: 1
Joined: Mon 02 Dec, 2013, 11:32
Posts: 27
Location: AustraliaAustralia
I have been trying to add more of my code to your example, but can't seem to get the results i need.

I am used to selecting the element from the array by a number.
eg zigzag[1], zigzag[2]

but when i try to create some variables around this, i can't get the same values that output using "swings" in the print messages.

Essentially i think i need to pull values 8 and 9 from your example, so i tried to create variables for these swingvalue1 and swingvalue 2 - that i could then use for comparisons.

for (int i = zigzag.length - 1 - processedCandles; i >=0; i--) { 
                    if (!Double.isNaN(zigzag[i])) {
                        swings.addFirst(zigzag[i]);
                        swingTimes.addFirst(feedElements.get(i).getTime());
                       
                        if(chart != null){
                            ITextChartObject text = chart.getChartObjectFactory().createText("swing"+swings.size(), feedElements.get(i).getTime(), zigzag[i]);
                            int index = (swings.size() - 1) % (symbols.length);
                            text.setText(String.valueOf( symbols[index]), new Font(Font.DIALOG, Font.PLAIN, 20));
                            text.setColor(Color.BLUE);
                            chart.add(text);
                        }
                        if (swings.size() >= swingHistory) {
                            break;
                        }
                       
                    }
                    swingvalue1 = zigzag[8];
                    swingvalue2 = zigzag[9];
                }
                if (swings.size() >= swingHistory) {
                    break;
                }
                candlesBefore+=InitialIntervalSize;
                processedCandles+=InitialIntervalSize;
                console.getOut().println("Not sufficient swing history, increasing candlesBefore to " + candlesBefore);
            }
            console.getOut().println(DateUtils.format(feedData.getTime()) + " swings: " + swingvalue1 + ","+swingvalue2 );


Also if using the onFeedData - where should i be putting the rest of my code? eg other trade criteria checking, order placement etc - does it also have to go in this section or should it go in OnTick or OnBar?


 
 Post subject: Re: Pulling values from an indicator - Problems with my array Post rating: 0   New post Posted: Wed 08 Jan, 2014, 14:39 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Quote:
swingvalue1 = zigzag[8];
swingvalue2 = zigzag[9];

The values that you need are in the swings variable, thus to fetch the previous 2 swings (excluding the current one) you would need to do something like this after the while cycle:
swings.pollFirst(); // don't need the last value
swingvalue1 = swings.pollFirst();
swingvalue2 = swings.pollFirst();
Mind that if you need at most 3 values, then decrease InitialIntervalSize to say 30 and to swingHistory to 3.
PhoenixProject wrote:
Also if using the onFeedData - where should i be putting the rest of my code? eg other trade criteria checking, order placement etc - does it also have to go in this section or should it go in OnTick or OnBar?
If you only work with one feed, then you can do all the logic in the onFeedData - it simply allows you define the feed variables only once, thus making your code a bit more robust. Plus it provides more flexibility - here you could also switch to using a renko chart simply by changing the type of feedDescriptor in the parameter dialog.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com