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.

Executing Trade on fractals
 Post subject: Executing Trade on fractals Post rating: 0   New post Posted: Mon 10 Oct, 2011, 22:52 

User rating: 0
Joined: Mon 10 Oct, 2011, 22:43
Posts: 1
Location: GB
Hello
Is there a way to automatically execute orders once a fractal appears.

I have reviewd the below code for printing the figures but is there a way to adapt this to execute trades based on when the fractal appears?


package jforex;

import com.dukascopy.api.*;

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);
      }
   }
}


 
 Post subject: Re: Executing Trade on fractals Post rating: 0   New post Posted: Tue 11 Oct, 2011, 08:56 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please see the following example how strategy executes trading based on indicator values:
https://www.dukascopy.com/wiki/index.php ... SMA_Simple


 

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