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.

void close() Coding
 Post subject: void close() Coding Post rating: 0   New post Posted: Mon 09 Feb, 2009, 22:47 

User rating: 0
Joined: Mon 09 Feb, 2009, 22:35
Posts: 5
Hello everyone,

Would anyone happen to have just a general code for closing orders? The "simple strategy" offered here, while helpful, closes out orders with stop and limit orders, so I am a little lost on the closing part of my code as it uses indicators to do so. According to the Duka site, it should start out with void close(), but from there the format is a bit foreign to me. If someone might have a snippet, just something simple like two moving averages to close an order, it would greatly help. From there I can probably figure it out.

Thanks everyone,
Matt


 
 Post subject: Re: void close() Coding Post rating: 0   New post Posted: Tue 10 Feb, 2009, 10:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
to close the order you need to call .close() method

    if ("some condition is true") {
        order.close();
    }

The same method cancels pending orders (limit and stop orders)


 
 Post subject: Re: void close() Coding Post rating: 0   New post Posted: Thu 12 Feb, 2009, 22:13 

User rating: 0
Joined: Mon 09 Feb, 2009, 22:35
Posts: 5
I have been playing with the snippet of code you gave, however it keeps giving me an error: order cannot be resolved. This is the only error that shows up. The exact code I had in was this:

if (diff>1) {
order.close();
}
Am I using the correct expression - order.close()? Is there more to it? Do I need to incorporate a Void statement before hand?

Thanks again for your time.

Matt


 
 Post subject: Re: void close() Coding Post rating: 0   New post Posted: Fri 13 Feb, 2009, 16:35 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
That was just the example of how to close any order. Of course "order" is not some predefined variable or something like that, you should change it to your actual order. For example you can save it in variable when you call submitOrder method, or you can get it with engine.getOrder("label").
"order cannot be resolved" means, that you don't have such a variable named "order"


 
 Post subject: Re: void close() Coding Post rating: 0   New post Posted: Wed 18 Feb, 2009, 20:51 

User rating: 0
Joined: Mon 09 Feb, 2009, 22:35
Posts: 5
Thanks for the reply. I have been trying to figure this out, but with the Duka API page not giving any examples, it makes breaking into jfx tough. I have pasted the code I use in MT4 to close my orders. If it is not too much to ask, would you mind translating it into jfx? I am not sure if it will make a difference, but I am an External Manager with you guys, so if I can figure this out, it would be good for all of us. Also, once I have the basic template together, I would be happy to post it here to help anyone else who might need complete system code examples.

The value "ma" (found in the pasted code below) is a moving average, for which I already know how to write the code.

Thanks in advance for your time.
Matt

if(OrderType()==OP_BUY)   
           {         
           if ((iOpen(Symbol(),PERIOD_M1,1)>ma && iClose(Symbol(),PERIOD_M1,1)<ma && Close[1]-OrderOpenPrice()>=200*Point) ||
             (iClose(Symbol(),60,1)<ma1) || (Hour()==22 && DayOfWeek()==5))
                {
                 RefreshRates();
                 OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),1,Violet);
                 
                 
                    }
                 }
     
         if(OrderType()==OP_SELL)   
           {
           
            if ((iOpen(Symbol(),PERIOD_M1,1)<ma && iClose(Symbol(),PERIOD_M1,1)>ma && OrderOpenPrice()-Close[1]>=200*Point)||
           (iClose(Symbol(),60,1)>ma1) || (Hour()==22 && DayOfWeek()==5))
              {
                 RefreshRates();
                 OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),1,Violet);
                 
                 
                    }
                 }
              }


 

Jump to:  

cron
  © 1998-2024 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