♥ 0 |
Hi Pete. First I just want to offer a sincere thank you for this great resource, for your generosity, and for all you do for the community. You are to be commended sir. Now on to my question. I’m in the process of learning how to code while at the same time, building a multi-timeframe strategy. I’m making good progress but I’ve hit a roadblock and can’t seem to find the solution. Everything is fine until I try to enter the different aggregation periods. Here’s a small portion of the code that is causing me problems. I would really appreciate your expertise on this. Thank you so much! def agg1 = AggregationPeriod.MIN; input smaPrice = close; def SMA1 = Average(smaPrice, smaLength, (period == agg1)); def SMA2 = Average(smaPrice, smaLength, (period == agg2)); def SMA5 = Average(smaPrice, smaLength, (period == agg5));
Marked as spam
|
Private answer
Whoa! Slow down. These two things are like water and oil:
The average person might spend 3-5 years of writing basic common chart studies before they are ready to attempt working with multiple aggregation periods. Likewise, one might expect 3-5 years of writing basic common chart studies before they are ready to attempt building chart strategies. But to combine these two? That takes a very long time indeed. (just because you can, doesn't mean you should) But so long as you love to learn by bashing your skull against the keyboard then I say "Go For It!". That's how you learn, by making mistakes and fixing them. So how about we let you fix this one? First item on the list. How many arguments does the function named "Average()" accept? Need some help? https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Average Now, how many arguments did you try to include in your statements?
I count three. Busted right there. The language reference clearly tells us there are only two arguments for that function. First argument is the price and second argument is the length. So you have to write that statement with only two arguments:
But that still doesn't get you to the aggregation period you assigned to the variable named "agg1". Which just so happens to be the very lowest aggregation period you can assign to a chart. So... that was pointless. Ok, let's do that again. So you have to write that statement with only two arguments:
There, for now we'll assume the chart is set to 1 min time frame and all we want is a 20 period simple moving average of the close from the 2 min time frame. How do we get there from here? Need a hint? Write, so then we have the following:
Wonderful. We have solved the very first issue that was preventing you from completing this. Are you ready for the next problem to solve? That statement references the current value of the 2 min bar's 20 period simple moving average. What happens if that bar changes direction between the first 1 min bar and the second 1 min bar? Busted and broken. Imagine how bad it gets when you reference the 5 min data? Five 1 min candles, each one able to present and then vanish a valid signal. MADNESS!!! When constructing chart strategies for back testing, ones that use data from higher time frames, you must construct them using the previous higher time frame data. Otherwise your signals can repaint. All you get from chart strategies that reference the current data of the higher time frames is pure garbage. Signals that can never by repeated in a live market. Because it creates a leak into the future. Oh man... you have no idea how far up the creek you are right now. Best thing I can recommend is that you turn around and go the opposite direction. Go fishing, watch a movie, have a beer.... However if you happen to be one of those crazy wackjobs that loves to bash their skull against the keyboard (that's me). Well then you can get all the details on how to get out of the rabbit hole and on to the straight and narrow path right here: https://www.hahn-tech.com/thinkorswim-strategy-guide-mtf/
Marked as spam
|
Please log in to post questions.