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.

how to get previous fractal
 Post subject: how to get previous fractal Post rating: 0   New post Posted: Fri 18 May, 2012, 12:39 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
hello support,
this is my code for current fractal :

int valuesfractal  = 5;
int i =0;
Double fractalMax = Double.NaN;
Double fractalMin = Double.NaN;

while (fractalMax.isNaN() || (fractalMin.isNaN()) ){
      double[] fractal = indicators.fractal (instrument,period,OfferSide.BID,valuesfractal,i);
            if (!Double.isNaN(fractal[0]))
               fractalMax = fractal[0];   
            if (!Double.isNaN(fractal[1]))
               fractalMin = fractal[1];   
            i++;
         }


this is my code for get previous fractal :

int valuesfractal = 5;
int shift = 0;
int maxCount = 0;
int minCount = 0;
Double fractalMax10 = Double.NaN;
Double fractalMin10 = Double.NaN;

while (maxCount < valuesBack || minCount < valuesBack) {
             double[] fractal10 = indicators.fractal(instrument, period, OfferSide.BID,valuesfractal, shift);
                if (!Double.isNaN(fractal10[0]) && maxCount < valuesBack) {
                    fractalMax10 = fractal10[0];
                    maxCount++;
                }
                if (!Double.isNaN(fractal10[1]) && minCount < valuesBack) {
                    fractalMin10 = fractal10[1];
                    minCount++;
                }
                shift++;
            }


this is good way to find a previous fractal. but i need to retrieve a fractal following this condition with a loop :

if (fractalMax10 < fractalMax){
valuesBack !=2 but valuesBack=3
}
the loop is stopped when the fractalMax10 > fractalMax


 
 Post subject: Re: how to get previous fractal Post rating: 0   New post Posted: Fri 18 May, 2012, 12:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ericbiz wrote:
this is good way to find a previous fractal. but i need to retrieve a fractal following this condition with a loop :

if (fractalMax10 < fractalMax){
valuesBack !=2 but valuesBack=3
}
the loop is stopped when the fractalMax10 > fractalMax
I'ts unclear what you want to do here. Could you please explain this part more in detail?


 
 Post subject: Re: how to get previous fractal Post rating: 0   New post Posted: Fri 18 May, 2012, 14:50 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
sorry it's difficult for me to speak in english but i want to retrieve the fractalMax which more higher then current fractal.
it's not possible to do that using the variable valuesBack because somethime the previous fractalMax more higher appear one time before the current fractal, sometime he 's appear with the valuesBack more higher.

sorry for my english. please see the attached file. i hope it's more clear.

Attachment:
explanation.png [34.24 KiB]
Downloaded 470 times


 
 Post subject: Re: how to get previous fractal Post rating: 0   New post Posted: Sat 19 May, 2012, 19:08 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Try something like this:
package singlejartest;

import java.text.SimpleDateFormat;
import java.util.TimeZone;

import com.dukascopy.api.*;

public class FindMaxFractal implements IStrategy {

    IIndicators indicators;
    IConsole console;
    IHistory history;
   
    @Configurable("")
    public Instrument instrument = Instrument.EURUSD;
    @Configurable("")
    public Period period = Period.TEN_MINS;
    @Configurable("")
    public OfferSide side = OfferSide.BID;
    @Configurable("")
    public int barsOnSides = 10;
    @Configurable("")
    public int maxLookback = 1000;
   
    private static int MAX = 0;
    private static int MIN = 1;
   
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyy HH:mm:ss");
   
    @Override
    public void onStart(IContext context) throws JFException {
        indicators = context.getIndicators();
        console = context.getConsole();
        history = context.getHistory();
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
       
        //change shift to 0 to check fractal values starting from the current bar
        IBar currBar = history.getBar(instrument, period, side, 100);
       
        double[][] frac = indicators.fractal(instrument, period, side, barsOnSides, Filter.NO_FILTER, maxLookback, currBar.getTime(), 0);
       
        double maxValue = Double.MIN_VALUE, minValue = Double.MAX_VALUE;
        int maxShift = 0, minShift = 0;
       
        for(int shift = frac[0].length - 1; shift >=0; shift--){
            if(frac[MAX][shift] > maxValue){
                maxValue = frac[MAX][shift];
                maxShift = shift;
            }
            if(frac[MIN][shift] < minValue){
                minValue = frac[MIN][shift];
                minShift = shift;
            }
        }
        long minTime = history.getBar(instrument, period, side, minShift).getTime();
        long maxTime = history.getBar(instrument, period, side, maxShift).getTime();
       
        console.getOut().println(String.format("Max value=%.5f of shift=%s at %s; Min value=%.5f of shift=%s at %s",
                maxValue, maxShift, sdf.format(maxTime), minValue, minShift, sdf.format(minTime)));
    }

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

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar,
            IBar bidBar) throws JFException {}

    @Override
    public void onMessage(IMessage message) throws JFException {}

    @Override
    public void onAccount(IAccount account) throws JFException {}

    @Override
    public void onStop() throws JFException {}

}


Attachments:
FindMaxFractal.java [2.56 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.
 

Jump to:  

cron
  © 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