Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
need help.

i want to create an algorithm in which i want to open a position in sell before closing of the market. and next day close it when it goes -1.5%. i tried to create something but no success. please help me.

7 responses

Here's a real simple algo that I believe does what you want? If the price does not go down by the desired 1.5% it just tries the next day. This is done with a limit order but also could be done by checking the price each minute in the 'handle_data' method.

Check out the backtest transaction log to see the transactions (not very many).

Thank you very much this is what im searching.

one thing if i wanted to close if the stock goes down to -2%. how would be?

To change the target to -2% simply change this line

TARGET_PROFIT = .015 # 1.5% profit

to this

TARGET_PROFIT = .02 # 2% profit

Thank you i got it. Just one more thing i tested lots of time and the leverage is to much high. Is there anyway to contain it.

If your leverage is growing you may want to verify you do not place any orders if there are outstanding orders. Also make sure you are using 'order_target_percent' and not one of the other methods which order a fixed amount of shares.

Attach a backtest if you wish and the folks on the forum here may be able to help you troubleshoot it.

im sorry for late. Well i tried to control leverage. but the problem is that i made a pipeline to control alfa and beta. but nothing is happening. the worst thing is that there is lot of volatility. please help me to fix it. thank.