# VWOP: Volume Weighted & Oscillated Price for ThinkOrSwim

#### samer800

##### Moderator - Expert
VIP

Creator Message:
Normal VWAP = (Number of Shares Bought x Typical Price) / Total Volume

In VWOP Calculation, typical price is replaced by selected moving average type or "matype" and then multiplied by the volume .
Then a total value is calculated using math.sum with a length value that changes according to a selected oscillator's value. The total is then divided by
the sum of just volume using the same oscillating length value. Result is then passed through the selected"matype" once more to give the final result.

Indicator designed for use as a entry/exit indicator in conjunction with more traditional moving averages and/or signal filters. Useful for taking volume + an oscillator into account along with price, instead of just the price as with a simple moving average .

CODE:
CSS:
``````#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#indicator("Volume Weighted & Oscillated Price",shorttitle = "VWOP",overlay=true)
# converted and mod by Sam4Cok@Samer800 - 03/2023
input BarColor = yes;
input trendStrength = 0.1;
input src  = close;
input Length1 = 16;
input Length2 = 24;
input Length3 = 32;
input Length4 = 40;
input oscillatorLength = 16;
input oscillatorType = {RSI, CCI, COG, MFI, TSI, CMO, default COPPOCK, All};
input MovAvgType  = {VWAP, SWMA, VWMA, SMA, EMA, RMA, WMA, default LRC};
input curve   = {"Algo-1", "Algo-2",default "Algo-3", "Algo-4"};

def na = Double.NaN;
script nz {
input data  = close;
input repl  = 0;
def ret_val = if !IsNaN(data) then data else repl;
plot return = ret_val;
}
#export f_Vwap(simple string tf, float src, float src_v) =>
script f_Vwap {
input src = close;
def src_v = Volume;
def tf = GetDay();
def start0 = tf - tf[1];
def sumSrc0 = src * src_v;
def sumVol0 = src_v;
def sumSrc1 = CompoundValue(1, if start0 then sumSrc0 else sumSrc0 + sumSrc1[1], sumSrc0);
def sumVol1 = CompoundValue(1, if start0 then sumVol0 else sumVol0 + sumVol1[1], sumVol0);
def Vwap = sumSrc1 / sumVol1;
plot wap = Vwap;
}
#f_cmo(src, length) =>
script cmo {
input src = close;
input length = 16;
def mom = (src-src[1]);
def sm1 = sum(if (mom >= 0) then mom else 0.0, length);
def sm2 = sum(if (mom >= 0) then 0.0 else -mom, length);
def cmo = 100 * (sm1 - sm2) / (sm1 + sm2);
plot out = cmo;
}
# roc(src, length)
script roc {
input src = close;
input length = 14;
def roc = if isNaN(src[length]) then 0 else
if src[length] !=0 then 100 * ((src - src[length])/ src[length]) else 0;
plot return = roc;
}
#vwma(source, length)
script vwma {
input x = close;
input y = 15;
def v = volume;
def VWMA = SimpleMovingAvg(x * nz(v,1), y) / SimpleMovingAvg(nz(v,1), y);
plot result = VWMA;
}
#pine_swma(x) =>
script swma {
input x = close;
def swma = nz(x[3],X[2]) * 1 / 6 + NZ(x[2],X[1]) * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6;
plot return = swma;
}
#cog(source, length) =>
script cog {
input source = close;
input length = 14;
def Msum = Sum(source, length);
def num;
num = fold i = 0 to length with p do
p + source[i] * (i + 1);
plot return = -num / Msum;
}
#vwosc(src,len1=16,len2=24,len3=32,len4=40,osclen=16,string osctype="RSI",matype="LRC",curve="<>")=>
script vwosc {
input src = close;
input len1 = 16;
input len2 = 24;
input len3 = 32;
input len4 = 40;
input osclen = 16;
input osctype = "RSI";
input matype = "LRC";
input curve = "Algo-1";
def nRSI = RSI(Price = src, Length = osclen);
def nCCI = CCI(LENGTH = osclen);
def nCOG = cog(src, osclen);
def nMFI = MoneyFlowIndex(Length = osclen);
def nCMO = CMO(src, osclen);
def nTSI = TrueStrengthIndex(shortLength=osclen,longLength=Round(osclen * 1.5, 0));
def ROC1 = ROC(src, Round(1.1 * osclen, 0));
def ROC2 = ROC(src, Round(1.4 * osclen, 0));
def COPPOCK = WMA(ROC1 + ROC2, osclen);
def all = AbsValue(nRSI[1]-nrsi[len1]) + AbsValue(nCCI[1]-nCCI[len1]) +
AbsValue(nCOG[1]-nCOG[len1]) + AbsValue(nMFI[1]-nMFI[len1]) +
AbsValue(nCMO[1]-nCMO[len1]) + AbsValue(COPPOCK[1]-COPPOCK[len1]);
def osc = if osctype == "All" then all else
if osctype == "RSI" then nRSI else
if osctype == "CCI" then nCCI else
if osctype == "COG" then nCOG else
if osctype == "MFI" then nMFI else
if osctype == "CMO" then nCMO else
if osctype == "TSI" then nTSI else
if osctype == "COPPOCK" then COPPOCK else nRSI;

def max = Highest(osc, 500);
def min = Lowest(osc, 500);
def dif = max - min;
def lev1 =
if curve == "Algo-3"  then
if osc - min < 0.25 * dif then len1 else
if osc - min < 0.35 * dif then Round((len1 + len2) / 2, 0) else
if osc - min < 0.45 * dif then len2 else
if osc - min < 0.55 * dif then Round((len2 + len3) / 2, 0) else
if osc - min < 0.65 * dif then len3 else
if osc - min < 0.75 * dif then Round((len3 + len4) / 2, 0) else len4 else
if curve == "Algo-1" then
if osc - min < 0.25 * dif or max - osc < 0.25 * dif then len1 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then len2 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then len3 else len4 else
if curve == "Algo-2" then
if osc - min < 0.25 * dif or max - osc < 0.25 * dif then len4 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then len3 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then len2 else len1 else
if curve == "Algo-4" then
if max - osc < 0.25 * dif then len1 else
if max - osc < 0.35 * dif then Round((len1 + len2) / 2, 0) else
if max - osc < 0.45 * dif then len2 else
if max - osc < 0.55 * dif then Round((len2 + len3) / 2, 0) else
if max - osc < 0.65 * dif then len3 else
if max - osc < 0.75 * dif then Round((len3 + len4) / 2) else len4 else lev1[1];
def lev = if IsNaN(lev1) then if lev[1] == 0 then len2 else lev[1] else lev1;

def v = Volume * vwap;
def swma = swma(src) * V;
def fwap = f_Vwap(src) * V;
def vwma = VWMA(src, len1) * V;
def LRC = Inertia(src, len1) * V;
def SMA = Average(src, len1) * V;
def EMA = ExpAverage(src, len1) * V;
def RMA = WildersAverage(src, len1) * V;
def WMA = WMA(src, len1) * V;

def Volsum = fold i = 0 to lev with p do
p + GetValue(V, i);
def WAPsum = fold i1 =0 to lev with p1 do
p1 + GetValue(fwap, i1);
def SWMsum = fold i2 = 0 to lev with p2 do
p2 + GetValue(swma, i2);
def VWMsum = fold i3 = 0 to lev with p3 do
p3 + GetValue(vwma, i3);
def SMAsum = fold i4 = 0 to lev with p4 do
p4 + GetValue(SMA, i4);
def EMAsum = fold i5 = 0 to lev with p5 do
p5 + GetValue(EMA, i5);
def RMAsum = fold i6 = 0 to lev with p6 do
p6 + GetValue(RMA, i6);
def WMAsum = fold i7 = 0 to lev with p7 do
p7 + GetValue(WMA, i7);
def LRCsum = fold i8 = 0 to lev with p8 do
p8 + GetValue(LRC, i8);

def WAPsrc = WAPsum / Volsum;
def SWMsrc = SWMsum / Volsum;
def VWMsrc = VWMsum / Volsum;
def SMAsrc = SMAsum / Volsum;
def EMAsrc = EMAsum / Volsum;
def RMAsrc = RMAsum / Volsum;
def WMAsrc = WMAsum / Volsum;
def LRCsrc = LRCsum / Volsum;

def ma =
if matype == "VWAP" then f_Vwap(WAPsrc) else
if matype == "SWMA" then SWMA(SWMsrc) else
if matype == "VWMA" then vwma(VWMsrc, len2) else
if matype == "SMA"  then Average(SMAsrc, len2) else
if matype == "EMA"  then ExpAverage(EMAsrc, len2) else
if matype == "RMA"  then WildersAverage(RMAsrc, len2) else
if matype == "WMA"  then WMA (WMAsrc, len2) else
if matype == "LRC" then Inertia(LRCsrc, len2) else Average(SMAsrc, len2);
plot return = ma;
plot trend = all;
}

def line = vwosc(src, Length1, Length2, Length3, Length4, oscillatorLength, oscillatorType, MovAvgType, curve);
def VWOPvalue = line;
def ExtUp = src>VWOPvalue and VWOPvalue>Average(VWOPvalue, Length2);
def Up    = src>VWOPvalue and !ExtUp;
def ExtDn = src<VWOPvalue and VWOPvalue<Average(VWOPvalue, Length2);
def Dn    = src<VWOPvalue and !ExtDn;
plot VWOP = VWOPvalue;
VWOP.SetLineWeight(2);
VWOP.AssignValueColor(if src>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

AssignPriceColor(if !BarColor then Color.CURRENT else if src>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

plot trendUp = if ExtUp and Dn[1] then low else na;#, "Buy", Color.GREEN, no);
plot trendDn = if ExtDn and Up[1] then high else na;#, "Sell", Color.RED, yes);

trendUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
trendDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
trendUp.SetDefaultColor(Color.GREEN);
trendDn.SetDefaultColor(Color.RED);

#--- END CODE``````

Last edited by a moderator:
Ooh, this is a good one.

Is there a way to make this a scan for the up trend signal?

Great indicator as always!! You are rocks!

Creator Message:
Normal VWAP = (Number of Shares Bought x Typical Price) / Total Volume

In VWOP Calculation, typical price is replaced by selected moving average type or "matype" and then multiplied by the volume .
Then a total value is calculated using math.sum with a length value that changes according to a selected oscillator's value. The total is then divided by
the sum of just volume using the same oscillating length value. Result is then passed through the selected"matype" once more to give the final result.

Indicator designed for use as a entry/exit indicator in conjunction with more traditional moving averages and/or signal filters. Useful for taking volume + an oscillator into account along with price, instead of just the price as with a simple moving average .

CODE:
CSS:
``````#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#indicator("Volume Weighted & Oscillated Price",shorttitle = "VWOP",overlay=true)
# converted and mod by Sam4Cok@Samer800 - 03/2023
input BarColor = yes;
input trendStrength = 0.1;
input src  = close;
input Length1 = 16;
input Length2 = 24;
input Length3 = 32;
input Length4 = 40;
input oscillatorLength = 16;
input oscillatorType = {RSI, CCI, COG, MFI, TSI, CMO, default COPPOCK, All};
input MovAvgType  = {VWAP, SWMA, VWMA, SMA, EMA, RMA, WMA, default LRC};
input curve   = {"Algo-1", "Algo-2",default "Algo-3", "Algo-4"};

def na = Double.NaN;
script nz {
input data  = close;
input repl  = 0;
def ret_val = if !IsNaN(data) then data else repl;
plot return = ret_val;
}
#export f_Vwap(simple string tf, float src, float src_v) =>
script f_Vwap {
input src = close;
def src_v = Volume;
def tf = GetDay();
def start0 = tf - tf[1];
def sumSrc0 = src * src_v;
def sumVol0 = src_v;
def sumSrc1 = CompoundValue(1, if start0 then sumSrc0 else sumSrc0 + sumSrc1[1], sumSrc0);
def sumVol1 = CompoundValue(1, if start0 then sumVol0 else sumVol0 + sumVol1[1], sumVol0);
def Vwap = sumSrc1 / sumVol1;
plot wap = Vwap;
}
#f_cmo(src, length) =>
script cmo {
input src = close;
input length = 16;
def mom = (src-src[1]);
def sm1 = sum(if (mom >= 0) then mom else 0.0, length);
def sm2 = sum(if (mom >= 0) then 0.0 else -mom, length);
def cmo = 100 * (sm1 - sm2) / (sm1 + sm2);
plot out = cmo;
}
# roc(src, length)
script roc {
input src = close;
input length = 14;
def roc = if isNaN(src[length]) then 0 else
if src[length] !=0 then 100 * ((src - src[length])/ src[length]) else 0;
plot return = roc;
}
#vwma(source, length)
script vwma {
input x = close;
input y = 15;
def v = volume;
def VWMA = SimpleMovingAvg(x * nz(v,1), y) / SimpleMovingAvg(nz(v,1), y);
plot result = VWMA;
}
#pine_swma(x) =>
script swma {
input x = close;
def swma = nz(x[3],X[2]) * 1 / 6 + NZ(x[2],X[1]) * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6;
plot return = swma;
}
#cog(source, length) =>
script cog {
input source = close;
input length = 14;
def Msum = Sum(source, length);
def num;
num = fold i = 0 to length with p do
p + source[i] * (i + 1);
plot return = -num / Msum;
}
#vwosc(src,len1=16,len2=24,len3=32,len4=40,osclen=16,string osctype="RSI",matype="LRC",curve="<>")=>
script vwosc {
input src = close;
input len1 = 16;
input len2 = 24;
input len3 = 32;
input len4 = 40;
input osclen = 16;
input osctype = "RSI";
input matype = "LRC";
input curve = "Algo-1";
def nRSI = RSI(Price = src, Length = osclen);
def nCCI = CCI(LENGTH = osclen);
def nCOG = cog(src, osclen);
def nMFI = MoneyFlowIndex(Length = osclen);
def nCMO = CMO(src, osclen);
def nTSI = TrueStrengthIndex(shortLength=osclen,longLength=Round(osclen * 1.5, 0));
def ROC1 = ROC(src, Round(1.1 * osclen, 0));
def ROC2 = ROC(src, Round(1.4 * osclen, 0));
def COPPOCK = WMA(ROC1 + ROC2, osclen);
def all = AbsValue(nRSI[1]-nrsi[len1]) + AbsValue(nCCI[1]-nCCI[len1]) +
AbsValue(nCOG[1]-nCOG[len1]) + AbsValue(nMFI[1]-nMFI[len1]) +
AbsValue(nCMO[1]-nCMO[len1]) + AbsValue(COPPOCK[1]-COPPOCK[len1]);
def osc = if osctype == "All" then all else
if osctype == "RSI" then nRSI else
if osctype == "CCI" then nCCI else
if osctype == "COG" then nCOG else
if osctype == "MFI" then nMFI else
if osctype == "CMO" then nCMO else
if osctype == "TSI" then nTSI else
if osctype == "COPPOCK" then COPPOCK else nRSI;

def max = Highest(osc, 500);
def min = Lowest(osc, 500);
def dif = max - min;
def lev1 =
if curve == "Algo-3"  then
if osc - min < 0.25 * dif then len1 else
if osc - min < 0.35 * dif then Round((len1 + len2) / 2, 0) else
if osc - min < 0.45 * dif then len2 else
if osc - min < 0.55 * dif then Round((len2 + len3) / 2, 0) else
if osc - min < 0.65 * dif then len3 else
if osc - min < 0.75 * dif then Round((len3 + len4) / 2, 0) else len4 else
if curve == "Algo-1" then
if osc - min < 0.25 * dif or max - osc < 0.25 * dif then len1 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then len2 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then len3 else len4 else
if curve == "Algo-2" then
if osc - min < 0.25 * dif or max - osc < 0.25 * dif then len4 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then len3 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then len2 else len1 else
if curve == "Algo-4" then
if max - osc < 0.25 * dif then len1 else
if max - osc < 0.35 * dif then Round((len1 + len2) / 2, 0) else
if max - osc < 0.45 * dif then len2 else
if max - osc < 0.55 * dif then Round((len2 + len3) / 2, 0) else
if max - osc < 0.65 * dif then len3 else
if max - osc < 0.75 * dif then Round((len3 + len4) / 2) else len4 else lev1[1];
def lev = if IsNaN(lev1) then if lev[1] == 0 then len2 else lev[1] else lev1;

def v = Volume * vwap;
def swma = swma(src) * V;
def fwap = f_Vwap(src) * V;
def vwma = VWMA(src, len1) * V;
def LRC = Inertia(src, len1) * V;
def SMA = Average(src, len1) * V;
def EMA = ExpAverage(src, len1) * V;
def RMA = WildersAverage(src, len1) * V;
def WMA = WMA(src, len1) * V;

def Volsum = fold i = 0 to lev with p do
p + GetValue(V, i);
def WAPsum = fold i1 =0 to lev with p1 do
p1 + GetValue(fwap, i1);
def SWMsum = fold i2 = 0 to lev with p2 do
p2 + GetValue(swma, i2);
def VWMsum = fold i3 = 0 to lev with p3 do
p3 + GetValue(vwma, i3);
def SMAsum = fold i4 = 0 to lev with p4 do
p4 + GetValue(SMA, i4);
def EMAsum = fold i5 = 0 to lev with p5 do
p5 + GetValue(EMA, i5);
def RMAsum = fold i6 = 0 to lev with p6 do
p6 + GetValue(RMA, i6);
def WMAsum = fold i7 = 0 to lev with p7 do
p7 + GetValue(WMA, i7);
def LRCsum = fold i8 = 0 to lev with p8 do
p8 + GetValue(LRC, i8);

def WAPsrc = WAPsum / Volsum;
def SWMsrc = SWMsum / Volsum;
def VWMsrc = VWMsum / Volsum;
def SMAsrc = SMAsum / Volsum;
def EMAsrc = EMAsum / Volsum;
def RMAsrc = RMAsum / Volsum;
def WMAsrc = WMAsum / Volsum;
def LRCsrc = LRCsum / Volsum;

def ma =
if matype == "VWAP" then f_Vwap(WAPsrc) else
if matype == "SWMA" then SWMA(SWMsrc) else
if matype == "VWMA" then vwma(VWMsrc, len2) else
if matype == "SMA"  then Average(SMAsrc, len2) else
if matype == "EMA"  then ExpAverage(EMAsrc, len2) else
if matype == "RMA"  then WildersAverage(RMAsrc, len2) else
if matype == "WMA"  then WMA (WMAsrc, len2) else
if matype == "LRC" then Inertia(LRCsrc, len2) else Average(SMAsrc, len2);
plot return = ma;
plot trend = all;
}

def line = vwosc(src, Length1, Length2, Length3, Length4, oscillatorLength, oscillatorType, MovAvgType, curve);
def VWOPvalue = line;
def ExtUp = src>VWOPvalue and VWOPvalue>Average(VWOPvalue, Length2);
def Up    = src>VWOPvalue and !ExtUp;
def ExtDn = src<VWOPvalue and VWOPvalue<Average(VWOPvalue, Length2);
def Dn    = src<VWOPvalue and !ExtDn;
plot VWOP = VWOPvalue;
VWOP.SetLineWeight(2);
VWOP.AssignValueColor(if src>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

AssignPriceColor(if !BarColor then Color.CURRENT else if src>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

plot trendUp = if ExtUp and Dn[1] then low else na;#, "Buy", Color.GREEN, no);
plot trendDn = if ExtDn and Up[1] then high else na;#, "Sell", Color.RED, yes);

trendUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
trendDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
trendUp.SetDefaultColor(Color.GREEN);
trendDn.SetDefaultColor(Color.RED);

#--- END CODE``````

This looks pretty cool. Does anyone have video of it in use live trading

Creator Message:
Normal VWAP = (Number of Shares Bought x Typical Price) / Total Volume

In VWOP Calculation, typical price is replaced by selected moving average type or "matype" and then multiplied by the volume .
Then a total value is calculated using math.sum with a length value that changes according to a selected oscillator's value. The total is then divided by
the sum of just volume using the same oscillating length value. Result is then passed through the selected"matype" once more to give the final result.

Indicator designed for use as a entry/exit indicator in conjunction with more traditional moving averages and/or signal filters. Useful for taking volume + an oscillator into account along with price, instead of just the price as with a simple moving average .

CODE:
CSS:
``````#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#indicator("Volume Weighted & Oscillated Price",shorttitle = "VWOP",overlay=true)
# converted and mod by Sam4Cok@Samer800 - 03/2023
input BarColor = yes;
input trendStrength = 0.1;
input src  = close;
input Length1 = 16;
input Length2 = 24;
input Length3 = 32;
input Length4 = 40;
input oscillatorLength = 16;
input oscillatorType = {RSI, CCI, COG, MFI, TSI, CMO, default COPPOCK, All};
input MovAvgType  = {VWAP, SWMA, VWMA, SMA, EMA, RMA, WMA, default LRC};
input curve   = {"Algo-1", "Algo-2",default "Algo-3", "Algo-4"};

def na = Double.NaN;
script nz {
input data  = close;
input repl  = 0;
def ret_val = if !IsNaN(data) then data else repl;
plot return = ret_val;
}
#export f_Vwap(simple string tf, float src, float src_v) =>
script f_Vwap {
input src = close;
def src_v = Volume;
def tf = GetDay();
def start0 = tf - tf[1];
def sumSrc0 = src * src_v;
def sumVol0 = src_v;
def sumSrc1 = CompoundValue(1, if start0 then sumSrc0 else sumSrc0 + sumSrc1[1], sumSrc0);
def sumVol1 = CompoundValue(1, if start0 then sumVol0 else sumVol0 + sumVol1[1], sumVol0);
def Vwap = sumSrc1 / sumVol1;
plot wap = Vwap;
}
#f_cmo(src, length) =>
script cmo {
input src = close;
input length = 16;
def mom = (src-src[1]);
def sm1 = sum(if (mom >= 0) then mom else 0.0, length);
def sm2 = sum(if (mom >= 0) then 0.0 else -mom, length);
def cmo = 100 * (sm1 - sm2) / (sm1 + sm2);
plot out = cmo;
}
# roc(src, length)
script roc {
input src = close;
input length = 14;
def roc = if isNaN(src[length]) then 0 else
if src[length] !=0 then 100 * ((src - src[length])/ src[length]) else 0;
plot return = roc;
}
#vwma(source, length)
script vwma {
input x = close;
input y = 15;
def v = volume;
def VWMA = SimpleMovingAvg(x * nz(v,1), y) / SimpleMovingAvg(nz(v,1), y);
plot result = VWMA;
}
#pine_swma(x) =>
script swma {
input x = close;
def swma = nz(x[3],X[2]) * 1 / 6 + NZ(x[2],X[1]) * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6;
plot return = swma;
}
#cog(source, length) =>
script cog {
input source = close;
input length = 14;
def Msum = Sum(source, length);
def num;
num = fold i = 0 to length with p do
p + source[i] * (i + 1);
plot return = -num / Msum;
}
#vwosc(src,len1=16,len2=24,len3=32,len4=40,osclen=16,string osctype="RSI",matype="LRC",curve="<>")=>
script vwosc {
input src = close;
input len1 = 16;
input len2 = 24;
input len3 = 32;
input len4 = 40;
input osclen = 16;
input osctype = "RSI";
input matype = "LRC";
input curve = "Algo-1";
def nRSI = RSI(Price = src, Length = osclen);
def nCCI = CCI(LENGTH = osclen);
def nCOG = cog(src, osclen);
def nMFI = MoneyFlowIndex(Length = osclen);
def nCMO = CMO(src, osclen);
def nTSI = TrueStrengthIndex(shortLength=osclen,longLength=Round(osclen * 1.5, 0));
def ROC1 = ROC(src, Round(1.1 * osclen, 0));
def ROC2 = ROC(src, Round(1.4 * osclen, 0));
def COPPOCK = WMA(ROC1 + ROC2, osclen);
def all = AbsValue(nRSI[1]-nrsi[len1]) + AbsValue(nCCI[1]-nCCI[len1]) +
AbsValue(nCOG[1]-nCOG[len1]) + AbsValue(nMFI[1]-nMFI[len1]) +
AbsValue(nCMO[1]-nCMO[len1]) + AbsValue(COPPOCK[1]-COPPOCK[len1]);
def osc = if osctype == "All" then all else
if osctype == "RSI" then nRSI else
if osctype == "CCI" then nCCI else
if osctype == "COG" then nCOG else
if osctype == "MFI" then nMFI else
if osctype == "CMO" then nCMO else
if osctype == "TSI" then nTSI else
if osctype == "COPPOCK" then COPPOCK else nRSI;

def max = Highest(osc, 500);
def min = Lowest(osc, 500);
def dif = max - min;
def lev1 =
if curve == "Algo-3"  then
if osc - min < 0.25 * dif then len1 else
if osc - min < 0.35 * dif then Round((len1 + len2) / 2, 0) else
if osc - min < 0.45 * dif then len2 else
if osc - min < 0.55 * dif then Round((len2 + len3) / 2, 0) else
if osc - min < 0.65 * dif then len3 else
if osc - min < 0.75 * dif then Round((len3 + len4) / 2, 0) else len4 else
if curve == "Algo-1" then
if osc - min < 0.25 * dif or max - osc < 0.25 * dif then len1 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then len2 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then len3 else len4 else
if curve == "Algo-2" then
if osc - min < 0.25 * dif or max - osc < 0.25 * dif then len4 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then len3 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then len2 else len1 else
if curve == "Algo-4" then
if max - osc < 0.25 * dif then len1 else
if max - osc < 0.35 * dif then Round((len1 + len2) / 2, 0) else
if max - osc < 0.45 * dif then len2 else
if max - osc < 0.55 * dif then Round((len2 + len3) / 2, 0) else
if max - osc < 0.65 * dif then len3 else
if max - osc < 0.75 * dif then Round((len3 + len4) / 2) else len4 else lev1[1];
def lev = if IsNaN(lev1) then if lev[1] == 0 then len2 else lev[1] else lev1;

def v = Volume * vwap;
def swma = swma(src) * V;
def fwap = f_Vwap(src) * V;
def vwma = VWMA(src, len1) * V;
def LRC = Inertia(src, len1) * V;
def SMA = Average(src, len1) * V;
def EMA = ExpAverage(src, len1) * V;
def RMA = WildersAverage(src, len1) * V;
def WMA = WMA(src, len1) * V;

def Volsum = fold i = 0 to lev with p do
p + GetValue(V, i);
def WAPsum = fold i1 =0 to lev with p1 do
p1 + GetValue(fwap, i1);
def SWMsum = fold i2 = 0 to lev with p2 do
p2 + GetValue(swma, i2);
def VWMsum = fold i3 = 0 to lev with p3 do
p3 + GetValue(vwma, i3);
def SMAsum = fold i4 = 0 to lev with p4 do
p4 + GetValue(SMA, i4);
def EMAsum = fold i5 = 0 to lev with p5 do
p5 + GetValue(EMA, i5);
def RMAsum = fold i6 = 0 to lev with p6 do
p6 + GetValue(RMA, i6);
def WMAsum = fold i7 = 0 to lev with p7 do
p7 + GetValue(WMA, i7);
def LRCsum = fold i8 = 0 to lev with p8 do
p8 + GetValue(LRC, i8);

def WAPsrc = WAPsum / Volsum;
def SWMsrc = SWMsum / Volsum;
def VWMsrc = VWMsum / Volsum;
def SMAsrc = SMAsum / Volsum;
def EMAsrc = EMAsum / Volsum;
def RMAsrc = RMAsum / Volsum;
def WMAsrc = WMAsum / Volsum;
def LRCsrc = LRCsum / Volsum;

def ma =
if matype == "VWAP" then f_Vwap(WAPsrc) else
if matype == "SWMA" then SWMA(SWMsrc) else
if matype == "VWMA" then vwma(VWMsrc, len2) else
if matype == "SMA"  then Average(SMAsrc, len2) else
if matype == "EMA"  then ExpAverage(EMAsrc, len2) else
if matype == "RMA"  then WildersAverage(RMAsrc, len2) else
if matype == "WMA"  then WMA (WMAsrc, len2) else
if matype == "LRC" then Inertia(LRCsrc, len2) else Average(SMAsrc, len2);
plot return = ma;
plot trend = all;
}

def line = vwosc(src, Length1, Length2, Length3, Length4, oscillatorLength, oscillatorType, MovAvgType, curve);
def VWOPvalue = line;
def ExtUp = src>VWOPvalue and VWOPvalue>Average(VWOPvalue, Length2);
def Up    = src>VWOPvalue and !ExtUp;
def ExtDn = src<VWOPvalue and VWOPvalue<Average(VWOPvalue, Length2);
def Dn    = src<VWOPvalue and !ExtDn;
plot VWOP = VWOPvalue;
VWOP.SetLineWeight(2);
VWOP.AssignValueColor(if src>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

AssignPriceColor(if !BarColor then Color.CURRENT else if src>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

plot trendUp = if ExtUp and Dn[1] then low else na;#, "Buy", Color.GREEN, no);
plot trendDn = if ExtDn and Up[1] then high else na;#, "Sell", Color.RED, yes);

trendUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
trendDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
trendUp.SetDefaultColor(Color.GREEN);
trendDn.SetDefaultColor(Color.RED);

#--- END CODE``````
Looks good

Does this study repaint? I'll check it out next week during the live market but curious if anyone knows?

Does this study repaint? I'll check it out next week during the live market but curious if anyone knows?
I don't see any cause of repainting, but you may check it live trading and provide your feedback.

This looks awesome. What are the best time frames and will it work accurately for tick charts?

This looks awesome. What are the best time frames and will it work accurately for tick charts?
Typical Timeframes
5-minute or 15-minute timeframes are the most typical when trading intraday to illustrate the trend.

Tick charts are limited to 5 days of data. So you will see the message below.
However, this will not affect your intraday use of this indicator on tick charts

Last edited:
Seems to work well on 15m time frame and lower.

Has anyone tried creating a MTF on this study? I tried and failed miserably as there are too many variables.

Just in case someone asks... using any of these studies on a 1, 2 or 3 min chart gives you a much earlier indication than say using it on a 15m or 30m with the MTF.

Seems to work well on 15m time frame and lower.

Has anyone tried creating a MTF on this study? I tried and failed miserably as there are too many variables.

Just in case someone asks... using any of these studies on a 1, 2 or 3 min chart gives you a much earlier indication than say using it on a 15m or 30m with the MTF.

check this .

CSS:
``````#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#indicator("Volume Weighted & Oscillated Price",shorttitle = "VWOP",overlay=true)
# converted and mod by Sam4Cok@Samer800 - 03/2023
# Update - MTF and signal style optios - 06/2023
input BarColor = no;
input signalStyle = {Default Wedges, Bubbles, "Dont' Show"};
input trendStrength = 0.1;
input useChartTimeframe = {Default "Yes", "No"};
input ManualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input src  = close;
input Length1 = 16;
input Length2 = 24;
input Length3 = 32;
input Length4 = 40;
input oscillatorLength = 16;
input oscillatorType = {RSI, CCI, COG, MFI, TSI, CMO, default COPPOCK, All};
input MovAvgType  = {VWAP, SWMA, VWMA, SMA, EMA, RMA, WMA, default LRC};
input curve   = {"Algo-1", "Algo-2",default "Algo-3", "Algo-4"};

def na = Double.NaN;
def wedge = signalStyle==signalStyle.Wedges;
def bubble = signalStyle==signalStyle.Bubbles;
def cTF; def lTF;def hTF;def vTf;
Switch(useChartTimeframe) {
Case "Yes" :
cTF = src;
hTF = high;
lTF = low;
vTf = volume;
Case "No" :
cTF = close(Period=ManualTimeframe);
hTF = high(Period=ManualTimeframe);
lTF = low(Period=ManualTimeframe);
vTf = volume(Period=ManualTimeframe);
}
script nz {
input data  = close;
input repl  = 0;
def ret_val = if !IsNaN(data) then data else repl;
plot return = ret_val;
}
#export f_Vwap(simple string tf, float src, float src_v) =>
script f_Vwap {
input src = close;
input src_v = Volume;
def tf = GetDay();
def start0 = tf - tf[1];
def sumSrc0 = src * src_v;
def sumVol0 = src_v;
def sumSrc1 = CompoundValue(1, if start0 then sumSrc0 else sumSrc0 + sumSrc1[1], sumSrc0);
def sumVol1 = CompoundValue(1, if start0 then sumVol0 else sumVol0 + sumVol1[1], sumVol0);
def Vwap = sumSrc1 / sumVol1;
plot wap = Vwap;
}
#f_cmo(src, length) =>
script cmo {
input src = close;
input length = 16;
def mom = (src-src[1]);
def sm1 = sum(if (mom >= 0) then mom else 0.0, length);
def sm2 = sum(if (mom >= 0) then 0.0 else -mom, length);
def cmo = 100 * (sm1 - sm2) / (sm1 + sm2);
plot out = cmo;
}
# roc(src, length)
script roc {
input src = close;
input length = 14;
def roc = if isNaN(src[length]) then 0 else
if src[length] !=0 then 100 * ((src - src[length])/ src[length]) else 0;
plot return = roc;
}
#vwma(source, length)
script vwma {
input x = close;
input y = 15;
input v = volume;
def VWMA = SimpleMovingAvg(x * nz(v,1), y) / SimpleMovingAvg(nz(v,1), y);
plot result = VWMA;
}
#pine_swma(x) =>
script swma {
input x = close;
def swma = nz(x[3],X[2]) * 1 / 6 + NZ(x[2],X[1]) * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6;
plot return = swma;
}
#cog(source, length) =>
script cog {
input source = close;
input length = 14;
def Msum = Sum(source, length);
def num;
num = fold i = 0 to length with p do
p + source[i] * (i + 1);
plot return = -num / Msum;
}
def nRSI = RSI(Price = cTF, Length = oscillatorLength);
def price = cTF + lTF + hTF;
def linDev = lindev(price, oscillatorLength);
def CCI = (price - Average(price, oscillatorLength)) / linDev / 0.015;
def nCCI = CCI;#(LENGTH = oscillatorLength);
def nCOG = cog(cTF, oscillatorLength);
def nMFI = MoneyFlowIndex(Length = oscillatorLength);
def nCMO = CMO(cTF, oscillatorLength);
def nTSI = TrueStrengthIndex(shortLength=oscillatorLength,longLength=Round(oscillatorLength * 1.5, 0));
def ROC1 = ROC(cTF, Round(1.1 * oscillatorLength, 0));
def ROC2 = ROC(cTF, Round(1.4 * oscillatorLength, 0));
def COPPOCK = WMA(ROC1 + ROC2, oscillatorLength);
def all = AbsValue(nRSI[1]-nrsi[Length1]) + AbsValue(nCCI[1]-nCCI[Length1]) +
AbsValue(nCOG[1]-nCOG[Length1]) + AbsValue(nMFI[1]-nMFI[Length1]) +
AbsValue(nCMO[1]-nCMO[Length1]) + AbsValue(COPPOCK[1]-COPPOCK[Length1]);
def osc;
Switch(oscillatorType) {
Case "All" : osc = all;
Case "RSI" : osc = nRSI;
Case "CCI" : osc = nCCI;
Case "COG" : osc = nCOG;
Case "MFI" : osc = nMFI;
Case "CMO" : osc = nCMO;
Case "TSI" : osc = nTSI;
Case "COPPOCK" : osc = COPPOCK;
}
def max = Highest(osc, 500);
def min = Lowest(osc, 500);
def dif = max - min;
def lev1;
Switch(curve) {
Case "Algo-1" :
lev1 = if osc - min < 0.25 * dif or max - osc < 0.25 * dif then Length1 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then Length2 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then Length3 else Length4;
Case "Algo-2" :
lev1 = if osc - min < 0.25 * dif or max - osc < 0.25 * dif then Length4 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then Length3 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then Length2 else Length1;
Case "Algo-3" :
lev1 = if osc - min < 0.25 * dif then Length1 else
if osc - min < 0.35 * dif then Round((Length1 + Length2) / 2, 0) else
if osc - min < 0.45 * dif then Length2 else
if osc - min < 0.55 * dif then Round((Length2 + Length3) / 2, 0) else
if osc - min < 0.65 * dif then Length3 else
if osc - min < 0.75 * dif then Round((Length3 + Length4) / 2, 0) else Length4;
Case "Algo-4" :
lev1 = if max - osc < 0.25 * dif then Length1 else
if max - osc < 0.35 * dif then Round((Length1 + Length2) / 2, 0) else
if max - osc < 0.45 * dif then Length2 else
if max - osc < 0.55 * dif then Round((Length2 + Length3) / 2, 0) else
if max - osc < 0.65 * dif then Length3 else
if max - osc < 0.75 * dif then Round((Length3 + Length4) / 2) else Length4;
}
def lev = if IsNaN(lev1) then if lev[1] == 0 then Length2 else lev[1] else lev1;

def v = vTf * vwap;
def swma = swma(cTF) * V;
def fwap = f_Vwap(cTF, vTf) * V;
def vwma = VWMA(cTF, Length1, vTf) * V;
def LRC  = Inertia(cTF, Length1) * V;
def SMA  = Average(cTF, Length1) * V;
def EMA  = ExpAverage(cTF, Length1) * V;
def RMA  = WildersAverage(cTF, Length1) * V;
def WMA  = WMA(cTF, Length1) * V;

def Volsum = fold i = 0 to lev with p do
p + GetValue(V, i);
def WAPsum = fold i1 =0 to lev with p1 do
p1 + GetValue(fwap, i1);
def SWMsum = fold i2 = 0 to lev with p2 do
p2 + GetValue(swma, i2);
def VWMsum = fold i3 = 0 to lev with p3 do
p3 + GetValue(vwma, i3);
def SMAsum = fold i4 = 0 to lev with p4 do
p4 + GetValue(SMA, i4);
def EMAsum = fold i5 = 0 to lev with p5 do
p5 + GetValue(EMA, i5);
def RMAsum = fold i6 = 0 to lev with p6 do
p6 + GetValue(RMA, i6);
def WMAsum = fold i7 = 0 to lev with p7 do
p7 + GetValue(WMA, i7);
def LRCsum = fold i8 = 0 to lev with p8 do
p8 + GetValue(LRC, i8);

def WAPsrc = WAPsum / Volsum;
def SWMsrc = SWMsum / Volsum;
def VWMsrc = VWMsum / Volsum;
def SMAsrc = SMAsum / Volsum;
def EMAsrc = EMAsum / Volsum;
def RMAsrc = RMAsum / Volsum;
def WMAsrc = WMAsum / Volsum;
def LRCsrc = LRCsum / Volsum;

def ma;
Switch (MovAvgType) {
Case "VWAP": ma = f_Vwap(WAPsrc, vTf);
Case "SWMA": ma = SWMA(SWMsrc);
Case "VWMA": ma = vwma(VWMsrc, Length2, vTf);
Case "SMA" : ma = Average(SMAsrc, Length2);
Case "EMA" : ma = ExpAverage(EMAsrc, Length2);
Case "RMA" : ma = WildersAverage(RMAsrc, Length2);
Case "WMA" : ma = WMA(WMAsrc, Length2);
Case "LRC" : ma = Inertia(LRCsrc, Length2);
}
#    plot trend = all;
#}

def line = ma;
def VWOPvalue = line;
def ExtUp = cTF>VWOPvalue and VWOPvalue>Average(VWOPvalue, Length2);
def Up    = cTF>VWOPvalue and !ExtUp;
def ExtDn = cTF<VWOPvalue and VWOPvalue<Average(VWOPvalue, Length2);
def Dn    = cTF<VWOPvalue and !ExtDn;
plot VWOP = VWOPvalue;
VWOP.SetLineWeight(2);
VWOP.AssignValueColor(if cTF>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

AssignPriceColor(if !BarColor then Color.CURRENT else if cTF>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

plot trendUp = if wedge and ExtUp and Dn[1] then low else na;#, "Buy";
plot trendDn = if wedge and  ExtDn and Up[1] then high else na;#, "Sell";

trendUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
trendDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
trendUp.SetDefaultColor(Color.GREEN);
trendDn.SetDefaultColor(Color.RED);

#-- Bubbles

AddChartBubble(Bubble and ExtDn and Up[1], high, "Sell", Color.RED, yes);

#--- END CODE``````

Copy and paste this to use as lower indicator
Ruby:
``````declare lower;
input BarColor = yes;
input trendStrength = 0.1;
input src = close;
input Length1 = 16;
input Length2 = 24;
input Length3 = 32;
input Length4 = 40;
input oscillatorLength = 16;
input oscillatorType = {RSI, CCI, COG, MFI, TSI, CMO, default COPPOCK, All};
input MovAvgType = {VWAP, SWMA, VWMA, SMA, EMA, RMA, WMA, default LRC};
input curve = {"Algo-1", "Algo-2",default "Algo-3", "Algo-4"};

def na = Double.NaN;
script nz {
input data = close;
input repl = 0;
def ret_val = if !IsNaN(data) then data else repl;
plot return = ret_val;
}
#export f_Vwap(simple string tf, float src, float src_v) =>
script f_Vwap {
input src = close;
def src_v = Volume;
def tf = GetDay();
def start0 = tf - tf[1];
def sumSrc0 = src * src_v;
def sumVol0 = src_v;
def sumSrc1 = CompoundValue(1, if start0 then sumSrc0 else sumSrc0 + sumSrc1[1], sumSrc0);
def sumVol1 = CompoundValue(1, if start0 then sumVol0 else sumVol0 + sumVol1[1], sumVol0);
def Vwap = sumSrc1 / sumVol1;
plot wap = Vwap;
}
#f_cmo(src, length) =>
script cmo {
input src = close;
input length = 16;
def mom = (src-src[1]);
def sm1 = sum(if (mom >= 0) then mom else 0.0, length);
def sm2 = sum(if (mom >= 0) then 0.0 else -mom, length);
def cmo = 100 * (sm1 - sm2) / (sm1 + sm2);
plot out = cmo;
}
# roc(src, length)
script roc {
input src = close;
input length = 14;
def roc = if isNaN(src[length]) then 0 else
if src[length] !=0 then 100 * ((src - src[length])/ src[length]) else 0;
plot return = roc;
}
#vwma(source, length)
script vwma {
input x = close;
input y = 15;
def v = volume;
def VWMA = SimpleMovingAvg(x * nz(v,1), y) / SimpleMovingAvg(nz(v,1), y);
plot result = VWMA;
}
#pine_swma(x) =>
script swma {
input x = close;
def swma = nz(x[3],X[2]) * 1 / 6 + NZ(x[2],X[1]) * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6;
plot return = swma;
}
#cog(source, length) =>
script cog {
input source = close;
input length = 14;
def Msum = Sum(source, length);
def num;
num = fold i = 0 to length with p do
p + source * (i + 1);
plot return = -num / Msum;
}
#vwosc(src,len1=16,len2=24,len3=32,len4=40,osclen=16,string osctype="RSI",matype="LRC",curve="<>")=>
script vwosc {
input src = close;
input len1 = 16;
input len2 = 24;
input len3 = 32;
input len4 = 40;
input osclen = 16;
input osctype = "RSI";
input matype = "LRC";
input curve = "Algo-1";
def nRSI = RSI(Price = src, Length = osclen);
def nCCI = CCI(LENGTH = osclen);
def nCOG = cog(src, osclen);
def nMFI = MoneyFlowIndex(Length = osclen);
def nCMO = CMO(src, osclen);
def nTSI = TrueStrengthIndex(shortLength=osclen,longLength=Round(osclen * 1.5, 0));
def ROC1 = ROC(src, Round(1.1 * osclen, 0));
def ROC2 = ROC(src, Round(1.4 * osclen, 0));
def COPPOCK = WMA(ROC1 + ROC2, osclen);
def all = AbsValue(nRSI[1]-nrsi[len1]) + AbsValue(nCCI[1]-nCCI[len1]) +
AbsValue(nCOG[1]-nCOG[len1]) + AbsValue(nMFI[1]-nMFI[len1]) +
AbsValue(nCMO[1]-nCMO[len1]) + AbsValue(COPPOCK[1]-COPPOCK[len1]);
def osc = if osctype == "All" then all else
if osctype == "RSI" then nRSI else
if osctype == "CCI" then nCCI else
if osctype == "COG" then nCOG else
if osctype == "MFI" then nMFI else
if osctype == "CMO" then nCMO else
if osctype == "TSI" then nTSI else
if osctype == "COPPOCK" then COPPOCK else nRSI;

def max = Highest(osc, 500);
def min = Lowest(osc, 500);
def dif = max - min;
def lev1 =
if curve == "Algo-3" then
if osc - min < 0.25 * dif then len1 else
if osc - min < 0.35 * dif then Round((len1 + len2) / 2, 0) else
if osc - min < 0.45 * dif then len2 else
if osc - min < 0.55 * dif then Round((len2 + len3) / 2, 0) else
if osc - min < 0.65 * dif then len3 else
if osc - min < 0.75 * dif then Round((len3 + len4) / 2, 0) else len4 else
if curve == "Algo-1" then
if osc - min < 0.25 * dif or max - osc < 0.25 * dif then len1 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then len2 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then len3 else len4 else
if curve == "Algo-2" then
if osc - min < 0.25 * dif or max - osc < 0.25 * dif then len4 else
if osc - min < 0.35 * dif or max - osc < 0.35 * dif then len3 else
if osc - min < 0.45 * dif or max - osc < 0.45 * dif then len2 else len1 else
if curve == "Algo-4" then
if max - osc < 0.25 * dif then len1 else
if max - osc < 0.35 * dif then Round((len1 + len2) / 2, 0) else
if max - osc < 0.45 * dif then len2 else
if max - osc < 0.55 * dif then Round((len2 + len3) / 2, 0) else
if max - osc < 0.65 * dif then len3 else
if max - osc < 0.75 * dif then Round((len3 + len4) / 2) else len4 else lev1[1];
def lev = if IsNaN(lev1) then if lev[1] == 0 then len2 else lev[1] else lev1;

def v = Volume * vwap;
def swma = swma(src) * V;
def fwap = f_Vwap(src) * V;
def vwma = VWMA(src, len1) * V;
def LRC = Inertia(src, len1) * V;
def SMA = Average(src, len1) * V;
def EMA = ExpAverage(src, len1) * V;
def RMA = WildersAverage(src, len1) * V;
def WMA = WMA(src, len1) * V;

def Volsum = fold i = 0 to lev with p do
p + GetValue(V, i);
def WAPsum = fold i1 =0 to lev with p1 do
p1 + GetValue(fwap, i1);
def SWMsum = fold i2 = 0 to lev with p2 do
p2 + GetValue(swma, i2);
def VWMsum = fold i3 = 0 to lev with p3 do
p3 + GetValue(vwma, i3);
def SMAsum = fold i4 = 0 to lev with p4 do
p4 + GetValue(SMA, i4);
def EMAsum = fold i5 = 0 to lev with p5 do
p5 + GetValue(EMA, i5);
def RMAsum = fold i6 = 0 to lev with p6 do
p6 + GetValue(RMA, i6);
def WMAsum = fold i7 = 0 to lev with p7 do
p7 + GetValue(WMA, i7);
def LRCsum = fold i8 = 0 to lev with p8 do
p8 + GetValue(LRC, i8);

def WAPsrc = WAPsum / Volsum;
def SWMsrc = SWMsum / Volsum;
def VWMsrc = VWMsum / Volsum;
def SMAsrc = SMAsum / Volsum;
def EMAsrc = EMAsum / Volsum;
def RMAsrc = RMAsum / Volsum;
def WMAsrc = WMAsum / Volsum;
def LRCsrc = LRCsum / Volsum;

def ma =
if matype == "VWAP" then f_Vwap(WAPsrc) else
if matype == "SWMA" then SWMA(SWMsrc) else
if matype == "VWMA" then vwma(VWMsrc, len2) else
if matype == "SMA" then Average(SMAsrc, len2) else
if matype == "EMA" then ExpAverage(EMAsrc, len2) else
if matype == "RMA" then WildersAverage(RMAsrc, len2) else
if matype == "WMA" then WMA (WMAsrc, len2) else
if matype == "LRC" then Inertia(LRCsrc, len2) else Average(SMAsrc, len2);
plot return = ma;
plot trend = all;
}

def line = vwosc(src, Length1, Length2, Length3, Length4, oscillatorLength, oscillatorType, MovAvgType, curve);
def VWOPvalue = line;
def ExtUp = src>VWOPvalue and VWOPvalue>Average(VWOPvalue, Length2);
def Up = src>VWOPvalue and !ExtUp;
def ExtDn = src<VWOPvalue and VWOPvalue<Average(VWOPvalue, Length2);
def Dn = src<VWOPvalue and !ExtDn;
plot VWOP = VWOPvalue;
VWOP.SetLineWeight(2);
VWOP.AssignValueColor(if src>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

AssignPriceColor(if !BarColor then Color.CURRENT else if src>VWOPvalue then
if VWOPvalue>Average(VWOPvalue, Length2) then Color.GREEN else Color.DARK_GREEN else
if VWOPvalue<Average(VWOPvalue, Length2) then Color.RED else Color.DARK_RED);

plot trendUp = if ExtUp and Dn[1] then low else na;#, "Buy", Color.GREEN, no);
plot trendDn = if ExtDn and Up[1] then high else na;#, "Sell", Color.RED, yes);

trendUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
trendDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
trendUp.SetDefaultColor(Color.GREEN);
trendDn.SetDefaultColor(Color.RED);``````

Last edited by a moderator:

87k+ Posts
412 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?