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.

problem for configurate void setStopLossPips
 Post subject: problem for configurate void setStopLossPips Post rating: 0   New post Posted: Thu 06 Dec, 2012, 11:36 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
hello support,

strategy scenario :

when signal buy occur the strategy open 3 position with label : long1, long2, long3 in a same time with same sl and 3 different tp.
i want to change my stoploss of the long2 when the tp of long1 is reached and change my stoploss of the long3 when the tp of long2 is reached.

i try to change my stoploss values as :

public void setStopLossPips(double stopLossPips) throws JFException {
         
            Instrument instr = order.getInstrument();
            double currentStopLoss = order.getStopLossPrice();
           
            if (order.isLong()){
            if(order.getLabel().equals("long1") && order.getState() == IOrder.State.CLOSED){
               if(order.getLabel().equals("long2")){
                  
               double newStopLoss = currentStopLoss + toPrice (generalPips, order.getInstrument());
               newStopLoss = round(newStopLoss, order.getInstrument());
               if(newStopLoss != currentStopLoss) {
               order.setStopLossPrice(newStopLoss);
               print("nsl:" + newStopLoss + "csl:" + currentStopLoss);
               }
            }
      }
   }
  }


i think a have a problem with this part of code : if(order.getLabel().equals("long1") && order.getState() == IOrder.State.CLOSED)
but i don't understand why?
Can you shed some light on this?

eric


 
 Post subject: Re: problem for configurate void setStopLossPips Post rating: 0   New post Posted: Thu 06 Dec, 2012, 12:24 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
the stop loss update starting with line 10 will never get executed, since the combination of the if statements in 8 and 9 will always yield false.


 
 Post subject: Re: problem for configurate void setStopLossPips Post rating: 0   New post Posted: Thu 06 Dec, 2012, 13:02 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
Quote:
the stop loss update starting with line 10 will never get executed, since the combination of the if statements in 8 and 9 will always yield false.


yes you're right this is why I included the if statement. but when the statements return true my sl don't move.

if i delete this part of code : if(order.getLabel().equals("long1") && order.getState() == IOrder.State.CLOSED)
my sl move without a problem.

see attached file


Attachments:
sl.png [22.58 KiB]
Downloaded 343 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: problem for configurate void setStopLossPips Post rating: 0   New post Posted: Thu 06 Dec, 2012, 13:16 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please consider adding additional print statements with the relevant values to trace which execution paths get taken and why.
Alternatively consider using JForex-SDK and debugging the strategy within an IDE, e.g. Eclipse or NetBeans.


 
 Post subject: Re: problem for configurate void setStopLossPips Post rating: 0   New post Posted: Thu 06 Dec, 2012, 14:54 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
i have just a little question :

when i write this code : if(order.getLabel().equals("long1") && order.getState() == IOrder.State.CLOSED)

the order.getState is applied for all orders or just the order with label "long1"?

if the order.getState is applied for all order, how can i applied for the order long1 only?


 
 Post subject: Re: problem for configurate void setStopLossPips Post rating: 0   New post Posted: Thu 06 Dec, 2012, 17:46 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ericbiz wrote:
the order.getState is applied for all orders or just the order with label "long1"?
IOrder represents a single order/position, thus - the latter.


 

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