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.

Sell existing positions at profit at any pivot point
 Post subject: Sell existing positions at profit at any pivot point Post rating: 0   New post Posted: Wed 31 Jul, 2013, 17:25 

User rating: 0
Joined: Mon 19 Dec, 2011, 14:21
Posts: 12
Location: SwitzerlandSwitzerland
Hello,

I want to sell all open positions in profit if price touch any Daily pivot line. My strategy works OnBar and i use OnTick to exit. My code has no compilation error but doesn't exit the winning positions.
Any suggestion to correct the problem ?
Thanks for any help...

 public void onTick(Instrument instrument, ITick tick) throws JFException {
       
       
         IBar DpivotBar = history.getBar(instrument, Period.DAILY_SUNDAY_IN_MONDAY, offerSide, 1);
         IBar WpivotBar = history.getBar(instrument, Period.WEEKLY, offerSide, 1);
         IBar MpivotBar = history.getBar(instrument, Period.MONTHLY, offerSide, 1);
         double bid = history.getLastTick(instrument).getBid();
         double ask = history.getLastTick(instrument).getAsk();
         double DP  = getPivotPrice(Pivot.P, DpivotBar);
         double DS1 = getPivotPrice(Pivot.S1, DpivotBar);
         double DS2 = getPivotPrice(Pivot.S2, DpivotBar);
         double DS3 = getPivotPrice(Pivot.S3, DpivotBar);
         double DR1 = getPivotPrice(Pivot.R1, DpivotBar);
         double DR2 = getPivotPrice(Pivot.R2, DpivotBar);
         double DR3 = getPivotPrice(Pivot.R3, DpivotBar);
         
        if (bid == DS3 || bid == DS2 || bid == DS1 || bid == DP|| bid == DR1|| bid == DR2 || bid == DR3  ) {
        for (IOrder ord : engine.getOrders(instrument)) {
           
           if(order.getProfitLossInPips() >= 0) {
                    closeAllPositions();
                   
         
            }
        }
        }
        }
       
   


 
 Post subject: Re: Sell existing positions at profit at any pivot point Post rating: 0   New post Posted: Wed 31 Jul, 2013, 20:25 
User avatar

User rating: 11
Joined: Tue 05 Feb, 2013, 10:39
Posts: 104
Location: Romania, Iasi
Edbegood wrote:
Hello,

I want to sell all open positions in profit if price touch any Daily pivot line. My strategy works OnBar and i use OnTick to exit. My code has no compilation error but doesn't exit the winning positions.
Any suggestion to correct the problem ?
Thanks for any help...

 public void onTick(Instrument instrument, ITick tick) throws JFException {
       
       
         IBar DpivotBar = history.getBar(instrument, Period.DAILY_SUNDAY_IN_MONDAY, offerSide, 1);
         IBar WpivotBar = history.getBar(instrument, Period.WEEKLY, offerSide, 1);
         IBar MpivotBar = history.getBar(instrument, Period.MONTHLY, offerSide, 1);
         double bid = history.getLastTick(instrument).getBid();
         double ask = history.getLastTick(instrument).getAsk();
         double DP  = getPivotPrice(Pivot.P, DpivotBar);
         double DS1 = getPivotPrice(Pivot.S1, DpivotBar);
         double DS2 = getPivotPrice(Pivot.S2, DpivotBar);
         double DS3 = getPivotPrice(Pivot.S3, DpivotBar);
         double DR1 = getPivotPrice(Pivot.R1, DpivotBar);
         double DR2 = getPivotPrice(Pivot.R2, DpivotBar);
         double DR3 = getPivotPrice(Pivot.R3, DpivotBar);
         
        if (bid == DS3 || bid == DS2 || bid == DS1 || bid == DP|| bid == DR1|| bid == DR2 || bid == DR3  ) {
        for (IOrder [b]ord[/b] : engine.getOrders(instrument)) {
           
           if(order.getProfitLossInPips() >= 0) {
                    closeAllPositions();
                   
         
            }
        }
        }
        }
       
   


That variable doesn't make sense. (Ord)
Either way this is a Visual JForex board... try asking in the Strategies board.

Cheers


 

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