Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Auto Trade with Study Alerts

Posted by bughatti 
Auto Trade with Study Alerts
February 11, 2016 02:07PM
All, I know this might stir up some fuss but I wanted to ask around about this. I am looking at this from a purely technical perspective with coding/software and nothing more.

Has anyone tried playing around with very minimal indicators and creating automatic buy/sell orders based off of studies and actually had success?

What I am testing is to find out if the larger auto buy/sell profits would out way the small loses/commission fees. Right now I am playing with EMA crossing up and down and making an auto trade from that indicator alone. I just started playing with it in the last hour so I can not show any failure/success stories but would be interested if anyone has suggestions on better indicators or scripts that could possibly make this successful!
Re: Auto Trade with Study Alerts
February 11, 2016 02:55PM
I've never tried it. One positive about system trading would be removing the emotional entry/exits that plague many traders (me included).
Re: Auto Trade with Study Alerts
February 11, 2016 09:30PM
Bughatti,

I have never tried coding strategies and automated algo trading but you might want to read this book:

[www.amazon.com]

It is about trading strategies that have been coded and tested and allegedly found to work. Following is a synopsis:

[files.meetup.com]

Following is an algo trading system that supposedly has a good performance record, though I haven't tried it:

[www.algotrades.net]

Usually algo trading is based on very complex algorithms and requires complex coding, and simple technical indicator based algo trading doesn't really work otherwise computer software programmers would be printing millions en masse. Most of the technical indicators have an inherent flaw that they are lagging, and don't take into account the overall market context and money management aspect of trading, hence poor performance.



Edited 1 time(s). Last edit at 02/11/2016 10:00PM by tanman.
Re: Auto Trade with Study Alerts
February 12, 2016 07:14AM
Figure out a automated trade system in TOS based on the "e" system smiling smiley
Re: Auto Trade with Study Alerts
February 12, 2016 07:57PM
bughatti, I admire what you're trying to do. Without Experimenters like yourself, we'd never have had indicators, not one! You probably expected me to come along sooner or later spinning smiley sticking its tongue out . But I've been looking at your idea ever since because you emphasize simple and I like that. My thoughts (you likely already know this stuff):

1. Simple is best, but often difficult to achieve.
2. Having more signals to evaluate is better than fewer signals. One way to get more sigs is to drastically shorten any MA or EMA lengths in your code. For example, changing RSI(Wilders) from 14-70-30 to 2-70-30 gets more signals. Or, in a basic PPO, changing 9-26 to 2-26 does the same.
3. The chosen indicators should be as “unrelated” as possible, to avoid colinearity and to promote independent views. So, I probably wouldn't use a PPO with a MACD because the only difference is that the first is a percentile difference between EMA values and the second is integer difference.
4. Writing a potentially viable automated trading code should be a multi-step process. In Step1 we have a Theory, in your post defined as EMA crosses as trade signals. So, Step2 is to write code to evaluate how often the Theory is True. If the Theory proves sufficiently True, Step3 is to write code to quantify its truth, i.e., How much money do we make by applying this Theory over time? That step will also include optimizing HoldTimes, TakeProfit levels, and StopLoss levels. When that's done, forward-test in realtime.
5. A Lookback element should be present. I'm not talking about evaluating previous signal gains/losses, since that work's already done above. I mean having a look at the recent local terrain. Itty-bitty candles come in bunches; bigbaddy candles come in bunches. So Step4 is separate code to identify the nature of that, i.e., How many to a bunch? What other factors might decide the start/end of a bunch? And Step5 is building that finding into the trading code. This helps to optimize gains over losses.
6. Finally- and I'm not recommending this because most traders would never have the stomach for it, esp those in high-gain high-loss markets like equity options or binary options. It's what I call a Truncated Martingale (TM). It's been around for years. It has its supporters and its critics (on one forum somebody said, “It's only for people with lousy algorithms.”) However, it's mathematically sound. For example, if your final best effort at coding your automated algo only wins 40% of the time, the TM can still make it profitable. A normal Martingale is where every time you lose you double your bet; if you win, your next bet is back at some predefined baseline. But this means an extended bad run can bankrupt the account because you have limited capital. A TM, however, limits the doubling iterations to three or at most four levels. I don't gamble but suppose we have $10,000 at a roulette table. Our first bet would be $400 (4%); if we lose, second bet would be $800 (8%); if we lose again, third bet would be $1600 (16%) and we'd stay at that level 'til we win. Anytime we win, our next bet starts back at the $400 level. This system is a hunting-oscillator, which would be much more dangerous except that it's tempered by the iterative limits, much the way that a wobbly train's hunting oscillation is tempered by the sloped wheel design and speed limits. But it's still very dangerous because its oscillatory limits are roughly between 7x and 0.1x (assuming that each losing bet cost you your entire bet and each winning bet tripled your bet, which is ridiculous for trading purposes). So in the course of this kind of betting our starting acct value of $10,000 will range between $70,000 and $100. I've actually tested it with $250 of play money in online roulette and consistently took the house for about $1700 every 45 minutes, with my account sometimes dropping as low as $40 in the process; a real life casino would- ahem- have certain mitigating factors. More realistically, in trading, we'd want to bias our TakeProfit to something greater than our StopLoss, and that ratio will determine the limits of the function. Anytime we near the upper limit, our code should then modify our trade sizes (not the 4-8-16% levels) based on our current balance times the 4-8-16% levels. Like I said, I'm not recommending it but thought maybe you'd never heard of it.
7. I've never written automated algos. Frankly, I'm terrified of them because they can so quickly drain an account if something goes wrong. Of course, a check against this is a StopRun piece of code if/when the acct loses a certain amount.
8. Finally, what I've been looking at for you is a PPO/RSI combination. Visually, it's intensely appealing. Just run RSI(Wilders) at 2-70-30 and merge it with the PPO study below (TDA doesn't have a PPO). To merge, load the studies in EditStudies mode then hover over one and use the triangular arrow to merge. You'll see two things- when plots “appear” to come together at an extreme it signals a move; and when they cross it signals a move. I say “visually” appealing because I've yet to figure out how to tell the software to see it because the PPO and RSI values are actually quite different. Maybe you can work it out.
EDIT for Language change re:candle sizes, as original may have been inadvertently offensive- sorry if it was

So good luck, bugatti, and I hope you keep experimenting!
#Basic PPO code
declare lower;
input price = close;
input L1 = 2;
input L2 = 26;
plot myPPO = (ExpAverage(price,L1)-ExpAverage(price,L2))/ExpAverage(price,L2);

Gamblers roll the dice; Traders load the dice.



Edited 1 time(s). Last edit at 02/12/2016 09:33PM by baffled1.
Re: Auto Trade with Study Alerts
February 12, 2016 09:34PM
bughatti, this helps with finding ittybittys and bigbaddys start/end patterns.
declare lower;
input cutoff = 0.25;
input lookback = 50;
plot candles = high-low;
plot myzero = highest(candles,lookback)*cutoff;

Gamblers roll the dice; Traders load the dice.
Re: Auto Trade with Study Alerts
February 13, 2016 01:28PM
All readers,

I posted an algo trading script before in the thinkscript forum but since then I have modified it to give a buy signal only in an uptrend and sell signal only in a downtrend of the symbol, which has eliminated some losing signals. It uses stochastics, volume average, on balance volume, and trend determination to give signals.

I haven't programmed the stop loss and exit yet but you can code ATR x 2 below entry price as stop loss and 2 closes below the 8 EMA as exit, and incorporate auto buy and auto sell commands to make it a fully automated trading algo script for paper trading and educational purposes. You will also have to program size of shares traded according to paper account size. You can also program the trend and ADX of SPY in it so it buys to open only if SPY is in uptrend and ADX > 20 and sells to open only if SPY is in a downtrend and ADX > 20. That should improve the performance. Market internals can also be programmed so it trades according to market context.

The script generates most signals on 1 minute chart, but it gives signals on any time frame. It would be very interesting if someone can back test this script for multiple symbols and see how it performs over various time frames for the last few years. Unfortunately I am just a beginner coder and it will be too complicated for me to make all the suggested additions to this script or to back test it for research. Here is the modified basic script for anyone interested. This script is for educational purposes only and it is not recommended to use this script for trading any equity with real money:


input inputStochLong = 22;
input inputStochShort = 78;

# return %k for going long or short on stochastics
def StochLongFast = StochasticFull(80, 20, 10, 10, high, low, close, 3, AverageType.SIMPLE).FastK;
def StochLongFull = StochasticFull(80, 20, 10, 10, high, low, close, 3, AverageType.SIMPLE).FullD;

def longOneFilter = StochLongFast < inputStochLong;
def longTwoFilter = StochLongFull < 18;
def shortOneFilter = StochLongFast > inputStochShort;
def shortTwoFilter = StochLongFull > 82;

# define average voume
def AvgVol = Average(volume, 6);
def VolUP = volume > AvgVol and volume > volume[1] * 0.75;

# define combined trend
def MA1 = ExpAverage(close, 8);
def MA2 = ExpAverage(close, 21);
def MA3 = ExpAverage(close, 50);
def MA4 = ExpAverage(close, 200);
def upTrend = MA1 > MA2 and close > MA3;
def dnTrend = MA1 < MA2 and close < MA3;

# define OBV signal
def OBV = TotalSum(Sign(close - close[1]) * volume);
def OBVUP = OBV > OBV[1];
def OBVDN = OBV < OBV[1];

# define long and short signals
def LongSignal1 = VolUP[1] and OBVUP and close > MA4 and longOneFilter[1] and StochLongFast[1] >= StochLongFast[2];
def LongSignal2 = volume[2] > AvgVol[2] and OBVUP and close > MA4 and longTwoFilter[1] and StochLongFull[1] < StochLongFull[2];
def ShortSignal1 = VolUP[1] and OBVDN and close < MA4 and shortOneFilter[1] and StochLongFast[1] <= StochLongFast[2];
def ShortSignal2 = volume[2] > AvgVol[2] and OBVDN and close < MA4 and shortTwoFilter[1] and StochLongFull[1] > StochLongFull[2];

# show up arrow for buy signal and down arrow for sell signal
plot SignalBuy = if LongSignal1 and !dnTrend then low else if LongSignal2 and !dnTrend then low else Double.NaN;
plot SignalSell = if ShortSignal1 and !upTrend then high else if ShortSignal2 and !upTrend then high else Double.NaN;
SignalBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SignalBuy.AssignValueColor(Color.UPTICK);
SignalSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SignalSell.AssignValueColor(Color.RED);

# show alert and make sound
Alert(SignalBuy, " TIME TO GO LONG", Alert.BAR, Sound.Bell);
Alert(SignalSell, " TIME TO GO SHORT", Alert.BAR, Sound.Bell);



Edited 1 time(s). Last edit at 02/13/2016 01:31PM by tanman.
Re: Auto Trade with Study Alerts
February 16, 2016 03:45PM




Baffled1, your code does seem to be spot on

going to look at it from other time periods



Edited 4 time(s). Last edit at 02/16/2016 04:31PM by bughatti.
Re: Auto Trade with Study Alerts
February 16, 2016 05:56PM
bughatti Wrote:
-------------------------------------------------------
Baffled1, your code does seem to be spot on
> going to look at it from other time periods
==============================================
B, glad you found it helpful. Waiting to see what you think for other TFs.


Gamblers roll the dice; Traders load the dice.
Re: Auto Trade with Study Alerts
February 16, 2016 06:20PM
Here is a 10d 30 min chart. My circles are a little off but as you can see a ppo cross below 10 and above 90 are good indicators, that is of coarse if I am even reading the charts right -------> still a nub smiling smiley

Re: Auto Trade with Study Alerts
February 16, 2016 06:22PM
Bugatti, I just found an "anomaly" in the PPO/RSI merger and feel I should share with you. Slowly scroll back thru time and the relationships between RSI and PPO change, so that a meetup signal is no longer a meetup signal. However, on the good side, that same scrolling causes other good meetup signals to appear. So no matter where you are in scrolling, a meetup is a good signal. Anyway, to debug this issue, I'm going to make another try at putting it all into one code so we can get alerts out of it (arrows, sound or whatever). Might be awhile- as I said before, numeric differences are a problem. PPO lim is +/- infinity, RSI lim is just 0-100. The result- if I get it right- will likely sacrifice some of those good signals, but at least it'll be more consistent. Almost making my head explode just thinking about what I have to do...

Gamblers roll the dice; Traders load the dice.
Re: Auto Trade with Study Alerts
February 16, 2016 06:30PM
not sure if its doable, but what I have scene every day since I have been on think or swim is that there are at least 4 good 5 point trends throughout the day, this is from 6 am CST when I get on all the way to 11pm CST when I go to bed. If I could catch at least 4 good 5 point runs, that would be great.

Sorry if I am asking to much here, reign me back in if need be!!!!!!!
Re: Auto Trade with Study Alerts
February 16, 2016 06:35PM
Baffled1,

I have tried similar indicator overlays before (for example On Balance Volume and ADX) but the signals are just an illusion i.e. appear when you look back but don't appear in real time due to the anomaly you mentioned. By the way Wendy Kirkland's P3 trading system is based on a similar principle and I think works really well for swing trading, but she uses different indicators. You can google the videos.
Re: Auto Trade with Study Alerts
February 16, 2016 06:47PM
what about something along the lines of when RSI is above 90 or below 10 and SMA 4 crosses SMA 7
Re: Auto Trade with Study Alerts
February 17, 2016 07:20AM
Tanman, thanks for Wendy Kirkland idea. Yes, I just watched /ES awhile on 5m and is tricky to use that earlier algo.
bughatti, I was able to cure the problem as I mentioned and as Tanman described, but with a couple of sacrifices, as well as a couple of benefits. You can do as before- tack this code onto the bottom of the RSI code (reset RSI to 2-70-30 as before). Crosses, in my opinion, are not as flashy anymore, but maybe you'll see something in where they occur. Meetups are not as frequent, but let me add: when exact meetups do happen, they are POWERFUL. Also, near-meetups are very good (you'll have to decide what constitutes a "near-meetup"winking smiley. To me, those two things are the sweet spots. And the real advantage here- getting back to why you started this thread- is that the thing can now be coded for Buy and Sell in your auto-trade script. And no, you're not asking too much! I learn from this stuff!
input L1 = 2;
input L2 = 26;
input myrange = 200;
def myPPO = (ExpAverage(price,L1)-ExpAverage(price,L2))/ExpAverage(price,L2);
def highestRSI = highest(RSI,myrange);
def highestPPO = highest(myPPO,myrange);
plot PPO = absvalue(myPPO/highestPPO)*highestRSI;

Gamblers roll the dice; Traders load the dice.
Re: Auto Trade with Study Alerts
February 17, 2016 08:33AM
is the latest suppose to have

input price = close;

It also does not like

def highestRSI = highest(RSI,myrange);

I am putting this in a new study to merge with RSI



Edited 1 time(s). Last edit at 02/17/2016 08:34AM by bughatti.
Re: Auto Trade with Study Alerts
February 17, 2016 03:59PM
bughatti, I may have changed something a little in the RSI code, "maybe". So I just sent you a PM with full code that I've tried and it works fine.

Gamblers roll the dice; Traders load the dice.
Re: Auto Trade with Study Alerts
March 10, 2016 03:15PM
baffled1, can you please post corrected "def highestRSI = highest(RSI,myrange);", system doesn't allow to take. Thank you for sharing and work.
Re: Auto Trade with Study Alerts
March 10, 2016 03:44PM
Nevermind, I figured out already. thanks. thumbs up
Sorry, only registered users may post in this forum.

Click here to login