Multipe time frame SMA setup, need to build a scanner

stockula

stockula

New member
VIP
Multiple time frame scanner:

Hi guys, i'll try to keep this as short and clear as possible, any help would be greatly appreciated. There is a setup that I look for which yields consistent results for day trades and short swings. Unfortunately, I am unable to build a scanner for it, for the life of me I have tried. The setup is really simple, but the conditions pretty much have to be exact. I will describe the bullish setup, any SMA combination can be used, but I find 5/10, 10/20, 13/21 etc work well, so having the ability to change the SMA's would be great.

The setup involves two SMAs and two time frames. (5 sma, 10 sma, and 1H and 4H)

The idea of this setup, is to go from the fast 4H sma to the slow 4Hsma, while fast is below slow, in terms of price target. i.e. I wanna enter on the 4H 5sma, and exit at the 4H 10sma... kinda thing, but using the 1H candle as my entry trigger.

1 Hour conditions:
-1 Hour candle is above the 1Hour 5sma and 30sma
-1 Hour candle CLOSES ABOVE the 4Hour 5sma but below the 4H 10sma

4Hour conditions:
-4Hour 10sma is above 4Hour 5sma ( the 10sma needs to be at least 3% away from the 5sma, and if this % is adjustable, it will make this scanner very accurate)

Entry conditions:
-Enter when the 1H closes above the 4H slow sma.

Notes:
-It is crucial that there is room between the 4H smas. Again, if this 'room' could be adjusted as a % of the price, it would make for very accurate scans.
-Works best on big cap stocks with high volume
-This play is basically a downtrend break continuation

(tried posting a pic ,but keep getting an error, not sure why)
 
stockula

stockula

New member
VIP
Yup, tos definitely doesn’t allow that. I tried a work around; instead of scanning for 4H conditions, I tried using 1H smas multiplied by 4, since a 4H candle is 4 1H candles. It’s correct in theory, but it definitely doesn’t work the same way on the scanner. I will continue to work on this, but due to that tos time constraint, I fear it’s a fruitless endeavour.
 
J

Jynx

New member
@BenTen @stockula This is possible, took me a few minutes to figure it out, I'm still kinda new to this scripting thing and its 3am but you can reference a custom study in watchlist scripts it will require 2 custom scripts the hr4sma() set to 4hrs and convert the sma's to variables and then the second script set to hourly and reference the variables and viola! since it basically inputs the referenced into the other I'll just post the one, I colored it so that the signals pop as red when true(note this isn't possible in chart studies though, as you cant reference a custom script from another custom script and you get the secondary aggregation error) So just add this as a watchlist column and wait for it to pop, its like 3am so I didn't add the 3% part and its after hours so I haven't tested it but I didn't pop in any secondary aggregation reference error so give it a try!

Code:
script hr4sma5 {
Def A = close(GetSymbol(), AggregationPeriod.four_hours);
Def HR4SMA5=average(a,5);
def hrsma10=average(a,10);
plot A1=hr4sma5;


}
declare upper;
def A = close(GetSymbol(), AggregationPeriod.HOUR);


def conditionA = A > Average(A, 5) and Average(A, 30);
def conditionB =A> hr4sma5().a1;
def ConditionC =A< hr4sma5()."hrsma10";
def signal = if conditionA == 1 and ConditionB == 1 and conditionC==1 then 1 else Double.NaN ;
plot signal1=signal;
AssignBackgroundColor(if conditionA == 1 and ConditionB == 1 and conditionC==1 then color.red else  color.gray);
 

Similar threads

Top