I have years of programming experience but I'm very new to thinkScript. I'm trying to write both an upper study and a scan for price crossing above or below a user-configurable moving average in the last X number of price bars (X also user-configurable, if possible) on any time frame (For my example I'm using 1-min). Let's say X = 20 candles. On the chart I'd like to mark up to 20 candles since the first crossover in some way. I would want to plot up to 20 bars only as long as price didn't cross back over the MA.
What's the motivation for this? I often see price cross above or below an MA, then return to the MA to backtest the cross. From there you can see a really nice trend develop (up or down) as it bounces off the MA. I know I don't have the skills yet to program a backtest, so, for now, I'm just trying to manually build a watchlist of stocks that might be ready (soon) to begin a trend in a new direction. Why the X number of candles back? I'd like to screen out stocks that just pop above/below the MA and then retreat back to the other side. Besides, the backtest takes a while to develop anyway.
I started with code from the TOS PriceAverageCrossover function which plots a single up or down arrow when price crosses an MA. The up/down arrow it uses is fine to mark the up to 20 bars, or something different/better - just not a fan of studies that change the candle colors since that interferes with the visual interpretation of candle patterns. I can't figure out a clean, concise way to code it and I'm sure I'm writing WAY TOO MUCH code (which isn't working at all right now anyway - no output). Your help would be greatly appreciated.
"He's intelligent but not experienced. His pattern indicates two-dimensional thinking." - Spock, The Wrath of Khan, speaking about my inability to code this.
What's the motivation for this? I often see price cross above or below an MA, then return to the MA to backtest the cross. From there you can see a really nice trend develop (up or down) as it bounces off the MA. I know I don't have the skills yet to program a backtest, so, for now, I'm just trying to manually build a watchlist of stocks that might be ready (soon) to begin a trend in a new direction. Why the X number of candles back? I'd like to screen out stocks that just pop above/below the MA and then retreat back to the other side. Besides, the backtest takes a while to develop anyway.
I started with code from the TOS PriceAverageCrossover function which plots a single up or down arrow when price crosses an MA. The up/down arrow it uses is fine to mark the up to 20 bars, or something different/better - just not a fan of studies that change the candle colors since that interferes with the visual interpretation of candle patterns. I can't figure out a clean, concise way to code it and I'm sure I'm writing WAY TOO MUCH code (which isn't working at all right now anyway - no output). Your help would be greatly appreciated.
"He's intelligent but not experienced. His pattern indicates two-dimensional thinking." - Spock, The Wrath of Khan, speaking about my inability to code this.