|
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 the fractal signal? |
Guest
|
Post subject: how to get the fractal signal? |
Post rating: 0
|
Posted: Tue 03 Aug, 2010, 16:36
|
|
User rating: -
|
Hi,sir double [] macd0= indicators.macd(instrument, _currentPeriod, OfferSide.BID, IIndicators.AppliedPrice.MEDIAN_PRICE, 12, 26, 9, 0) ; double macd=macd0[0] double[] fr0=indicators.fractal(instrument,_currentPeriod,OfferSide.BID,5,0); double[] fr1=indicators.fractal(instrument,_currentPeriod,OfferSide.BID,5,1); double frc0=fr1[0]; double frc1=fr1[1]; _console.getOut().println("MACD="+macd); _console.getOut().println("frc0="+frc0); _console.getOut().println("frc1="+frc1);
macd is working but the fractal not worked. it display NaN. where I do somehting wrong?
how to get the fractal signal ?
many thanks benjamin
|
|
|
|
 |
API Support
|
Post subject: Re: how to get the fractal signal? |
Post rating: 0
|
Posted: Wed 04 Aug, 2010, 10:48
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, You did everything right, Double.NaN means that there is no value at that point. You need to find candle which has fractal minimum and/or maximum value. Please consider the following code: public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (instrument.equals(Instrument.EURUSD) && (period.equals(Period.TEN_SECS))){ double [] macd0= indicators.macd(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.MEDIAN_PRICE, 12, 26, 9, 0) ; double macd=macd0[0]; Double fractalMax = Double.NaN; Double fractalMin = Double.NaN; int i =0; while (fractalMax.isNaN() || (fractalMin.isNaN()) ){ double[] fractal = indicators.fractal(instrument,period,OfferSide.BID,5,i); if (!Double.isNaN(fractal[0])) fractalMax = fractal[0]; if (!Double.isNaN(fractal[1])) fractalMin = fractal[1]; i++; } console.getOut().println("MACD=" + macd); console.getOut().println("Fractal maximum: " + fractalMax + "; Fractal minimum: " + fractalMin); } }
|
|
|
|
 |
intery
|
Post subject: Re: how to get the fractal signal? |
Post rating: 0
|
Posted: Tue 17 Aug, 2010, 16:17
|
|
User rating: 0
Joined: Fri 20 May, 2011, 17:14 Posts: 4 Location: SpainSpain
|
Support wrote: Hi, You did everything right, Double.NaN means that there is no value at that point. You need to find candle which has fractal minimum and/or maximum value. Please consider the following code: Double fractalMax = Double.NaN; Double fractalMin = Double.NaN; int i =0; while (fractalMax.isNaN() || (fractalMin.isNaN()) ){ double[] fractal = indicators.fractal(instrument,period,OfferSide.BID,5,i); if (!Double.isNaN(fractal[0])) fractalMax = fractal[0]; if (!Double.isNaN(fractal[1])) fractalMin = fractal[1]; i++; }
This one show last formed fractal, Is possible to find previous fractals like second or third or earlier with this algorithm, or how to find them? thank you.
|
|
|
|
 |
API Support
|
Post subject: Re: how to get the fractal signal? |
Post rating: 0
|
Posted: Wed 18 Aug, 2010, 10:01
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Yes, it is possible. Use configurable parameter to select the number of fractal values back. Please consider the following code:
Using java Syntax Highlighting
public class FractalTest implements IStrategy {
private IEngine engine ;
private IConsole console ;
private IHistory history ;
private IContext context ;
private IIndicators indicators ;
private IUserInterface userInterface ;
@Configurable ("Number of Fractal values back")
public int valuesBack = 3;
public void onStart (IContext context ) throws JFException {
this. engine = context. getEngine();
this. console = context. getConsole();
this. history = context. getHistory();
this. context = context ;
this. indicators = context. getIndicators();
this. userInterface = context. getUserInterface();
}
public void onAccount (IAccount account ) throws JFException {
}
public void onMessage (IMessage message ) throws JFException {
}
public void onStop () throws JFException {
}
public void onTick (Instrument instrument, ITick tick ) throws JFException {
}
public void onBar (Instrument instrument, Period period, IBar askBar, IBar bidBar ) throws JFException {
if (instrument. equals(Instrument. EURUSD) && (period. equals(Period. TEN_SECS))) {
double[] macd0 = indicators. macd(instrument, period, OfferSide. BID, IIndicators. AppliedPrice. MEDIAN_PRICE, 12, 26, 9, 0 );
double macd = macd0 [0 ];
Double fractalMax = Double. NaN;
Double fractalMin = Double. NaN;
int maxCount = 0;
int minCount = 0;
int shift = 0;
while (maxCount < valuesBack || minCount < valuesBack ) {
double[] fractal = indicators. fractal(instrument, period, OfferSide. BID, 5, shift );
if (!Double. isNaN(fractal [0 ]) && maxCount < valuesBack ) {
fractalMax = fractal [0 ];
maxCount ++;
}
if (!Double. isNaN(fractal [1 ]) && minCount < valuesBack ) {
fractalMin = fractal [1 ];
minCount ++;
}
shift ++;
}
console. getOut(). println("MACD=" + macd );
console. getOut(). println("Fractal maximum: " + fractalMax + "; Fractal minimum: " + fractalMin );
}
}
}
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|