Hi everyone,As we know, TradingView's regular session closes at 20:00 EST and reopens at 04:00 EST the next day, while Thinkorswim charts run 24 hours (including the overnight session).I tried modifying the Ripster EMA Clouds script to exclude the overnight session when calculating the EMAs, so they align perfectly with the standard Ripster Clouds on TradingView (which only use RTH +EXT data).However, after applying the modified script on Thinkorswim, the chart lags badly — it keeps loading data for a long time and sometimes takes minutes before the chart finally appears. This is making me a bit worried.
can anyone optimized this code so that it can run with out any lags. here is the code that need modification or optimization?
Thank you in advance!!!
can anyone optimized this code so that it can run with out any lags. here is the code that need modification or optimization?
Code:
# Session-based EMA Clouds
#ORIGINAL RIPSTER_EMA_CLOUDS
#MODIFY BY RAZOO TO ALLIGN WITH TRADING_VIEW EMA CLOUDS
input displace = 0;
def price = hl2;
# Session handling
def seconds = SecondsFromTime(0);
def isOvernight = seconds >= 20*60*60 or seconds < 4*60*60; # 8 PM to 4 AM
def isRegularSession = !isOvernight;
# EMA periods for clouds
input show_cloud1=yes;
input ema1low = 5;
input ema1high = 12;
input show_cloud2=yes;
input ema2low = 8;
input ema2high = 9;
input show_cloud3=yes;
input ema3low = 34;
input ema3high = 50;
input show_cloud4=yes;
input ema6low = 20;
input ema6high = 21;
input show_cloud5=yes;
input ema4low = 120;
input ema4high = 150;
input show_cloud6=yes;
input ema5low = 180;
input ema5high = 200;
# Calculate session-based EMAs using hl2
rec ema5 = if IsNaN(ema5[1]) then ExpAverage(hl2, ema1low) else
if isRegularSession then (2 * hl2 + (ema1low - 1) * ema5[1]) / (ema1low + 1)
else ema5[1];
rec ema13 = if IsNaN(ema13[1]) then ExpAverage(hl2, ema1high) else
if isRegularSession then (2 * hl2 + (ema1high - 1) * ema13[1]) / (ema1high + 1)
else ema13[1];
rec ema8 = if IsNaN(ema8[1]) then ExpAverage(hl2, ema2low) else
if isRegularSession then (2 * hl2 + (ema2low - 1) * ema8[1]) / (ema2low + 1)
else ema8[1];
rec ema9 = if IsNaN(ema9[1]) then ExpAverage(hl2, ema2high) else
if isRegularSession then (2 * hl2 + (ema2high - 1) * ema9[1]) / (ema2high + 1)
else ema9[1];
rec ema34 = if IsNaN(ema34[1]) then ExpAverage(hl2, ema3low) else
if isRegularSession then (2 * hl2 + (ema3low - 1) * ema34[1]) / (ema3low + 1)
else ema34[1];
rec ema50 = if IsNaN(ema50[1]) then ExpAverage(hl2, ema3high) else
if isRegularSession then (2 * hl2 + (ema3high - 1) * ema50[1]) / (ema3high + 1)
else ema50[1];
rec ema20 = if IsNaN(ema20[1]) then ExpAverage(hl2, ema6low) else
if isRegularSession then (2 * hl2 + (ema6low - 1) * ema20[1]) / (ema6low + 1)
else ema20[1];
rec ema21 = if IsNaN(ema21[1]) then ExpAverage(hl2, ema6high) else
if isRegularSession then (2 * hl2 + (ema6high - 1) * ema21[1]) / (ema6high + 1)
else ema21[1];
rec ema120 = if IsNaN(ema120[1]) then ExpAverage(hl2, ema4low) else
if isRegularSession then (2 * hl2 + (ema4low - 1) * ema120[1]) / (ema4low + 1)
else ema120[1];
rec ema150 = if IsNaN(ema150[1]) then ExpAverage(hl2, ema4high) else
if isRegularSession then (2 * hl2 + (ema4high - 1) * ema150[1]) / (ema4high + 1)
else ema150[1];
rec ema180 = if IsNaN(ema180[1]) then ExpAverage(hl2, ema5low) else
if isRegularSession then (2 * hl2 + (ema5low - 1) * ema180[1]) / (ema5low + 1)
else ema180[1];
rec ema200 = if IsNaN(ema200[1]) then ExpAverage(hl2, ema5high) else
if isRegularSession then (2 * hl2 + (ema5high - 1) * ema200[1]) / (ema5high + 1)
else ema200[1];
# Plot displaced EMAs
plot AvgExp5 = ema5[-displace];
plot AvgExp13 = ema13[-displace];
plot AvgExp8 = ema8[-displace];
plot AvgExp9 = ema9[-displace];
plot AvgExp34 = ema34[-displace];
plot AvgExp50 = ema50[-displace];
plot AvgExp20 = ema20[-displace];
plot AvgExp21 = ema21[-displace];
plot AvgExp120 = ema120[-displace];
plot AvgExp150 = ema150[-displace];
plot AvgExp180 = ema180[-displace];
plot AvgExp200 = ema200[-displace];
# Add clouds using plotted EMAs with conditional display
AddCloud(if show_cloud1 then AvgExp5 else Double.NaN, if show_cloud1 then AvgExp13 else Double.NaN, Color.GREEN, Color.RED, no);
AddCloud(if show_cloud2 then AvgExp8 else Double.NaN, if show_cloud2 then AvgExp9 else Double.NaN, Color.Green, Color.Red, no);
AddCloud(if show_cloud3 then AvgExp34 else Double.NaN, if show_cloud3 then AvgExp50 else Double.NaN, Color.Cyan, Color.Orange, no);
AddCloud(if show_cloud4 then AvgExp20 else Double.NaN, if show_cloud4 then AvgExp21 else Double.NaN, Color.RED, Color.RED, no);
AddCloud(if show_cloud5 then AvgExp120 else Double.NaN, if show_cloud5 then AvgExp150 else Double.NaN, Color.LIGHT_ORANGE, Color.PLUM, no);
AddCloud(if show_cloud6 then AvgExp180 else Double.NaN, if show_cloud6 then AvgExp200 else Double.NaN, Color.CYAN, Color.Pink, no);
Thank you in advance!!!
Last edited by a moderator: