Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Market Bracket Orders with Pips instead of Price #145

Closed
Jammawind opened this issue Jun 27, 2019 · 7 comments
Closed

Creating Market Bracket Orders with Pips instead of Price #145

Jammawind opened this issue Jun 27, 2019 · 7 comments

Comments

@Jammawind
Copy link

Hello,

Is there a way to make StopLoss and TakeProfit orders as a pip difference based on the Market order instead of a set price.

The current method only allows you to put in a price for the StopLoss and Take Profit. I would like to be able to use a constant SL and TP for my trades.

Thank you,
Artis Johnson

@hootnot
Copy link
Owner

hootnot commented Jun 27, 2019

Hi,

Asuming you use the contrib.request classes: I took a quick look and saw that for TrailingStopLossOrderRequest the distance parameter is available. But not for the classes you mention. I will have a look at it somewhere next days

@gkourogiorgas
Copy link

Any updates? I can use distance in stoplossOnFill and set stop loss relative to the opening price of the trade. Is there anything new on the take profit front? What is the workaround?

@hootnot
Copy link
Owner

hootnot commented Nov 20, 2019

it is a few lines of code to calculate things in a way that it can be handled in an order request. But I will leave that to the programmer

@gkourogiorgas
Copy link

gkourogiorgas commented Nov 20, 2019

How about this:

p1={
    "order": {
    "type":"MARKET",
    "timeInForce": "FOK", 
    "instrument": "EUR_USD"
   , "units": "-100",
    "positionFill": "DEFAULT"
    } 
    }
r = orders.OrderCreate(accountID=accountID, data=p1)
rv=client.request(r)

u1={
  "takeProfit": {
    "timeInForce": "GTC",
    "price": str(float(rv['orderFillTransaction']['tradeOpened']['price'])-0.0001)
  },
  "stopLoss": {
    "timeInForce": "GTC",
    "price": str(float(rv['orderFillTransaction']['tradeOpened']['price'])+0.01)
  }
}
r = trades.TradeCRCDO(accountID=accountID,
                                 tradeID=rv['orderFillTransaction']['tradeOpened']['tradeID'],
                                  data=u1)
client.request(r)

@hootnot
Copy link
Owner

hootnot commented Nov 20, 2019

Feel free to program it the way you like. The examples in https://github.com/hootnot/oandapyV20-examples show a clear example in src/contrib_mo_tp_sl.py using the contrib classes:

EUR_USD_STOP_LOSS = 1.05
EUR_USD_TAKE_PROFIT = 1.10

# The orderspecs
mktOrder = MarketOrderRequest(
    instrument="EUR_USD",
    units=10000,
    takeProfitOnFill=TakeProfitDetails(price=EUR_USD_TAKE_PROFIT).data,
    stopLossOnFill=StopLossDetails(price=EUR_USD_STOP_LOSS).data
)
print("Market Order specs: \n{}".format(json.dumps(mktOrder.data, indent=4)))

# create the OrderCreate request
r = orders.OrderCreate(accountID, data=mktOrder.data)

@gkourogiorgas
Copy link

I see. Can you use distance for stop loss? In the API doc it doesn't mention distance in TP, unfortunately.

@hootnot
Copy link
Owner

hootnot commented Nov 21, 2019

OANDA doesn't support the distance parameter in a TP, see #147 .

But you can write your own class or subclass TakeProfitDetails class and make it handle the distance the you like it.

@hootnot hootnot closed this as completed Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants