What I meant to say was this code doesn't compound, it always places $10k when opening a trade.
I'm pretty sure your code snippet won't work properly but I get why mine wouldn't either. TOS sure is weird.
What I meant to say was this code doesn't compound, it always places $10k when opening a trade.
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
What is your opinion instead of saying low <= EMA1 I say low <= EMA1[1] since that EMA has been set and established? It would still be a good entry and the EMA wouldn’t change.After spending like 3 days looking at this thing, I don't think the newest iteration is any different. All the scripts suffer from future bias and are on paper profitable because they are looking into the future. At least in terms of how the backtest orders are placed.
I spent $250k on consulting and dev time building algos over the last few years. Made a bunch of money trading futures, lost a bunch of money trading futures. I got lucky to break even. It all started from a script I found here that took me down the rabbit hole. It was a hull moving avg 'holy grail' algo from what i remember. My point is these entries are not even close to real. If you cannot automate a strategy, you're just using colors on a chart to gamble. Gambling is fun but making sure money is more fun.
I hope I'm misinterpreting your code and you know something I don't. The basic entry logic and exit logic is fine but you cannot manipulate the entry price. You have to use open[-1] in TOS and mentally account for some slippage. If you try and use this chart live, the EMA cannot and will not stay stagnant in the current candle that's updating, which it shouldn't, and therefore you cannot make an entry until the candle is closed. Right now you're entering trades at some percent relative to current candles EMA, based on last candles buy trigger. You cannot go in the past and get the price of what it was. This is future telling bias. The current candle EMA isn't calculated until the current candle is closed. Does that make sense?
I'm happy to hop on a skype call and chat. I sure hope I'm wrong and you've figured it out though!
I wouldn’t enter at the close. I would enter the second I get a trigger or atleast submit a trailing buy order. The twitter news in this example would make me a bunch of money.So... let's look at the entry.
def ShortTkPftBub = TradingDayExt and (ShortEntryInd or ShortHoldInd2) and low < EMA1 * 0.99;
It's looking at current candle situation. So let's say we're on 5 minute chart and at 5:01 ShortTkPftBub is true. We're all set to short. The low is less than the current EMA times 99% plus whatever checks you have. Now, at 5:04 the stock jumps on twitter news and now jumped up 100$ in price. Now, with 100% certainty, the low is still lower than 99% EMA. So, at the end of the candle, when the trade executes, at 5:04:59seconds, the low * 1.0025 is unattainable as an entry.
I'm trying to explain, the 5EMA that's triggering the order doesn't exist. The reason in TOS why you have to use open[-1] for entries and exits, which is using the price of the future candle open to execute a trade called on the current candle, is because how thinkscript works. If you watched your strategy live, you'd see your entries happen, then disappear when the price changes.
Thinkscript is a really strange language / compiles awkwardly. It's a particular programming language that's somewhat easy to read but really difficult to work with. Basically, Thinkscript executes on each candle over and over until the candle completes.
Does that make sense? Admin, chime in here? I'm 99% sure I'm correct but willing to be told otherwise.
Looks like it does! THanksThis is what I got though. Why it wouldn't work?
How do you use these codes in TOS ?Just realized that ToS has the entryPrice() function.
So this is simpler:
Code:input tradeAmount = 10000; def orderQuantity = Round(tradeAmount / open, 0); #OPEN ORDERS AddOrder(OrderType.BUY_TO_OPEN, ShowOrders and LongEntryInd, EMA1[1] * 1.0025, orderQuantity, Color.GREEN, Color.LIGHT_GREEN); AddOrder(OrderType.SELL_TO_OPEN, ShowOrders and ShortEntryInd, EMA1[1] * 0.9975, orderQuantity, Color.GREEN, Color.LIGHT_GREEN); #CLOSE ORDERS AddOrder(OrderType.SELL_TO_CLOSE, ShowOrders and ShowTkPftOrders and LongTkPftBub, high * 0.999, entryPrice(), Color.RED, Color.LIGHT_RED); AddOrder(OrderType.SELL_TO_CLOSE, ShowOrders and (LongSellInd or EndDay[-1]), open, entryPrice(), Color.RED, Color.LIGHT_RED); AddOrder(OrderType.BUY_TO_CLOSE, ShowOrders and ShowTkPftOrders and ShortTkPftBub, low * 1.001, entryPrice(), Color.RED, Color.LIGHT_RED); AddOrder(OrderType.BUY_TO_CLOSE, ShowOrders and (ShortSellInd or EndDay[-1]), open, entryPrice(), Color.RED, Color.LIGHT_RED);
I attached the above code to the end of Version 10 and tried to use the Floating P/L script. I get nothingHow do you use these codes in TOS ?
You have to replace the previous code not just add it to the end. This will then work.I attached the above code to the end of Version 10 and tried to use the Floating P/L script. I get nothing
Hey I have implemented your script and man has it been working great for me! Thank you for your work on this.I wouldn’t enter at the close. I would enter the second I get a trigger or atleast submit a trailing buy order. The twitter news in this example would make me a bunch of money.
Also we already went over this with the admin many times on this exact issue and it was decided that open[-1] would be even more inaccurate since that is not the intent of the strategy
Could you post a link to that?You have to replace the previous code not just add it to the end. This will then work.
declare lower;
#TSI
input TSILongLength = 25;
input TSIShortLength = 13;
#TRUE STENGTH INDEX(TSI)
def DiffShort = close - close[1];
def DoubleSmoothedAbsDiffShort = ExpAverage(ExpAverage(AbsValue(DiffShort), TSILongLength), TSIShortLength);
#TSI
def TSI = if DoubleSmoothedAbsDiffShort == 0 then 0 else Round((100 * (ExpAverage(ExpAverage(DiffShort, TSILongLength), TSIShortLength)) / DoubleSmoothedAbsDiffShort), 2);
def TSIBull = TSI > 10;
def TSIBear = TSI < -10;
input fastLength = 10;
input slowLength = 22;
input MACDLength = 8;
input averageType = AverageType.EXPONENTIAL;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
plot Diff = if TSI > Avg then TSI + Avg else if TSI < Avg then TSI - Avg else 0;
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.DefineColor("Neutral", Color.BLUE);
Diff.AssignValueColor(if Diff > 3 and Diff > Diff[1] then Diff.color("Positive and Up") else if Diff > 3 and Diff < Diff[1] then Diff.color("Positive and Down") else if Diff < -3 and Diff < Diff[1] then Diff.color("Negative and Down") else if Diff < -3 and Diff > Diff[1] then Diff.color("Negative and Up") else Diff.color("Neutral"));
Hey man, interesting strategy and indicator. I'm wondering if you think it's possible to add an average line to that macd tsi script. Maybe it could filter out lower quality moves. Just an idea. Good stuff!Edited Version 10 on Post# 148. The new code and link are there now.
I changed the MACD and TSI buy parameters so that they work off of each other. This change increased profits about $4k on TSLA over 90 days, I also added a little white dash above(or below) any buy candles to basically show you where the 5EMA +/- 0.25% was 1 bar prior. That way you can enter a trade after the fact on what was a good entry point (hope that part makes sense). Hopefully this white line will morph into a more accurate backtest.
If I get some positive feedback this weekend I will just post this new version on Post 1 and update that entire post with new photos, instuctions, etc.
In Addition, I created this neat little MACD/TSI Histogram. Seems to be working well. I happened to notice on the 5-Min Chart that if the histogram crosses below 3 or above -3 that is a pretty good sign of a reversal. Haven't really given the study much time though. Let me know what you see.
Code:declare lower; #TSI input TSILongLength = 25; input TSIShortLength = 13; #TRUE STENGTH INDEX(TSI) def DiffShort = close - close[1]; def DoubleSmoothedAbsDiffShort = ExpAverage(ExpAverage(AbsValue(DiffShort), TSILongLength), TSIShortLength); #TSI def TSI = if DoubleSmoothedAbsDiffShort == 0 then 0 else Round((100 * (ExpAverage(ExpAverage(DiffShort, TSILongLength), TSIShortLength)) / DoubleSmoothedAbsDiffShort), 2); def TSIBull = TSI > 10; def TSIBear = TSI < -10; input fastLength = 10; input slowLength = 22; input MACDLength = 8; input averageType = AverageType.EXPONENTIAL; def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength); def Avg = MovingAverage(averageType, Value, MACDLength); plot Diff = if TSI <> Avg then TSI - Avg else 0; Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Diff.DefineColor("Positive and Up", Color.GREEN); Diff.DefineColor("Positive and Down", Color.DARK_GREEN); Diff.DefineColor("Negative and Down", Color.RED); Diff.DefineColor("Negative and Up", Color.DARK_RED); Diff.DefineColor("Neutral", Color.BLUE); Diff.AssignValueColor(if Diff > 3 and Diff > Diff[1] then Diff.color("Positive and Up") else if Diff > 3 and Diff < Diff[1] then Diff.color("Positive and Down") else if Diff < -3 and Diff < Diff[1] then Diff.color("Negative and Down") else if Diff < -3 and Diff > Diff[1] then Diff.color("Negative and Up") else Diff.color("Neutral"));
Hey man, interesting strategy and indicator. I'm wondering if you think it's possible to add an average line to that macd tsi script. Maybe it could filter out lower quality moves. Just an idea. Good stuff!
Gimme 5. I'll add it back in and post it to Post #148. I will default it to off but you will be able to turn it on in the options. I'll let you know when I'm doneWhere is 34 /50 cloud this is very important
How to add it from previous script
Updated code and link in post #148. You must turn on ShowEMACloud and Show2ndEMACloud to view the 5/12 and 34/50 EMAs and Clouds. If you only turn on Show2ndEMACloud and leave ShowEMACloud off than you will not see any clouds and if you only turn on ShowEMACloud and leave Show2ndEMACloud than you will only see the 5/12 EMA Cloud. Default is 5EMA line only.Where is 34 /50 cloud this is very important
How to add it from previous script
No. The option to turn off premarket cloud is only visual. It still includes that parameter for the buy trigger. As far as your second request, I still **** at coding prior day stuff and if I figured out how to get the values, it would take me some time to figure out how to add that switch and not screw everything up.One more stupid question
So if i turn pre market cloud off
It will be exclud pre market once the criteria met for all other criteria will be red or green
I am using only pre day high and low
Can you make this option to use previous day high and low instead
I know its alot of work to do guide me where to start
Thanks
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.