this code is helpful if you prefer different colors for your 'Up' and 'Down' trend lines.
At first I was going to send a new feature request, but decided to implement it in PowerLanguage.
I need some help, so the code could apply the color without having to wait for a new tick (when charting offline).
Thanks,
Code: Select all
// Automatic Trend Line Coloring
//
// File name: TL_AutoColor
//
// This indicator designed to work with Multicharts and be placed
// on all your charts. The indicator detects when a new trend line
// is created or existing trend line is selected. It automatically
// applies one of three pre-defined colors to selected trend line
// depending on 'positive', 'negative', or 'neutral' slope.
// The corresponding color inputs are: 'Up', 'Down',and 'Neutral'.
//
inputs: Up(blue), Down(red), Neutral(cyan);
vars: Active_TL_ID (-1), // The ID of active TL
NewTrendlineColor(neutral);
condition1 = TL_GetActive <> (-1); // trendline is active
condition2 = TL_GetActive <> (-2); // trendline has valid ID
if condition1 AND NOT condition2 then // TL is active, and has Invalid ID
begin
// trendline has invalid ID.
// whatever happens here
end;
if condition1 AND condition2 then begin // TL is active and has valid ID
Active_TL_ID = TL_GetActive;
// Detect the slope of trendline --------------------------------------------
condition4 = TL_GetBeginTime_s(TL_GetActive) = TL_GetEndTime_s(TL_GetActive);
condition5 = TL_GetBeginDate(TL_GetActive) = TL_GetEndDate(TL_GetActive);
condition6 = TL_GetEndVal(TL_GetActive) = TL_GetBeginVal(TL_GetActive);
condition7 = (condition4 AND condition5 ) OR condition6; // slope 'neutral'
condition8 = TL_GetEndVal(TL_GetActive) < TL_GetBeginVal(TL_GetActive); // slope 'negative'
condition9 = TL_GetEndVal(TL_GetActive) > TL_GetBeginVal(TL_GetActive); // slope 'positive'
if condition9 then begin // check for 'positive' slope
NewTrendlineColor = Up;
end;
if condition8 then begin // check for 'negative' slope
NewTrendlineColor = Down;
end;
if condition7 then begin // check for 'neutral' slope
NewTrendlineColor = Neutral;
end;
// slope detected ----------------------------------------------------------
end;
TL_SetColor(Active_TL_ID, NewTrendlineColor); // Set trend line color