{-------------------------------------------------------------------------------------------------}
// Fernando Santos
// MC forum thread : http://www.multicharts.com/discussion/viewtopic.php?f=1&t=11804
// 1st version : 01-23-2013
// 2nd version : 01-24-2013
// SP (forum member), wrote lines 204 till 208 for a better box alignment
// 3rd version : 01-27-2013
// SP (forum member), wrote the candle drawing code
// embed the text_FloatLocation function for better text and trendline (candle) management
// there's a time input for set the exchange close time so we can have an open/close status
// 4th version : 01-30-2013
// custom sound alerts were added
{-------------------------------------------------------------------------------------------------}
inputs:
DataBoxLocation (90), // set as percentage
VariBoxLocation (84), // set as percentage
BoxColor (rgb(30,30,30)),
SetDataBoxEndSpace (2), // align box
SetVariBoxEndSpace (2), // align box
MyDecimals (2),
DataLabelColor (white),
VariLabelUpColor (green),
VariLabelDnColor (red),
ShowBoxBorder (false),
CloseLabelColor (rgb(81,81,81)),
ShowStatus (true), // show open or close label
ShowCandle (true),
LabelSize (9),
LabelFont ("Lucida Sans Typewriter"),
UseALerts (true),
SessionCloseTime (2115), // time at which the regular trading hour session close
AlertTimeTrigger (5), // minutes to trigger alert prior market close
SymbolAlert ("ES"), // symbol for alerts - ES, NQ, YM, TY, CL, EU
AlertsLocation ("C:\Sounds"); // folder where alerts sounds are
variables:
alertTrigger (0),
uniqueName (false),
isAlertOff (-1),
databoxTXT (-1),
variBoxTXT (-1),
statusTXT (-1),
textShift (0),
isStartDay (false),
isDayOpen (false),
dailyHi (-999999),
dailyLo (+999999),
dailyOp (0),
dailyCl (0),
prevDailyCl (0),
changePct (0),
changePrice (0),
closeTime (0),
intrabarpersist lastPrice (0),
intrabarpersist DataBox (0.95),
intrabarpersist VariBox (0.95),
candleWick (0),
candleBody (0),
HighestDispValue (0),
LowestDispValue (0),
CloseDispValue (0),
dayRange (0),
hi (0),
lo (0),
bottom (0),
top (0),
ito (0),
itc (0);
// Vertical percentage position function
if LastBarOnChart_s then begin
HighestDispValue = GetAppInfo(aiHighestDispValue);
LowestDispValue = GetAppInfo(aiLowestDispValue);
CloseDispValue = (Close - LowestDispValue)/(HighestDispValue - LowestDispValue);
if DataBoxLocation = -1 or VariBoxLocation = -1 then begin
if CloseDispValue > 0.6 then begin
DataBox = 0.05;
VariBox = 0.05;
end
else begin
if CloseDispValue < 0.4 then begin
DataBox = 0.95;
VariBox = 0.95;
end;
end;
end
else begin
DataBox = 0.01 * DataBoxLocation;
VariBox = 0.01 * VariBoxLocation;
end;
end;
// Reminder to enable alerts
If UseALerts = true then begin
If AlertEnabled = False And LastBarOnChart_S then
isALertOff = Text_New_S(Date, Time_S, Low, "Enable alerts at Format Study > Alerts > Enable Alerts");
text_setfontname(isAlertOff, "arial black");
text_setsize(isAlertOff, 16);
text_setcolor(isAlertOff, white);
text_setstyle(isAlertOff, 1, 2);
end;
if currentbar = 1 then begin
closeTime = TimeToMinutes(sessionCloseTime) * 60;
closeTime = SecondsToTime_s(closeTime);
alertTrigger = secondstotime_s((timetominutes(sessionclosetime) * 60) - (alerttimetrigger * 60));
dataBoxTXT = Text_new_s(date, time_s, high,"");
text_setfontname(dataBoxTXT, LabelFont);
text_setsize(dataBoxTXT, LabelSize);
text_setstyle(dataBoxTXT, 0, 2);
text_setborder(dataBoxTXT, ShowBoxBorder);
text_setbgcolor(dataBoxTXT, boxColor);
variBoxTXT = Text_new_s(date, time_s, high,"");
text_setfontname(variBoxTXT, LabelFont);
text_setsize(variBoxTXT, LabelSize);
text_setstyle(variBoxTXT, 0, 2);
text_setborder(variBoxTXT, ShowBoxBorder);
text_setbgcolor(variBoxTXT, boxColor);
if ShowStatus = true then begin
statusTXT = Text_new_s(date, time_s, high,"");
text_setfontname(statusTXT, LabelFont);
text_setsize(statusTXT, LabelSize);
text_setstyle(statusTXT, 1, 2);
end;
end;
tl_delete (candleWick);
tl_delete (candleBody);
if date <> date[1] then begin
isStartDay = true;
dailyHi = -999999;
dailyLo = +999999;
isDayOpen = false;
dailyCl = close[1];
uniqueName = true;
end;
if isStartDay then begin
// Set day's high, low and range
if High > dailyHi then
dailyHi = High;
if Low < dailyLo then
dailyLo = Low;
hi = dailyHi;
lo = dailyLo;
dayRange = hi - lo;
lastPrice = close;
// Set open
if isDayOpen = false then begin
isDayOpen = true;
dailyOp = Open;
end;
// Candle wick
top = LowestDispValue + (DataBox * (HighestDispValue - LowestDispValue));
bottom = LowestDispValue + (VariBox * (HighestDispValue - LowestDispValue));
// Candle body
if dayRange <> 0 then begin
itc = ((lastPrice - dailyLo) / dayRange) * (top-bottom) + bottom;
ito = ((dailyOp - dailyLo) / dayRange) * (top-bottom) + bottom;
end;
// Candle lines
if ShowCandle = true then begin
candleWick = tl_new_s(date, time_s, bottom, date, time_s, top);
tl_setsize (candleWick, 2);
tl_setcolor(candleWick,lightgray);
candleBody = tl_new_s(date, time_s, ito, date, time_s, itc);
tl_setsize (candleBody, 4);
if lastPrice > dailyOp then
tl_setcolor(candleBody, VariLabelUpColor)
else
tl_setcolor(candleBody, VariLabelDnColor);
end;
// Daily variation
if dailyCl <> 0 then
changePct = absvalue(((lastPrice / dailyCl) - 1) * 100);
changePrice = absvalue(lastPrice - dailyCl);
// Alerts
if UseALerts = true then begin
if time_s = alertTrigger and barstatus = 2 and LastBarOnChart_s then begin
if SymbolAlert = "ES" then begin
Alert("S&P futures will close in " + numtostr(AlertTimeTrigger, 0) + " minutes");
PlaySound(AlertsLocation + "\ESclosein5min.wav");
end
else
if SymbolAlert = "NQ" then begin
Alert("Nasdaq futures will close in " + numtostr(AlertTimeTrigger, 0) + " minutes");
PlaySound(AlertsLocation + "\NQclosein5min.wav");
end
else
if SymbolAlert = "YM" then begin
Alert("Dow Jones futures will close in " + numtostr(AlertTimeTrigger, 0) + " minutes");
PlaySound(AlertsLocation + "\YMclosein5min.wav");
end
else
if SymbolAlert = "TY" then begin
Alert("10 year note will close in " + numtostr(AlertTimeTrigger, 0) + " minutes");
PlaySound(AlertsLocation + "\TYclosein5min.wav");
end
else
if SymbolAlert = "EU" then begin
Alert("Euro futures will close in " + numtostr(AlertTimeTrigger, 0) + " minutes");
PlaySound(AlertsLocation + "\EUclosein5min.wav");
end
else
if SymbolAlert = "CL" then begin
Alert(" Crude Oil futures will close in " + numtostr(AlertTimeTrigger, 0) + " minutes");
PlaySound(AlertsLocation + "\CLclosein5min.wav");
end;
end
else
if time_s = closeTime and barstatus = 2 and LastBarOnChart_s then begin
if SymbolAlert = "ES" then begin
Alert("S&P futures just closed for the day");
PlaySound(AlertsLocation + "\ESisclosed.wav");
end
else
if SymbolAlert = "NQ" then begin
Alert("Nasdaq futures just closed for the day");
PlaySound(AlertsLocation + "\NQisclosed.wav");
end
else
if SymbolAlert = "YM" then begin
Alert("Dow Jones futures just closed for the day");
PlaySound(AlertsLocation + "\YMisclosed.wav");
end
else
if SymbolAlert = "TY" then begin
Alert("10 year note just closed for the day");
PlaySound(AlertsLocation + "\TYisclosed.wav");
end
else
if SymbolAlert = "EU" then begin
Alert("Euro futures just closed for the day");
PlaySound(AlertsLocation + "\EUisclosed.wav");
end
else
if SymbolAlert = "CL" then begin
Alert("Crude Oil just closed for the day");
PlaySound(AlertsLocation + "\CLisclosed.wav");
end;
end;
end;
// Color settings
if time_s < closeTime then begin
text_setstring(statusTXT , "O \nP \nE \nN");
text_setcolor(dataBoxTXT , DataLabelColor);
text_setcolor(statusTXT, rgb(81,81,81));
if lastPrice > dailyCl then
text_setcolor(variBoxTXT , VariLabelUpColor)
else
text_setcolor(variBoxTXT , VariLabelDnColor);
if lastPrice > dailyOp then
tl_setcolor(candleBody, VariLabelUpColor)
else
tl_setcolor(candleBody, VariLabelDnColor);
end
else
if time_s = closeTime and barstatus = 2 and LastBarOnChart_s then begin
text_setstring(statusTXT , "C \nL \nO \nS \nE");
text_setcolor(variBoxTXT , CloseLabelColor);
text_setcolor(dataBoxTXT , CloseLabelColor);
text_setcolor(statusTXT, white);
//if lastPrice >= dailyOp or lastPrice <= dailyOp then begin
//tl_setcolor(candleBody, CloseLabelColor);
//tl_setcolor(candleWick, CloseLabelColor);
//end;
end;
// DataBox
text_setstring(dataBoxTXT, " < " + text(getsymbolname) + " > " + NewLine +
spaces(1) + " OP |" + " " + NumToStr(dailyOp, MyDecimals) + spaces(SetDataBoxEndSpace) + NewLine +
spaces(1) + " HI |" + " " + NumToStr(dailyHi, MyDecimals) + spaces(SetDataBoxEndSpace) + NewLine +
spaces(1) + " LO |" + " " + NumToStr(dailyLo, MyDecimals) + spaces(SetDataBoxEndSpace) + NewLine +
spaces(1) + " CL |" + " " + NumToStr(lastPrice, MyDecimals) + spaces(SetDataBoxEndSpace)) ;
// VariBox
text_setstring(variBoxTXT , spaces(1) + " % | " + NumToStr(changePct, 2) +
Spaces(StrLen(NumToStr(changePct, 2)) - StrLen(NumToStr(changePrice, 1))) +
spaces(SetVariBoxEndSpace) + NewLine +
spaces(1) + " CH | " + NumToStr(changePrice, MyDecimals) +
Spaces(StrLen (NumToStr(lastPrice, MyDecimals)) - StrLen(NumToStr(changePrice, MyDecimals))) + spaces(SetVariBoxEndSpace)) ;
// Data and Vari box location
text_setlocation_s(dataBoxTXT, date, time_s, LowestDispValue + (DataBox * (HighestDispValue - LowestDispValue)));
text_setlocation_s(variBoxTXT, date, time_s, LowestDispValue + (VariBox * (HighestDispValue - LowestDispValue)));
// Status location
if ShowStatus = true then
text_setlocation_s(statusTXT, date, time_s, LowestDispValue + (DataBox * (HighestDispValue - LowestDispValue)));
end;
|