Problems creating simple Limit / Stop

Moderator: Moderator

Problems creating simple Limit / Stop

Postby ProfitProphet » Fri Aug 05, 2011 9:59 am

Hi,

Right, so I’ve been struggling with creating a (new) Stop and/or Limit for an existing Trade. I’m not sure why, since I can easily create Market- and Limit Entry Orders. I tried every combination, checked the values over and over again, included some optional values and even hardcoded the value-map entries, but when it comes to assigning an O2GRequest variable to the Request Factory’s “CreateOrderRequest”-method with the value-map, the variable simply remains null. Here’s the simplest form of the code I’m using:

Code: Select all
Using factory As O2GRequestFactory = mSession.getRequestFactory
   Using newValueMap As O2GValueMap = factory.createValueMap
      With newValueMap
         .setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder)
         .setString(O2GRequestParamsEnum.OrderType, Constants.Order.Stop)
         .setString(O2GRequestParamsEnum.OfferID, "1")
         .setString(O2GRequestParamsEnum.AccountID, myAccount.AccountID)
         .setString(O2GRequestParamsEnum.TradeID, myOpenTrade.TradeID)
         .setString(O2GRequestParamsEnum.BuySell, Constants.Sell)        'Since original Trade was a "Buy"
         .setString(O2GRequestParamsEnum.Amount, myOpenTrade.Amount)
         .setString(O2GRequestParamsEnum.Rate, myOpenTrade.OpenRate - 0.005)
         Using theRequest As O2GRequest = factory.createOrderRequest(newValueMap)
            Call mSession.sendRequest(theRequest)
         End Using
      End With
   End Using
End Using


Hopefully I’m just missing something simple.
ProfitProphet
 
Posts: 3
Joined: Thu Jul 21, 2011 3:04 pm

Re: Problems creating simple Limit / Stop

Postby sunshine » Mon Aug 08, 2011 2:53 am

Please use setInt for the amount:
Code: Select all
valuemap.setInt(O2GRequestParamsEnum.Amount, myOpenTrade.Amount)

rather than setString:
Code: Select all
valuemap.setString(O2GRequestParamsEnum.Amount, myOpenTrade.Amount)


Besides, if RequestFactory returns an error, you can check it using the code:
Code: Select all
string error = factory.getLastError();
sunshine
 

Re: Problems creating simple Limit / Stop

Postby ProfitProphet » Mon Aug 08, 2011 7:02 am

Hi Sunshine,

Thanks for the reply. I’ve made the suggested change, but that didn’t solve the issue. I did take your last comment to heart and peeked at the factory’s last error message which stated: “Order Type ‘LS’ does not exist”, so I’m guessing the ‘Constants.Order.Stop’-enumeration isn’t mapped to the Trading Server?

Kind Regards
ProfitProphet
 
Posts: 3
Joined: Thu Jul 21, 2011 3:04 pm

Re: Problems creating simple Limit / Stop

Postby sunshine » Wed Aug 10, 2011 4:30 am

It looks like the problem in ForexConnect. I've informed the development about it. I'll keep you informed.
Sorry for the inconvenience.
sunshine
 

Re: Problems creating simple Limit / Stop

Postby ProfitProphet » Wed Aug 10, 2011 8:44 am

Thanks Sunshine,

I played around with the values and was able to successfully place a Stop (for an existing trade) by simply replacing
Code: Select all
.setString(O2GRequestParamsEnum.OrderType, Constants.Order.Limit)

with
Code: Select all
.setString(O2GRequestParamsEnum.OrderType, “S”)

(not to be confused with the “S” for the Buy/Sell-enumeration)

Regards
ProfitProphet
 
Posts: 3
Joined: Thu Jul 21, 2011 3:04 pm

Re: Problems creating simple Limit / Stop

Postby sunshine » Thu Aug 11, 2011 8:02 am

It looks like you have found a workaround for the issue.
Anyway, developers will fix the defect in the next release of the API. Thank you for the reporting the issue!
sunshine
 

Re: Problems creating simple Limit / Stop

Postby Bebbspoke » Tue Oct 11, 2011 7:47 am

Please would some explain - in plain english the CORRECT nomenclature for the following operations in FXConnect: -

1/ Long/Up/Buy market (arbitary figures): - I set a STOP LOSS at 1.2020, I set a LIMIT at 1.2090 and I set my ENTRY at 1.2040; - the current market price is at 1.2030 some ten pips BELOW my ENTRY...

2/ Short/Down/Sell market (arbitary figures): - I set a STOP LOSS at 1.5080, I set a LIMIT at 1.5010 and I set my ENTRY at 1.5060: - the current market price is at 1.5070 some ten pips ABOVE my ENTRY...

PLEASE could someone give CLEAR guidance here, thank you.

O2Go might have been a pain at times but at least it did not require to be told which direction one is expecting the market to go in...

And to the gentleman who, in his footer, implies that the interpretation of indicators is more of an art than a science - I strongly recommend that he spends a while off the trading floor, takes a break from software writing and spends a while stuying proper mathematics...

Cheers, Bebbspoke
User avatar
Bebbspoke
FXCodeBase: Confirmed User
 
Posts: 170
Joined: Tue Aug 16, 2011 4:04 am
Location: Walton on the Naze UK

Re: Problems creating simple Limit / Stop

Postby sunshine » Wed Oct 12, 2011 7:34 am

When you create an entry order, you should determine the type of the order (SE,LE) depending on the side (buy or sell) and position of the order price against the market (please read more about entry order types here). The order type must be sent in the order request since the server requires it.
We've prepared the example on how to create an entry order where the order type is determined automatically. You can find the example here: http://fxcodebase.com/wiki/index.php/Cr ... %28.NET%29
sunshine
 

Re: Problems creating simple Limit / Stop

Postby chimpy » Mon Jan 20, 2014 10:11 pm

sunshine wrote:When you create an entry order, you should determine the type of the order (SE,LE) depending on the side (buy or sell) and position of the order price against the market (please read more about entry order types here). The order type must be sent in the order request since the server requires it.
We've prepared the example on how to create an entry order where the order type is determined automatically. You can find the example here: http://fxcodebase.com/wiki/index.php/Cr ... %28.NET%29



Hi sunshine. Do you have an example of an entry Market order at best available price.
Also, do you know off had how I will pass in command line variables for such things like the unit size, stop limit and other variables, or any other way to do this with .NET?
Or would a better approch be to use javascript, in that case do you have a code example I could look at. Thanks Chimpy
chimpy
FXCodeBase: Initiate
 
Posts: 112
Joined: Fri Jun 10, 2011 10:32 am

Re: Problems creating simple Limit / Stop

Postby Gennadiy » Wed Jan 22, 2014 6:10 am

Hello chimpy,

Also, do you know off had how I will pass in command line variables for such things like the unit size, stop limit and other variables, or any other way to do this with .NET?

You could pass variables in command line using our samples for C#.
Find samples in the ForexConnect API directory \samples\cs.
You can use them to write your own program.
Also you could find articles about trading commands (with code snippets) here. It may be helpful.

Here you could find article about using variables with command line in C# (args).
Gennadiy
 


Return to ForexConnect API

Who is online

Users browsing this forum: No registered users and 13 guests