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.

Determine if order was closed with profit
 Post subject: Determine if order was closed with profit Post rating: 0   Post Posted: Mon 10 Dec, 2012, 15:52 

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

i try to manage my risk in my strategy with a sample way, but i have a problem with my cycle.
the scenario is simple : with a winner trade, i increments my risk by one. with a loser trade , i decrease my risk by one.

but the cycle repeats itself because stategy returns to "void onaccount". so i would like that the strategy enters the cycle once.

could you help me please?

   
  @Override
    public void onAccount(IAccount account) throws JFException {
         
         
         double riskmax = 4;
         double riskAddLess = 1;
         double riskmin = 1;
         double baseBalance = account.getBalance();
         double currentBalance = account.getBaseEquity();
         
         for(int ip=0;ip<1;ip++){
            if (order.getState() == IOrder.State.CLOSED){
               if(baseBalance < currentBalance && risk < riskmax){
            
                  risk = risk + riskAddLess;
                  
            }else if(baseBalance > currentBalance && risk > riskmin){
            
         
                  risk = risk - riskAddLess;
         
            }
             }
      }
    print("risk:" +risk);
    }

thank.
eric


 
 Post subject: Re: void onAccount Post rating: 0   Post Posted: Mon 10 Dec, 2012, 15:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ericbiz wrote:
so i would like that the strategy enters the cycle once.
Exactly when do you want it to execute?


 
 Post subject: Re: void onAccount Post rating: 0   Post Posted: Mon 10 Dec, 2012, 17:12 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
when the order is closed with profit i want to increase my "double risk" . when the order is closed with loss i want to decrease my "double risk". well, my cycle "for" do that but the cycle repeat itself because the strategy read constantly the "void onAccount" and re enter in the cycle. when the new order is opened the cycle is stopped due at the if statement : if (order.getState() == IOrder.State.CLOSED).

when the order is closed the strategy go to the cycle increase or decrease but only once.

i hope is more clear. sorry for my english

eric


 
 Post subject: Re: void onAccount Post rating: 0   Post Posted: Tue 11 Dec, 2012, 08:27 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Then you need to move the logic to the IStrategy.onMessage method, e.g.:
   @Override
   public void onMessage(IMessage message) throws JFException {
      if(message.getType() == IMessage.Type.ORDER_CLOSE_OK && message.getOrder().getState() == IOrder.State.CLOSED){
         if(message.getOrder().getProfitLossInUSD() >= 0){
            //...
         } else {
            //...
         }
      }
   }
For more please refer to the article and the full workflow diagrams:
https://www.dukascopy.com/wiki/#Order_state


 
 Post subject: Re: void onAccount Post rating: 0   Post Posted: Tue 11 Dec, 2012, 12:24 

User rating: 1
Joined: Wed 07 Mar, 2012, 05:56
Posts: 101
Location: New CaledoniaNew Caledonia
ok thank for that.


 

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