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.

Calculating LOWEST HIGH from the last open position
 Post subject: Calculating LOWEST HIGH from the last open position Post rating: 0   New post Posted: Wed 14 Jul, 2010, 11:27 

User rating: 0
Joined: Wed 07 Jul, 2010, 17:54
Posts: 10
Dear support,

I am trying to get the 'Lowest High' for my strategy and having some troubles. First of all I created such a variable:

double max= indicators.max(instrument, defPeriod, OfferSide.BID, IIndicators.AppliedPrice.HIGH, 2, 0);

This variable returns me the highest values. The second part is more complicated. I want to get the Lowest of these Highs, but not over some specified period, but for the period from my last opened position. It implies that sometimes this 'Low of the Highs' will be calculated for e.g. 5 candles and sometimes for e.g. 15 candles.

could you give me some hint or idea, how could I get this? I think I should use something like

'public double getMin()'

and something with

'for (IOrder order : engine.getOrders(instrument)) {
if (order.getState() == IOrder.State.FILLED) {'

but have no idea how to implement this. I would be very grateful if you could help.

Thanks!


 
 Post subject: Re: Calculating LOWEST HIGH from the last open position Post rating: 0   New post Posted: Tue 27 Jul, 2010, 11:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
please consider the following code:
package forum;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IOrder.State;

public class ForumSandbox implements IStrategy {
   private IEngine engine;
   private IConsole console;
   private IHistory history;   
   
   Period period = Period.ONE_HOUR;
   Instrument instrument = Instrument.EURUSD;
   IOrder order = null;
   
   public void onStart(IContext context) throws JFException {
      this.engine = context.getEngine();
      this.console = context.getConsole();
      this.history = context.getHistory();      
            
       this.order = engine.submitOrder("order", this.instrument, OrderCommand.SELL, 0.001); 
   }

   public void onAccount(IAccount account) throws JFException {
   }

   public void onMessage(IMessage message) throws JFException {
   }

   public void onStop() throws JFException {
      if (this.order.getState() != State.CREATED && this.order.getState() != State.CANCELED)
         this.order.close();
   }

   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(this.instrument) || period != this.period) return;
       
       if (bidBar.getTime() < this.order.getCreationTime()) return;
       
       console.getOut().println("Min high value: " + getMinHigh());
    }
   
    private double getMinHigh() throws JFException{              
       long orderBarTime = history.getBarStart(this.period, this.order.getCreationTime());             
       long lastClosedBarTime = history.getBar(this.instrument, this.period, OfferSide.BID, 1).getTime();                  
       
       List<IBar> bars = history.getBars(this.instrument, this.period, OfferSide.BID, orderBarTime, lastClosedBarTime);
             
       ArrayList<Double> barHighs = new ArrayList<Double>();
       for (IBar bar : bars){
          barHighs.add(bar.getHigh());
       }
          
       double lowestValue = barHighs.get(0);
       for (Double barHigh : barHighs){
          lowestValue = barHigh < lowestValue ? barHigh : lowestValue;
       }                                                     
       return lowestValue;              
    }
}


 

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