forex20723
New member
Last edited by a moderator:
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
input Length = 14;
input Src = Close;
def Mom = Src - Src[1];
def UpSum = sum(max(Mom,0),Length);
def DownSum = sum(-min(Mom, 0), Length);
def Out = (UpSum - DownSum) / (UpSum + DownSum);
def Cmo = absvalue(Out);
def Alpha = 2 / (Length + 1);
def Vidya = Src * Alpha * Cmo + (if isNaN(Vidya[1]) then 0 else Vidya[1]) * (1 - Alpha * Cmo);
plot x = Vidya;
declare Lower;
input period1 = 3;
input period2 = 5;
input period3 = 8;
input period4 = 10;
input period5 = 12;
input period6 = 15;
input period7 = 30;
input period8 = 35;
input period9 = 40;
input period10 = 45;
input period11 = 50;
input period12 = 60;
input paintbars = 0;
input arrows = 0;
Input Label = 0;
input soundAlert = No;
Input dotsize = 3;
Def src = (Open + Close)/2;
def Mom = Src - Src[1];
def UpSumA = sum(max(Mom,0),Period1);
def DownSumA = sum(-min(Mom, 0), Period1);
def OutA = (UpSumA - DownSumA) / (UpSumA + DownSumA);
def CmoA = absvalue(OutA);
def AlphaA = 2 / (Period1 + 1);
def VidyaA = Src * AlphaA * CmoA + (if isNaN(VidyaA[1]) then 0 else VidyaA[1]) * (1 - AlphaA * CmoA);
def UpSumB = sum(max(Mom,0),Period2);
def DownSumB = sum(-min(Mom, 0), Period2);
def OutB = (UpSumB - DownSumB) / (UpSumB + DownSumB);
def CmoB = absvalue(OutB);
def AlphaB = 2 / (Period2 + 1);
def VidyaB = Src * AlphaB * CmoB + (if isNaN(VidyaB[1]) then 0 else VidyaB[1]) * (1 - AlphaB * CmoB);
def UpSumC = sum(max(Mom,0),Period3);
def DownSumC = sum(-min(Mom, 0), Period3);
def OutC = (UpSumC - DownSumC) / (UpSumC + DownSumC);
def CmoC = absvalue(OutC);
def AlphaC = 2 / (Period3 + 1);
def VidyaC = Src * AlphaC * CmoC + (if isNaN(VidyaC[1]) then 0 else VidyaC[1]) * (1 – AlphaC * CmoC);
def UpSumD = sum(max(Mom,0),Period4);
def DownSumD = sum(-min(Mom, 0), Period4);
def OutD = (UpSumD - DownSumD) / (UpSumD + DownSumD);
def CmoD = absvalue(OutD);
def AlphaD = 2 / (Period4 + 1);
def VidyaD = Src * AlphaD * CmoD + (if isNaN(VidyaD[1]) then 0 else VidyaD[1]) * (1 – AlphaD * CmoD);
def UpSumE = sum(max(Mom,0),Period5);
def DownSumE = sum(-min(Mom, 0), Period5);
def OutE = (UpSumE - DownSumE) / (UpSumE + DownSumE);
def CmoE = absvalue(OutE);
def AlphaE = 2 / (Period5 + 1);
def VidyaE = Src * AlphaE * CmoE + (if isNaN(VidyaE[1]) then 0 else VidyaE[1]) * (1 – AlphaE * CmoE);
def UpSumF = sum(max(Mom,0),Period6);
def DownSumF = sum(-min(Mom, 0), Period6);
def OutF = (UpSumF- DownSumF) / (UpSumF + DownSumF);
def CmoF = absvalue(OutF);
def AlphaF = 2 / (Period6 + 1);
def VidyaF = Src * AlphaF * CmoF+ (if isNaN(VidyaF[1]) then 0 else VidyaF[1]) * (1 – AlphaF * CmoF);
def UpSumG = sum(max(Mom,0),Period7);
def DownSumG = sum(-min(Mom, 0), Period7);
def OutG = (UpSumG - DownSumG) / (UpSumG + DownSumG);
def CmoG = absvalue(OutG);
def AlphaG = 2 / (Period7 + 1);
def VidyaG = Src * AlphaG * CmoG + (if isNaN(VidyaG[1]) then 0 else VidyaG[1]) * (1 – AlphaG * CmoG);
def UpSumH = sum(max(Mom,0),Period8);
def DownSumH = sum(-min(Mom, 0), Period8);
def OutH = (UpSumH - DownSumH) / (UpSumH+ DownSumH);
def CmoH = absvalue(OutH);
def AlphaH = 2 / (Period8 + 1);
def VidyaH = Src * AlphaH * CmoH + (if isNaN(VidyaH[1]) then 0 else VidyaH[1]) * (1 – AlphaH * CmoH);
def UpSumI = sum(max(Mom,0),Period9);
def DownSumI = sum(-min(Mom, 0), Period9);
def OutI = (UpSumI - DownSumI) / (UpSumI + DownSumI);
def CmoI = absvalue(OutI);
def AlphaI = 2 / (Period9 + 1);
def VidyaI = Src * AlphaI * CmoI + (if isNaN(VidyaI[1]) then 0 else VidyaI[1]) * (1 – AlphaI * CmoI);
def UpSumJ = sum(max(Mom,0),Period10);
def DownSumJ = sum(-min(Mom, 0), Period10);
def OutJ = (UpSumJ - DownSumJ) / (UpSumJ + DownSumJ);
def CmoJ = absvalue(OutJ);
def AlphaJ = 2 / (Period10 + 1);
def VidyaJ = Src * AlphaJ * CmoJ + (if isNaN(VidyaJ[1]) then 0 else VidyaJ[1]) * (1 – AlphaJ * CmoJ);
def UpSumK = sum(max(Mom,0),Period11);
def DownSumK = sum(-min(Mom, 0), Period11);
def OutK = (UpSumK - DownSumK) / (UpSumK + DownSumK);
def CmoK = absvalue(OutK);
def AlphaK= 2 / (Period11 + 1);
def VidyaK = Src * AlphaK * CmoK + (if isNaN(VidyaK[1]) then 0 else VidyaK[1]) * (1 – AlphaK * CmoK);
def UpSumL = sum(max(Mom,0),Period12);
def DownSumL = sum(-min(Mom, 0), Period12);
def OutL = (UpSumL - DownSumL) / (UpSumL + DownSumL);
def CmoL = absvalue(OutL);
def AlphaL = 2 / (Period12 + 1);
def VidyaL = Src * AlphaL * CmoL + (if isNaN(VidyaL[1]) then 0 else VidyaL[1]) * (1 – AlphaL * CmoL);
plot A1_Dot = if IsNaN(Close) then Double.NaN else 1;
A1_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A1_Dot.SetLineWeight(DotSize);
A1_Dot.AssignValueColor(if VidyaA >= VidyaA[1] then Color.Cyan else Color.Magenta);
plot A2_Dot = if IsNaN(Close) then Double.NaN else 2;
A2_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A2_Dot.SetLineWeight(DotSize);
A2_Dot.AssignValueColor(if VidyaB >= VidyaB[1] then Color.Cyan else Color.Magenta);
plot A3_Dot = if IsNaN(Close) then Double.NaN else 3;
A3_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A3_Dot.SetLineWeight(DotSize);
A3_Dot.AssignValueColor(if VidyaC >= VidyaC[1] then Color.Cyan else Color.Magenta);
plot A4_Dot = if IsNaN(Close) then Double.NaN else 4;
A4_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A4_Dot.SetLineWeight(DotSize);
A4_Dot.AssignValueColor(if VidyaD >= VidyaD[1] then Color.Cyan else Color.Magenta);
plot A5_Dot = if IsNaN(Close) then Double.NaN else 5;
A5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A5_Dot.SetLineWeight(DotSize);
A5_Dot.AssignValueColor(if VidyaE >= VidyaE[1] then Color.Cyan else Color.Magenta);
plot A6_Dot = if IsNaN(Close) then Double.NaN else 6;
A6_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A6_Dot.SetLineWeight(DotSize);
A6_Dot.AssignValueColor(if VidyaF >= VidyaF[1] then Color.Cyan else Color.Magenta);
plot A8_Dot = if IsNaN(Close) then Double.NaN else 8;
A8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A8_Dot.SetLineWeight(DotSize);
A8_Dot.AssignValueColor(if VidyaG >= VidyaG[1] then Color.BLUE else Color.RED);
plot A9_Dot = if IsNaN(Close) then Double.NaN else 9;
A9_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A9_Dot.SetLineWeight(DotSize);
A9_Dot.AssignValueColor(if VidyaH >= VidyaH[1] then Color.BLUE else Color.RED);
plot A10_Dot = if IsNaN(Close) then Double.NaN else 10;
A10_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A10_Dot.SetLineWeight(DotSize);
A10_Dot.AssignValueColor(if VidyaI >= VidyaI[1] then Color.BLUE else Color.RED);
plot A11_Dot = if IsNaN(Close) then Double.NaN else 11;
A11_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A11_Dot.SetLineWeight(DotSize);
A11_Dot.AssignValueColor(if VidyaJ >= VidyaJ[1] then Color.BLUE else Color.RED);
plot A12_Dot = if IsNaN(Close) then Double.NaN else 12;
A12_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A12_Dot.SetLineWeight(DotSize);
A12_Dot.AssignValueColor(if VidyaK >= VidyaK[1] then Color.BLUE else Color.RED);
plot A13_Dot = if IsNaN(Close) then Double.NaN else 13;
A13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
A13_Dot.SetLineWeight(DotSize);
A13_Dot.AssignValueColor(if VidyaL >= VidyaL[1] then Color.BLUE else Color.RED);
AssignPriceColor(if paintbars == 1 and VidyaA > VidyaA[1] then Color.Cyan else if paintbars == 1 and VidyaA < VidyaA[1] then Color.Magenta else if paintbars == 2 and VidyaB > VidyaB[1] then Color.Cyan else if paintbars == 2 and VidyaB < VidyaB[1] then Color.Magenta else if paintbars == 3 and VidyaC > VidyaC[1] then Color.Cyan else if paintbars == 3 and VidyaC < VidyaC[1] then Color.Magenta else if paintbars == 4 and VidyaD > VidyaD[1] then Color.Cyan else if paintbars == 4 and VidyaD < VidyaD[1] then Color.Magenta else
if paintbars == 5 and VidyaE > VidyaE[1] then Color.Cyan else if paintbars == 5 and VidyaE < VidyaE[1] then Color.Magenta else if paintbars == 6 and VidyaF > VidyaF[1] then Color.Cyan else if paintbars == 6 and VidyaF < VidyaF[1] then Color.Magenta else if paintbars == 8 and VidyaG > VidyaG[1] then Color.Blue else if paintbars == 8 and VidyaG < VidyaG[1] then Color.Red else if paintbars == 9 and VidyaH > VidyaH[1] then Color.Blue else if paintbars == 9 and VidyaH < VidyaH[1] then Color.Red else
if paintbars == 10 and VidyaI > VidyaI[1] then Color.Blue else if paintbars == 10 and VidyaI < VidyaI[1] then Color.Red else if paintbars == 11 and VidyaJ > VidyaJ[1] then Color.Blue else if paintbars == 11 and VidyaJ < VidyaJ[1] then Color.Red else if paintbars == 12 and VidyaK > VidyaK[1] then Color.Blue else if paintbars == 12 and VidyaK < VidyaK[1] then Color.Red else if paintbars == 13 and VidyaL > VidyaL[1] then Color.Blue else if paintbars == 13 and VidyaL < VidyaL[1] then Color.Red else
color.Current);
Using the Vidya and Guppy Lengths I created a Binary indicator
Code:declare Lower; input period1 = 3; input period2 = 5; input period3 = 8; input period4 = 10; input period5 = 12; input period6 = 15; input period7 = 30; input period8 = 35; input period9 = 40; input period10 = 45; input period11 = 50; input period12 = 60; input paintbars = 0; input arrows = 0; Input Label = 0; input soundAlert = No; Input dotsize = 3; Def src = (Open + Close)/2; def Mom = Src - Src[1]; def UpSumA = sum(max(Mom,0),Period1); def DownSumA = sum(-min(Mom, 0), Period1); def OutA = (UpSumA - DownSumA) / (UpSumA + DownSumA); def CmoA = absvalue(OutA); def AlphaA = 2 / (Period1 + 1); def VidyaA = Src * AlphaA * CmoA + (if isNaN(VidyaA[1]) then 0 else VidyaA[1]) * (1 - AlphaA * CmoA); def UpSumB = sum(max(Mom,0),Period2); def DownSumB = sum(-min(Mom, 0), Period2); def OutB = (UpSumB - DownSumB) / (UpSumB + DownSumB); def CmoB = absvalue(OutB); def AlphaB = 2 / (Period2 + 1); def VidyaB = Src * AlphaB * CmoB + (if isNaN(VidyaB[1]) then 0 else VidyaB[1]) * (1 - AlphaB * CmoB); def UpSumC = sum(max(Mom,0),Period3); def DownSumC = sum(-min(Mom, 0), Period3); def OutC = (UpSumC - DownSumC) / (UpSumC + DownSumC); def CmoC = absvalue(OutC); def AlphaC = 2 / (Period3 + 1); def VidyaC = Src * AlphaC * CmoC + (if isNaN(VidyaC[1]) then 0 else VidyaC[1]) * (1 – AlphaC * CmoC); def UpSumD = sum(max(Mom,0),Period4); def DownSumD = sum(-min(Mom, 0), Period4); def OutD = (UpSumD - DownSumD) / (UpSumD + DownSumD); def CmoD = absvalue(OutD); def AlphaD = 2 / (Period4 + 1); def VidyaD = Src * AlphaD * CmoD + (if isNaN(VidyaD[1]) then 0 else VidyaD[1]) * (1 – AlphaD * CmoD); def UpSumE = sum(max(Mom,0),Period5); def DownSumE = sum(-min(Mom, 0), Period5); def OutE = (UpSumE - DownSumE) / (UpSumE + DownSumE); def CmoE = absvalue(OutE); def AlphaE = 2 / (Period5 + 1); def VidyaE = Src * AlphaE * CmoE + (if isNaN(VidyaE[1]) then 0 else VidyaE[1]) * (1 – AlphaE * CmoE); def UpSumF = sum(max(Mom,0),Period6); def DownSumF = sum(-min(Mom, 0), Period6); def OutF = (UpSumF- DownSumF) / (UpSumF + DownSumF); def CmoF = absvalue(OutF); def AlphaF = 2 / (Period6 + 1); def VidyaF = Src * AlphaF * CmoF+ (if isNaN(VidyaF[1]) then 0 else VidyaF[1]) * (1 – AlphaF * CmoF); def UpSumG = sum(max(Mom,0),Period7); def DownSumG = sum(-min(Mom, 0), Period7); def OutG = (UpSumG - DownSumG) / (UpSumG + DownSumG); def CmoG = absvalue(OutG); def AlphaG = 2 / (Period7 + 1); def VidyaG = Src * AlphaG * CmoG + (if isNaN(VidyaG[1]) then 0 else VidyaG[1]) * (1 – AlphaG * CmoG); def UpSumH = sum(max(Mom,0),Period8); def DownSumH = sum(-min(Mom, 0), Period8); def OutH = (UpSumH - DownSumH) / (UpSumH+ DownSumH); def CmoH = absvalue(OutH); def AlphaH = 2 / (Period8 + 1); def VidyaH = Src * AlphaH * CmoH + (if isNaN(VidyaH[1]) then 0 else VidyaH[1]) * (1 – AlphaH * CmoH); def UpSumI = sum(max(Mom,0),Period9); def DownSumI = sum(-min(Mom, 0), Period9); def OutI = (UpSumI - DownSumI) / (UpSumI + DownSumI); def CmoI = absvalue(OutI); def AlphaI = 2 / (Period9 + 1); def VidyaI = Src * AlphaI * CmoI + (if isNaN(VidyaI[1]) then 0 else VidyaI[1]) * (1 – AlphaI * CmoI); def UpSumJ = sum(max(Mom,0),Period10); def DownSumJ = sum(-min(Mom, 0), Period10); def OutJ = (UpSumJ - DownSumJ) / (UpSumJ + DownSumJ); def CmoJ = absvalue(OutJ); def AlphaJ = 2 / (Period10 + 1); def VidyaJ = Src * AlphaJ * CmoJ + (if isNaN(VidyaJ[1]) then 0 else VidyaJ[1]) * (1 – AlphaJ * CmoJ); def UpSumK = sum(max(Mom,0),Period11); def DownSumK = sum(-min(Mom, 0), Period11); def OutK = (UpSumK - DownSumK) / (UpSumK + DownSumK); def CmoK = absvalue(OutK); def AlphaK= 2 / (Period11 + 1); def VidyaK = Src * AlphaK * CmoK + (if isNaN(VidyaK[1]) then 0 else VidyaK[1]) * (1 – AlphaK * CmoK); def UpSumL = sum(max(Mom,0),Period12); def DownSumL = sum(-min(Mom, 0), Period12); def OutL = (UpSumL - DownSumL) / (UpSumL + DownSumL); def CmoL = absvalue(OutL); def AlphaL = 2 / (Period12 + 1); def VidyaL = Src * AlphaL * CmoL + (if isNaN(VidyaL[1]) then 0 else VidyaL[1]) * (1 – AlphaL * CmoL); plot A1_Dot = if IsNaN(Close) then Double.NaN else 1; A1_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A1_Dot.SetLineWeight(DotSize); A1_Dot.AssignValueColor(if VidyaA >= VidyaA[1] then Color.Cyan else Color.Magenta); plot A2_Dot = if IsNaN(Close) then Double.NaN else 2; A2_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A2_Dot.SetLineWeight(DotSize); A2_Dot.AssignValueColor(if VidyaB >= VidyaB[1] then Color.Cyan else Color.Magenta); plot A3_Dot = if IsNaN(Close) then Double.NaN else 3; A3_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A3_Dot.SetLineWeight(DotSize); A3_Dot.AssignValueColor(if VidyaC >= VidyaC[1] then Color.Cyan else Color.Magenta); plot A4_Dot = if IsNaN(Close) then Double.NaN else 4; A4_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A4_Dot.SetLineWeight(DotSize); A4_Dot.AssignValueColor(if VidyaD >= VidyaD[1] then Color.Cyan else Color.Magenta); plot A5_Dot = if IsNaN(Close) then Double.NaN else 5; A5_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A5_Dot.SetLineWeight(DotSize); A5_Dot.AssignValueColor(if VidyaE >= VidyaE[1] then Color.Cyan else Color.Magenta); plot A6_Dot = if IsNaN(Close) then Double.NaN else 6; A6_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A6_Dot.SetLineWeight(DotSize); A6_Dot.AssignValueColor(if VidyaF >= VidyaF[1] then Color.Cyan else Color.Magenta); plot A8_Dot = if IsNaN(Close) then Double.NaN else 8; A8_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A8_Dot.SetLineWeight(DotSize); A8_Dot.AssignValueColor(if VidyaG >= VidyaG[1] then Color.BLUE else Color.RED); plot A9_Dot = if IsNaN(Close) then Double.NaN else 9; A9_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A9_Dot.SetLineWeight(DotSize); A9_Dot.AssignValueColor(if VidyaH >= VidyaH[1] then Color.BLUE else Color.RED); plot A10_Dot = if IsNaN(Close) then Double.NaN else 10; A10_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A10_Dot.SetLineWeight(DotSize); A10_Dot.AssignValueColor(if VidyaI >= VidyaI[1] then Color.BLUE else Color.RED); plot A11_Dot = if IsNaN(Close) then Double.NaN else 11; A11_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A11_Dot.SetLineWeight(DotSize); A11_Dot.AssignValueColor(if VidyaJ >= VidyaJ[1] then Color.BLUE else Color.RED); plot A12_Dot = if IsNaN(Close) then Double.NaN else 12; A12_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A12_Dot.SetLineWeight(DotSize); A12_Dot.AssignValueColor(if VidyaK >= VidyaK[1] then Color.BLUE else Color.RED); plot A13_Dot = if IsNaN(Close) then Double.NaN else 13; A13_Dot.SetPaintingStrategy(PaintingStrategy.POINTS); A13_Dot.SetLineWeight(DotSize); A13_Dot.AssignValueColor(if VidyaL >= VidyaL[1] then Color.BLUE else Color.RED); AssignPriceColor(if paintbars == 1 and VidyaA > VidyaA[1] then Color.Cyan else if paintbars == 1 and VidyaA < VidyaA[1] then Color.Magenta else if paintbars == 2 and VidyaB > VidyaB[1] then Color.Cyan else if paintbars == 2 and VidyaB < VidyaB[1] then Color.Magenta else if paintbars == 3 and VidyaC > VidyaC[1] then Color.Cyan else if paintbars == 3 and VidyaC < VidyaC[1] then Color.Magenta else if paintbars == 4 and VidyaD > VidyaD[1] then Color.Cyan else if paintbars == 4 and VidyaD < VidyaD[1] then Color.Magenta else if paintbars == 5 and VidyaE > VidyaE[1] then Color.Cyan else if paintbars == 5 and VidyaE < VidyaE[1] then Color.Magenta else if paintbars == 6 and VidyaF > VidyaF[1] then Color.Cyan else if paintbars == 6 and VidyaF < VidyaF[1] then Color.Magenta else if paintbars == 8 and VidyaG > VidyaG[1] then Color.Blue else if paintbars == 8 and VidyaG < VidyaG[1] then Color.Red else if paintbars == 9 and VidyaH > VidyaH[1] then Color.Blue else if paintbars == 9 and VidyaH < VidyaH[1] then Color.Red else if paintbars == 10 and VidyaI > VidyaI[1] then Color.Blue else if paintbars == 10 and VidyaI < VidyaI[1] then Color.Red else if paintbars == 11 and VidyaJ > VidyaJ[1] then Color.Blue else if paintbars == 11 and VidyaJ < VidyaJ[1] then Color.Red else if paintbars == 12 and VidyaK > VidyaK[1] then Color.Blue else if paintbars == 12 and VidyaK < VidyaK[1] then Color.Red else if paintbars == 13 and VidyaL > VidyaL[1] then Color.Blue else if paintbars == 13 and VidyaL < VidyaL[1] then Color.Red else color.Current);
The fastest lengths are on the lower lines and the longest lengths are on top. They color cyan or blue when the MA is greater or equal than the day before else they color Magenta or redThank you. But how do you use this indicator ? How are the signals determined ?
Start a new thread and receive assistance from our community.
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.
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.