Multi timeframe, 9/20 EMA, RSI crossing 50

naveed505

New member
I am looking to somehow create a strategy to back-test so that if the conditions are met below, it'll signal me to go long or short. I would really appreciate it if someone can point me to the right direction. :)

Long Strategy:
Entry:

On 5 min RSI =above 50
Price moves above VWAP
15 min – 9EMA above 20 EMA
5 min – 9 EMA above 20 EMA
5 min- price closes above 9 EMA
1 min price close above 9EMA

Exit if any met
5 min - VWAP below 50
5 min- close below 9 EMA
1 min -close below 20 EMA

SHORT only when
Entry:

On 5 min RSI =below 50
Price moves below VWAP
15 min – 9EMA below 20 EMA
5 min – 9 EMA below 20 EMA
5 min- price closes below 9 EMA
1 min price close below 9EMA

Exit if any met
5 min - VWAP above 50
5 min- close above 9 EMA
1 min -close above 20 EMA
 
Solution
here check it out
Code:
# MTF Moving Average

input Period1 = AggregationPeriod.MIN;
input Period2 = AggregationPeriod.FIVE_MIN;
input Period3 = AggregationPeriod.FIFTEEN_MIN;
input Period14 = AggregationPeriod.HOUR;
input AvgType = AverageType.EXPONENTIAL;
input Length1 = 9;
input Length2 = 20;

input priceclose = close;

#15 min – 9EMA above 20 EMA

def AVG1 = MovingAverage(AvgType, close(period = Period3), Length1);

def AVG2 = MovingAverage(AvgType, close(period = Period3), Length2);


#5 min – 9 EMA above 20 EMA

def AVG3 = MovingAverage(AvgType, close(period = Period2), Length1);

def AVG4 = MovingAverage(AvgType, close(period = Period2), Length2);


#1 min price close above 9EMA
def AVG5 = MovingAverage(AvgType, close(period =...
here check it out
Code:
# MTF Moving Average

input Period1 = AggregationPeriod.MIN;
input Period2 = AggregationPeriod.FIVE_MIN;
input Period3 = AggregationPeriod.FIFTEEN_MIN;
input Period14 = AggregationPeriod.HOUR;
input AvgType = AverageType.EXPONENTIAL;
input Length1 = 9;
input Length2 = 20;

input priceclose = close;

#15 min – 9EMA above 20 EMA

def AVG1 = MovingAverage(AvgType, close(period = Period3), Length1);

def AVG2 = MovingAverage(AvgType, close(period = Period3), Length2);


#5 min – 9 EMA above 20 EMA

def AVG3 = MovingAverage(AvgType, close(period = Period2), Length1);

def AVG4 = MovingAverage(AvgType, close(period = Period2), Length2);


#1 min price close above 9EMA
def AVG5 = MovingAverage(AvgType, close(period = Period1), Length1);

def AVG6 = MovingAverage(AvgType, close(period = Period1), Length2);

#vwap
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};

def cap = GetAggregationPeriod();
def errorInAggregation =
    timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
    timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = GetYYYYMMDD();
def periodIndx;
switch (timeFrame) {
case DAY:
    periodIndx = yyyyMmDd;
case WEEK:
    periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7);
case MONTH:
    periodIndx = RoundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP = price;
plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;



#RSI
input length = 14;
input over_Bought = 50;
input over_Sold = 30;
input price2 = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price2 - price2[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price2 - price2[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

plot long = VWAP < close and AVG1 > AVG2 and AVG3 > AVG4 and AVG3 < close and AVG5 < close and RSI > over_Bought;
#long.SetPaintingStrategy(
#PaintingStrategy.BOOLEAN_ARROW_UP);
#Alert(long, "arrow up", Alert.BAR, Sound.Ring);
AssignPriceColor(if long then Color.white else  Color.current);

plot short = VWAP > close and AVG1 < AVG2 and AVG3 < AVG4 and AVG3 > close and AVG5 > close and RSI < over_Bought;
#short.SetPaintingStrategy(
#PaintingStrategy.BOOLEAN_ARROW_down);
#Alert(short, "arrow down", Alert.BAR, Sound.Ring);
AssignPriceColor(if short then Color.white else  Color.current);

AddOrder(OrderType.buy_AUTO,long, arrowcolor = Color.Dark_Orange, name = "buy");
AddOrder(OrderType.SELL_TO_CLOSE, vwap>close or avg3>close or avg6>close, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "TAKE PROFIT");

AddOrder(OrderType.sell_AUTO,short, arrowcolor = Color.Dark_Orange, name = "sell");
AddOrder(OrderType.buy_TO_CLOSE, vwap<close or avg3<close or avg6<close, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "TAKE PROFIT");
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I am looking to somehow create a strategy to back-test so that if the conditions are met below, it'll signal me to go long or short. I would really appreciate it if someone can point me to the right direction. :)

Long Strategy:
Entry:

On 5 min RSI =above 50
Price moves above VWAP
15 min – 9EMA above 20 EMA
5 min – 9 EMA above 20 EMA
5 min- price closes above 9 EMA
1 min price close above 9EMA

Exit if any met
5 min - VWAP below 50
5 min- close below 9 EMA
1 min -close below 20 EMA

SHORT only when
Entry:

On 5 min RSI =below 50
Price moves below VWAP
15 min – 9EMA below 20 EMA
5 min – 9 EMA below 20 EMA
5 min- price closes below 9 EMA
1 min price close below 9EMA

Exit if any met
5 min - VWAP above 50
5 min- close above 9 EMA
1 min -close above 20 EMA
How did this turn out?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
347 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top