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.

Entry at certain price intervals
 Post subject: Entry at certain price intervals Post rating: 0   New post Posted: Fri 30 Mar, 2012, 07:10 

User rating: 0
Joined: Fri 30 Mar, 2012, 06:38
Posts: 1
Location: Hong KongHong Kong
Dear Jforex support,

1. I am trying to compile a simple scalping strategy that will enter a trade at price intervals x.xx00, x.xx25, x.xx50 and x.xx75.

Is there a way to set those price intervals instead of manually entering all possible values?

2. long or short depends on the current Hour candle (configurable to other period too)
if current price > open price, long order only at ask price
else if open price = any price interval, no entry
else short order only at bid price

3. Second condition is if Stochastic >80, short only, and vice versa. Configurable stochastic parameters.

4. close the trade after a configurable time period.

5. 2 take profit levels, closes half the position each, once the first tp is hit sl is reset to break even.

Would you mind providing me with the complete code for these conditions? It would really help me to learn using this as a reference.
Many thanks in advanced!!


 
 Post subject: Re: Entry at certain price intervals Post rating: 0   New post Posted: Mon 02 Apr, 2012, 12:49 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
1. How do you plan to use the price intervals in the strategy?

2. Open long and short based on previous candle open price and current price:
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument != this.instrument) {
            return;
        }
       
        IBar previousBar = history.getBar(instrument, selectedPeriod, offerSide, 1);
        if(previousBar.getOpen() < tick.getAsk()){
            engine.submitOrder("order1", instrument, OrderCommand.BUY, amount, 0, slippage);
        } else if(previousBar.getOpen() < tick.getBid()){
            engine.submitOrder("order2", instrument, OrderCommand.SELL, amount, 0, slippage);
        }
    }

3. There is a strategy that uses Stochastic:
viewtopic.php?f=7&t=42704&p=60193&hilit=stochastic#p60193
4. Close position after some time preriod:
   
    @Configurable("Order duration")
    public int duration = 0;
    @Configurable("Order duration period")
    public Period period = Period.ONE_MIN;
         
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument != this.instrument) {
            return;
        }

        if((order.getState().equals(IOrder.State.FILLED) || order.getState().equals(IOrder.State.OPENED))
                && order.getFillTime() + period.getInterval() * duration < tick.getTime()) {
            order.close();
        }
    }

5. partial close
        if(order.getProfitLossInPips() > takeProfitPips) {
            if(order.getState() == IOrder.State.FILLED){
                order.close(order.getAmount() / 2);
                order.waitForUpdate(2000);
                order.setStopLossPrice(order.getOpenPrice());
                order.waitForUpdate(2000);
            }
        } else if (order.getProfitLossInPips() > takeProfitPips_2) {
            if(order.getState() == IOrder.State.FILLED){
                order.close();
            }
        }


 

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