Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Possible Help with Order type

Hello,

I am a beginning trader and have no background in coding. However,I need to try to code an order type for a stategy that I am working on. The concept is simple.

If Price hits X
Then sell/buy at Y

I opened an account with FXCM and they assured me that they offered this order type which was called "if then" but the if works as an entry and the then, the exit.

Is there any way to code a simple order so I don't have to pay the programming team an arm and a leg?

Thanks!

Chris A

2 responses

Hey Chris, I've never delved into Forex trading but it looks like this is just a basic limit buy order followed by a limit sell order. A very crude implementation on Quantopian with regular stocks would be something like this:

def initialize(context):  
    context.limit_active = False  
    context.stock = sid(14848)  
    context.limit_buy = 15.05  
    context.limit_sell = 15.30  
    context.num_shares = 1000

def handle_data(context, data):  
    current_price = data[context.stock].price  
    if not context.limit_active and current_price <= context.limit_buy:  
        order(context.stock, context.num_shares)  
        log.info("%s shares of Yahoo bought" % context.num_shares)  
        context.limit_active = True  
    if context.limit_active and current_price >= context.limit_sell:  
        order(context.stock, -context.num_shares)  
        log.info("%s shares of Yahoo sold" % -context.num_shares)  
        context.limit_active = False  

This just orders some shares when the price drops below a certain price and then resells them once it rises above a different price.

Hi Grant,

Thanks for the help! However I would need to tweak it just a bit. Instead of the first limit buy....it would be more of a pending order for the second part which would be the limit buy or sell. For example:

If price = 92.50
Then Buy @ 92.30

Or

If price = 92.50
Sell @ 92.70

The Sell or buy would differ each time being higher or lower than "pending" price (92.50)

Could I tweak the above to compensate for this ?