Create custom column in watchlist to reflect indicator color?

  • Thread starter hockeycoachdoug
  • Start date
H

hockeycoachdoug

Member
2019 Donor
VIP
Here is what I want to accomplish. I have a paint bar indicator which colors the bars red, gray, green. I want to add a 2 custom columns to a watch list showing the bars color on a daily basis and another custom column showing the bars color on a weekly basis. Actually I envision using various time frames, but if I see how you do this I should be able to change time frames myself. Below is the actual code of the indicator. Can someone help me code this. Thanks in advance.

Code:
input Trend = yes;
input Cycle = yes;
input Mom = yes;


DefineGlobalColor("UpColor", Color.GREEN);
DefineGlobalColor("DnColor", Color.RED);
DefineGlobalColor("NeutralColor", Color.LiGHT_GRAY);

script MyStdDev {
    input data = close;
    input length = 12;
    input dataType = 2;

    def divisor = if dataType == 1 then length else length - 1;

    def _std = StDev(data, length);
    def _sqrOfStd = _std * _std;
    def _sumSqr = _sqrOfStd * length;
    def _variancePS = if divisor>0 then _sumSqr / divisor else 0;
    #def Value1 = VariancePS( data, Length, count, DataType ).VALUE ;

    #def _std = if (Value1>0) then sqrt(value1) else 0;
    #plot STD = _std ;

    plot STD = If (_variancePS > 0, Sqrt(_variancePS), 0);
}

def BuyEntry = 55;
def SellEntry = 55;
def BuyExit = 20;
def SellExit = 20;

def BuyLevel = Highest(High, BuyEntry)[1];
def SellLevel = Lowest(Low, SellEntry)[1];

#{Sets Switchside to 1 for Buy Trend or -1 for Sell Trend}
def SwitchSide = CompoundValue(1, if (High > BuyLevel and Switchside[1] < 1) then 1 else if Low < SellLevel and switchside[1] > -1 then -1 else switchside[1], 0);

def Trendstatus = Switchside;



def MomLength = 12;
def SmoothLength = 21;
def Candle = (hl2 - hl2[1]);
def CSmooth = Max((ExpAverage(ExpAverage(Absvalue(Candle),MomLength),SmoothLength)),.000001);
def CMom = 100*((ExpAverage(ExpAverage(Candle,MomLength),SmoothLength))/CSmooth);

def MomB = If CMom < 0 then 0 else If CMom >= 0 then 1 else MomB[1];

def MomS = If CMom >= 0 then 0 else If CMom < 0 then -1 else MomS[1];

def FastVar5 = MovAvgExponential(hl2,5);
def SlowVar5 = Average(hl2,8);
def DiffVar5 = FastVar5 - SlowVar5;
def FastVar8 = MovAvgExponential(hl2,8);
def SlowVar8 = Average(hl2,13);
def DiffVar8 = FastVar8 - SlowVar8;
def FastVar13 = MovAvgExponential(hl2,13);
def SlowVar13 = Average(hl2,21);
def DiffVar13 = FastVar13 - SlowVar13;
def FastVar21 = MovAvgExponential(hl2,21);
def SlowVar21 = Average(hl2,35);
def DiffVar21 = FastVar21 - SlowVar21;
def FastVar35 = MovAvgExponential(hl2,35);
def SlowVar35 = Average(hl2,55);
def DiffVar35 = FastVar35 - SlowVar35;

def TotCycle = DiffVar5 + DiffVar8 + DiffVar13 + DiffVar21 + DiffVar35;

def PowerB = If TotCycle < 0 then 0 else If TotCycle >= 0 then 1 else PowerB[1];

def PowerS = If TotCycle >= 0 then 0 else If TotCycle < 0 then -1 else PowerS[1];


def Condition1 = Trend and Cycle and Mom;
def Condition2 = Trend==no and Cycle==no and Mom==no;
def Condition3 = Trend and Cycle == no and Mom==no;
def Condition4 = Trend == no and Cycle==no and Mom;
def Condition5 = Trend == no and Cycle and Mom==no;
def Condition6 = Trend and Cycle and Mom==no;
def Condition7 = Trend and Cycle==no and Mom;
def Condition8 = Trend==no and Cycle and Mom;

def Value1B = Trendstatus + MomB + PowerB;
def Value1S = Trendstatus + MomS + PowerS;

def Value6B = Trendstatus + PowerB;
def Value6S = Trendstatus + PowerS;

def Value7B = Trendstatus + MomB;
def Value7S = Trendstatus + MomS;

def Value8B = PowerB + MomB;
def Value8S = PowerS + MomS;

def Value4B = PowerB + MomB;
def Value4S = PowerS + MomS;

def C1 = Condition1 and Value1B >= 3;
def C2 = Condition1 and Value1S <= -3;
def C3 = Condition1 and Value1B < 3 and Value1S > -3;

def C4 = Condition2;
def C5 = Condition3 and Trendstatus >= 1;
def C6 = Condition3 and Trendstatus <= -1;
def C7 = Condition3 and Trendstatus < 1 and Trendstatus > -1;

def C8 = Condition4 and MomB >= 1;
def C9 = Condition4 and MomS <= -1;
def C10 = Condition4 and MomB < 1 and MomS > -1;

def C11 = Condition5 and PowerB >= 1;
def C12 = Condition5 and PowerS <= -1;
def C13 = Condition5 and PowerB < 1 and PowerS > -1;

def C14 = Condition6 and Value6B >= 2;
def C15 = Condition6 and Value6S <= -2;
def C16 = Condition6 and Value6B < 2 and Value6S > -2;

def C17 = Condition7 and Value7B >= 2;
def C18 = Condition7 and Value7S <= -2;
def C19 = Condition7 and Value7B < 2 and Value7S > -2;

def C20 = Condition8 and Value8B >= 2;
def C21 = Condition8 and Value8S <= -2;
def C22 = Condition8 and Value8B < 2 and Value8S > -2;


AssignPriceColor(
                if C1 or C5 or C8 or C11 or C14 or C17 or C20 then globalColor("UpColor") 
                else if C2 or C6 or C9 or C12 or C15 or C18 or C21 then globalColor("DnColor")
                else if C3 or C4 or C7 or C10 or C13 or C16 or C19 or C22 then globalColor("NeutralColor")
                else Color.CURRENT);
 
H

hockeycoachdoug

Member
2019 Donor
VIP
Is there anyone here who can help me with creating a custom colored watch list column?
 
H

hockeycoachdoug

Member
2019 Donor
VIP
@diazlaz - you have been so helpful coding my original post- Thank you. When you get a free minute, if you could have a look at my related post it would be greatly appreciated. Thanks in advance. Here is my related post regarding custom colored columns in a watch list.
 
Last edited by a moderator:
T

tomsk

Well-known member
VIP
@hockeycoachdoug The mechanism in which a watchlist column is colored is to use the AssignBackgroundColor() construct. Depending on your condition that you're looking for, you can specify one of the standard colors, or use the RGB color scheme that @markos posted above. Here is a very snippet based on TWO conditions to be defined

Code:
AssignBackgroundColor( if CONDITION1 then Color.RED else if CONDITION2 then Color.GREEN else Color.BLACK);
 
H

hockeycoachdoug

Member
2019 Donor
VIP
I will give this a try. Thank you both for your help.
 
H

hockeycoachdoug

Member
2019 Donor
VIP
I know the old saying "give a man a fish ...." vs "teach a man to fish ..." but I still seem to be too stupid to code this indicator into a color coded custom watch list column. The code for the indicator is a paint bar indicator that paints the bar red, green, or gray. I want to be able to have a custom colored watch column that shows what color the current bar is. I want to be able to use 2 different custom columns each using a different time frame i.e daily and weekly, daily and 60 min, etc. If someone would be kind enough to actually code this rather then give "hints" I would be very appreciative. Thanks in advance.
 
H

hockeycoachdoug

Member
2019 Donor
VIP
Many thanks to a very generous member here on the board who helped me with this. Here is the info shared with me showing how to accomplish this. Thought others might find the info useful and an aid to learning code. I have also included the actual code that was shared with me. Thanks again.

"Here you go - https://tos.mx/g4RYT8w import as many of these as you need, then add to your watchlist - change time arr in the watchlist properties of the indicator to the timeframe you want add, add multiple, one for each watchlist."

Code:
input Trend = yes;
input Cycle = yes;
input Mom = yes;

DefineGlobalColor("UpColor", Color.GREEN);
DefineGlobalColor("DnColor", Color.RED);
DefineGlobalColor("NeutralColor", Color.LiGHT_GRAY);

script MyStdDev {
    input data = close;
    input length = 12;
    input dataType = 2;

    def divisor = if dataType == 1 then length else length - 1;

    def _std = StDev(data, length);
    def _sqrOfStd = _std * _std;
    def _sumSqr = _sqrOfStd * length;
    def _variancePS = if divisor>0 then _sumSqr / divisor else 0;
    #def Value1 = VariancePS( data, Length, count, DataType ).VALUE ;

    #def _std = if (Value1>0) then sqrt(value1) else 0;
    #plot STD = _std ;

    plot STD = If (_variancePS > 0, Sqrt(_variancePS), 0);
}

def BuyEntry = 55;
def SellEntry = 55;
def BuyExit = 20;
def SellExit = 20;

def BuyLevel = Highest(High, BuyEntry)[1];
def SellLevel = Lowest(Low, SellEntry)[1];

#{Sets Switchside to 1 for Buy Trend or -1 for Sell Trend}
def SwitchSide = CompoundValue(1, if (High > BuyLevel and Switchside[1] < 1) then 1 else if Low < SellLevel and switchside[1] > -1 then -1 else switchside[1], 0);

def Trendstatus = Switchside;

def MomLength = 12;
def SmoothLength = 21;
def Candle = (hl2 - hl2[1]);
def CSmooth = Max((ExpAverage(ExpAverage(Absvalue(Candle),MomLength),SmoothLength)),.000001);
def CMom = 100*((ExpAverage(ExpAverage(Candle,MomLength),SmoothLength))/CSmooth);

def MomB = If CMom < 0 then 0 else If CMom >= 0 then 1 else MomB[1];
def MomS = If CMom >= 0 then 0 else If CMom < 0 then -1 else MomS[1];

def FastVar5 = MovAvgExponential(hl2,5);
def SlowVar5 = Average(hl2,8);
def DiffVar5 = FastVar5 - SlowVar5;
def FastVar8 = MovAvgExponential(hl2,8);
def SlowVar8 = Average(hl2,13);
def DiffVar8 = FastVar8 - SlowVar8;
def FastVar13 = MovAvgExponential(hl2,13);
def SlowVar13 = Average(hl2,21);
def DiffVar13 = FastVar13 - SlowVar13;
def FastVar21 = MovAvgExponential(hl2,21);
def SlowVar21 = Average(hl2,35);
def DiffVar21 = FastVar21 - SlowVar21;
def FastVar35 = MovAvgExponential(hl2,35);
def SlowVar35 = Average(hl2,55);
def DiffVar35 = FastVar35 - SlowVar35;

def TotCycle = DiffVar5 + DiffVar8 + DiffVar13 + DiffVar21 + DiffVar35;

def PowerB = If TotCycle < 0 then 0 else If TotCycle >= 0 then 1 else PowerB[1];

def PowerS = If TotCycle >= 0 then 0 else If TotCycle < 0 then -1 else PowerS[1];


def Condition1 = Trend and Cycle and Mom;
def Condition2 = Trend==no and Cycle==no and Mom==no;
def Condition3 = Trend and Cycle == no and Mom==no;
def Condition4 = Trend == no and Cycle==no and Mom;
def Condition5 = Trend == no and Cycle and Mom==no;
def Condition6 = Trend and Cycle and Mom==no;
def Condition7 = Trend and Cycle==no and Mom;
def Condition8 = Trend==no and Cycle and Mom;

def Value1B = Trendstatus + MomB + PowerB;
def Value1S = Trendstatus + MomS + PowerS;

def Value6B = Trendstatus + PowerB;
def Value6S = Trendstatus + PowerS;

def Value7B = Trendstatus + MomB;
def Value7S = Trendstatus + MomS;

def Value8B = PowerB + MomB;
def Value8S = PowerS + MomS;

def Value4B = PowerB + MomB;
def Value4S = PowerS + MomS;

def C1 = Condition1 and Value1B >= 3;
def C2 = Condition1 and Value1S <= -3;
def C3 = Condition1 and Value1B < 3 and Value1S > -3;

def C4 = Condition2;
def C5 = Condition3 and Trendstatus >= 1;
def C6 = Condition3 and Trendstatus <= -1;
def C7 = Condition3 and Trendstatus < 1 and Trendstatus > -1;

def C8 = Condition4 and MomB >= 1;
def C9 = Condition4 and MomS <= -1;
def C10 = Condition4 and MomB < 1 and MomS > -1;

def C11 = Condition5 and PowerB >= 1;
def C12 = Condition5 and PowerS <= -1;
def C13 = Condition5 and PowerB < 1 and PowerS > -1;

def C14 = Condition6 and Value6B >= 2;
def C15 = Condition6 and Value6S <= -2;
def C16 = Condition6 and Value6B < 2 and Value6S > -2;

def C17 = Condition7 and Value7B >= 2;
def C18 = Condition7 and Value7S <= -2;
def C19 = Condition7 and Value7B < 2 and Value7S > -2;

def C20 = Condition8 and Value8B >= 2;
def C21 = Condition8 and Value8S <= -2;
def C22 = Condition8 and Value8B < 2 and Value8S > -2;

AddLabel (1, " ", COLOR.GRAY);

#AddLabel(1,
#if C1 or C5 or C8 or C11 or C14 or C17 or C20 then "UpTrend"
#else if C2 or C6 or C9 or C12 or C15 or C18 or C21 then "DownTrend"
#else if C3 or C4 or C7 or C10 or C13 or C16 or C19 or C22 then #"Neutral" else "Other");

AssignBackgroundColor(
if C1 or C5 or C8 or C11 or C14 or C17 or C20 then COLOR.GREEN
else if C2 or C6 or C9 or C12 or C15 or C18 or C21 then COLOR.RED
else if C3 or C4 or C7 or C10 or C13 or C16 or C19 or C22 then COLOR.DARK_GRAY else COLOR.GRAY);
 
Last edited by a moderator:
D

diazlaz

Well-known member
2019 Donor
VIP
hi @hockeycoachdoug, I noticed you had the MyStdDev function, and didn't see it used in the watchlist or color selection. I also notice a few levels of buy and sell also not used. what are these for ?

let me know if you want to expand to include these in the logic selection.
 
H

hockeycoachdoug

Member
2019 Donor
VIP
Unknown. This is the actual code for Top Trade Tools Smart Bars that they sell. I didn't write the original indicator.
 

Similar threads

Top