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.
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.
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).
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.