SANTA CLARITA
Posts: 8 since Mar 2021
Thanks Given: 2
Thanks Received: 0
|
How would I create a code to automatically purchase and sell stock? I have already created a strategy. However, the strategy only communicates for me to be able to do backtesting with a floatingPL. I don’t think I am even close to making it automated yet. I am tempted to look into 3rd party software that automates the trading. I like to buy with one strategy. Then, I am interested in exiting the trade with an OCO bracket. A TOS manual I found references 1st Triggers OCO. I already do this manually. I found another comment that says 1st Triggers 3 OCO. First, I need to master 1 OCO. Also, I am not clear how an AutoOrder knows the timeframe that I am purchasing on. If it can be automated, can I place the order to repeat on the same stock? Run on a scanner and buy results that meet the criteria?
Also, I am wondering if there is code that I can use to sell based upon the current price instead of waiting for the close of a bar. If not, can I express the code of the exit to be based on a fraction of time… like 10 seconds… Again, I am unclear how auto order works. Thanks for any help you can give me.
I wrote some basic code below to test with to show that the software is working. When I run the code below, the sell doesn’t function right… I don’t think the or code is the right word for either or…
I think this is the wrong word…
def sell = close is less than or equal to EntryPrice()-0.20 ****¬OR**** close is greater than or equal to EntryPrice()*1.03;
I know that I have a zillion questions here. Any help will be appreciated. Thanks! EK
input price = FundamentalType.CLOSE;
def buy = PPS()."BuySignal" is true and close is greater than or equal to MovAvgExponentional(“length” = 200).”AvgExp”;
def sell = close is less than or equal to EntryPrice()-0.20 ¬OR close is greater than or equal to EntryPrice()*1.03;
AddOrder(OrderType.BUY_TO_OPEN, buy, name = “EK_Buy”);
AddOrder(OrderType.SELL_TO_CLOSE, sell, name = “EK_Exit”);
|