Need help in trading view Pine editor.
How can i Automatically draw an horizontal line based on bar high and low for a specified time frame and session. I need to have a horizontal line drawn for the highest and lowest value of the bar on the 15 minutes time frame chart and exactly for the bar of 9:30 session of Indian time (IST)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © flashgekko
// https://www.tradingview.com/pine-script-docs/en/v4/essential/Sessions_and_time_functions.html#:~:text=working%20with%20time-,The%20%E2%80%9Ctime%E2%80%9D%20function%20and%20variable,%E2%80%9D%20and%20%E2%80%9CSession%20bars%E2%80%9D
//#version=4
study("Project 002", overlay=true)
var h = high
var l = low
if (high > high[1]) and high >h
h := high
if (low < low[1]) and low <l
l := low
t = time("15","0900-1800")
if na(t[1]) and not na(t) or t[1] <t
l:= low
h:= high
plot(h, color = color.green)
plot(l, color = color.red)
I am making a Pong game in Delphi.
Paddle.Left := X - Paddle.Width div 2;
Paddle.Top := ClientHeight - Paddle.Height - 2;
I expect the output of 5/2 to be 2.5, but the actual output is 2.
The div operator performs integer division (5 div 2 = 2, throwing away the decimal .5), whereas the / operator performs floating point division (5 / 2 = 2.5).
In VCL, a control's Left, Top, Width, and Height values are expressed using whole integers, not floating point numbers.
In FMX, a control's Position and Size values are expressed using floating point numbers.
div is the integer division operator. It is a binary operator that takes two integers, and returns an integer, the truncated value of the division. For instance,
0 div 3 = 0
1 div 3 = 0
2 div 3 = 0
3 div 3 = 1
4 div 3 = 1
5 div 3 = 1
6 div 3 = 2
...
If you want to perform a floating-point division, you need to use the / operator:
0 / 3 = 0
1 / 3 = 0.33333333333333
2 / 3 = 0.66666666666666
3 / 3 = 1
4 / 3 = 1.33333333333333
5 / 3 = 1.66666666666666
6 / 3 = 2
...
Of course, the result cannot be stored in an integer variable. If you eventually need an integer value to specify a pixel on the screen, you need to round the floating-point value to an integer (using the Round function).
I have a few values
Quantity := 5;
Quantity2 := 8;
percent :=50;
so i want
Percent of Quantity + Quantity 2
which would be like : 50% of 13 = 6.5
I done it like this
HowMuchDamage := trunc(percent*(Quantity + Quantity2)/100);
How can i make it round up?
How can i make it round down?
Floor(X) returns the highest integer less than or equal to X.
Ceil(X) returns the lowest integer greater than or equal to X.
I'm working on a programming problem.
Note: This is not a student project. I am working on this for a new Quest for the website Try My Quest Dot Com, for which i am the admin.
Problem:
Jenny just started work as a programmer for Justine's Java Workshop. She is paid $10
an hour, with a few exceptions. She earns an extra $1.50 an hour for any part of a day where she works more than 8 hours, and an extra $2.50 an hour for hours beyond 40 in any one week. Also, she earns a 125% bonus for working on Saturday, and a 50% bonus for working on Sunday. The bonuses for Saturday and Sunday are computed based on the hours worked those days; they are not used to calculate any bonus for working more than 40 hours in a week. You'll be given the number of hours Jenny worked each day in a week (Sunday, Monday, etc ), and you need to compute her salary for the week. The input will be positive integers, less than or equal to 24. The output must be formatted with a dollar sign and rounded up to the nearest penny. For example, $2" and $2.136666" are wrong answers; the correct versions are $2.00" and $2.14", respectively.
Anyway, i am trying to write this in Delphi (No form project). I pass the program a command line argument - timecard.dat
input
0, 8, 8, 8, 8, 8, 0
0, 10, 10, 10, 10, 10, 0
0, 0, 8, 8, 8, 8, 8
0, 0, 0, 10, 10, 10, 10
10, 10, 10, 9, 9, 9, 9
Output
Output #1: $400.00
Output #2: $540.00
Output #3: $500.00
Output #4: $540.75
Output #5: $905.88
My Out put however is:
Output #1: $400.00
Output #2: $540.00
Output #3: $500.00
Output #4: $537.00
Output #5: $902.50
The last two output values of mine are different from the actual results. Not sure why, and the more i stare at the code, the less i see it
Can anyone tell me what i have done wrong?
program ACSL_Time_Cards;
{assumes Sunday = 1, Monday 3, etc}
uses
SysUtils,
Dialogs;
const
HourlyWage = 10.00;
OverEightWage = 1.50;
OverFortyWage = 2.50;
var
F: TextFile;
I, ArrayIndex: Integer;
WeeklyHours: Array[0..6] of Integer; //weekly hours
HourStr, LineStr: String;
TotalHours, TotalOverFortyHours, TotalOverEightHours, TotalSatHours, TotalSunHours: Integer;
TotalWages: Real;
begin
//initialize variables
TotalHours:= 0;
TotalOverEightHours:= 0;
TotalOverFortyHours:= 0;
TotalSatHours:= 0;
TotalSunHours:= 0;
TotalWages:= 0.00;
ArrayIndex:= 0;
//open file "timecard.dat" for input
if FileExists(ParamStr(1)) then
begin
AssignFile(F, ParamStr(1));
Reset(F);
//step through file and extract each line and store in hoursStr
while not EOF(F) do
begin
Readln(F, LineStr);
//step through hours string and fill Array with weekly hours
for I:= 1 to length(LineStr) do
begin
//if character is not a ',' then add it to hourStr
if LineStr[I] <> ',' then
HourStr:= HourStr + LineStr[I]
else
begin
//add HourStr to Array
WeeklyHours[ArrayIndex]:= StrToInt(HourStr);
//reset the variable
HourStr:= '';
//increment Variable
Inc(ArrayIndex);
end; //else
end; //for I:= 1 to length(HoursStr) do
//clean up by adding the last remaining one
WeeklyHours[ArrayIndex]:= StrToInt(HourStr);
//step through array and figure out overtime Daily and Weekly
for I:= Low(WeeklyHours) to High(WeeklyHours) do
begin
TotalHours:= TotalHours + WeeklyHours[I];
if WeeklyHours[I] > 8 then
TotalOverEightHours:= TotalOverEightHours + WeeklyHours[I]-8;
//get sunday hours
if I + 1 = 1 then
TotalSunHours:= TotalSunHours + WeeklyHours[I];
//get saturday hours
if I + 1 = 7 then
TotalSatHours:= TotalSatHours + WeeklyHours[I];
end;
//get total over 40 hours
if TotalHours > 40 then
TotalOverFortyHours:= TotalHours-40;
//compute Regular Hours
TotalWages:= TotalWages + TotalHours * 10.00;
//compute overtime hours
TotalWages:= TotalWages + TotalOverEightHours * 1.50;
TotalWages:= TotalWages + TotalOverFortyHours * 2.50;
//compute bonuses
TotalWages:= TotalWages + (TotalSatHours * 10.00) * 1.25;
TotalWages:= TotalWages + (TotalSunHours * 10.00) * 0.50;
ShowMessage('TotalWages: ' + FormatFloat('$0.00', TotalWages));
//reset variables
TotalWages:= 0.00;
TotalHours:= 0;
TotalOverEightHours:= 0;
TotalOverFortyHours:= 0;
TotalSatHours:= 0;
TotalSunHours:= 0;
HourStr:= '';
ArrayIndex:= 0;
end; //while not EOF(F) do
CloseFile(F);
end
else
ShowMessage('File does not exist!');
end.
I'm sure there are many ways that this could have been written better. I really am just interested in why my values different from the expected values. Thanks!
For a simple problem like this, you might want to write it out by hand and then see if your code follows the same steps you did.
For Output 4, the 125% bonus for Saturday is not including the $1.50 per hour extra after 8:
she should earn
Wed: $103 | $100 for 10 hours plus $3 for 2 hours over 8
Thu: $103 | $100 for 10 hours plus $3 for 2 hours over 8
Fri: $103 | $100 for 10 hours plus $3 for 2 hours over 8
Sat: $231.75 | ($100 for 10 hours, $3 for 2 hours over 8), $128.75 for 125% bonus
for a total of 540.75
The code would benefit from the I/O and the calculation being separated. You problems are with the calculation. I'd write it something like this:
uses
Math;
type
TDay = (
daySunday,
dayMonday,
dayTuesday,
dayWednesday,
dayThursday,
dayFriday,
daySaturday
);
TDayArray = array [TDay] of Integer;
function Wage(const Hours: TDayArray): Double;
const
BasicRate = 10.0;
DailyOvertimeRate = 1.5;
WeeklyOvertimeRate = 2.5;
DailyOvertimeThreshold = 8;
WeeklyOvertimeThreshold = 40;
DailyBonus: array [TDay] of Double = (1.5, 1.0, 1.0, 1.0, 1.0, 1.0, 2.25);
var
Day: TDay;
DailyOvertimeHours, WeeklyOvertimeHours, TotalHours: Double;
DailyPay: array [TDay] of Double;
begin
TotalHours := 0.0;
for Day := low(Day) to high(Day) do begin
TotalHours := TotalHours + Hours[Day];
DailyOvertimeHours := Max(Hours[Day]-DailyOvertimeThreshold, 0.0);
DailyPay[Day] := Hours[Day]*BasicRate;
DailyPay[Day] := DailyPay[Day] + DailyOvertimeHours*DailyOvertimeRate;
DailyPay[Day] := DailyPay[Day]*DailyBonus[Day];
end;
WeeklyOvertimeHours := Max(TotalHours-WeeklyOvertimeThreshold, 0.0);
Result := Sum(DailyPay) + WeeklyOvertimeHours*WeeklyOvertimeRate;
end;
This is still a little unpolished and I'm not very happy with the variable names for pay rates, overtime etc.
Once have such a utility function available, then putting it together with the rest of your program becomes a lot easier.
The biggest weakness in your current program is that everything is housed in one giant routine. Break it down into small pieces and you'll be able to verify those small pieces more readily than hunting for problems in a single large routine.
Find this by yourself by learning How to debug a Delphi program.
Pay atention to this parts:
Watches - you add a watch to track the values of program variables or expressions as you step over or trace into code.
Breakpoints - when pressing the F5 button or clicking on the left bar in your editor you can add a red line to your source. This line of source will have a breakpoint. When running the program, the execution will stop when it passes the source line. Now you can trace into your source by using some function keys.
I have a series of 3,600 values, one every second for an hour. I want to chart them as a single series, using TChart in Delphi 7.
The values should be plotted on the Y-axis. What should I pass to AddXY() as the X-axis value? The count of points?
I want to label the X-axis as MM:SS, how do I do that? What do I need beyond this? ...
Chart1.Series[0].XValues.DateTime := True;
Chart1.BottomAxis.DateTimeFormat := 'nn:ss';
I have been stuck for a while with this one. Can anyone post some sample code? Thanks
You can use Add function instead of AddXY.
Add( 100, FormatDateTime('nn:ss',Now), clRed );
Add( 80, FormatDateTime('nn:ss',Now), clRed );
If I am not wrong, this is what you want
Series1.AddXY(<Pass the data value>, <Pass Your value>, '', clRed);
Series1.AddXY(now, 1, '', clRed);
Series1.AddXY(now + ( 1 /(24*60*60)), 2, '', clRed); //After 1 seconds
Series1.AddXY(now + ( 2 /(24*60*60)), 3, '', clRed); //After 2 seconds