Pre-loop a chart [SOLVED]
- signalworks
- Posts: 65
- Joined: 06 Oct 2013
- Location: Germany.Solingen
- Has thanked: 23 times
- Been thanked: 2 times
- Contact:
Pre-loop a chart
Hello,
is it possible to pre-loop a complete chart and start a final calculation after that?
Idea: I need the lastDayOfWeek, lastDayOfMonth and lastDayOfYear for a calculation. I can calc that with i.e. dayOfMonth(date) < dayofMonth(date[1]). Here I need the value a day earlier (at the lastDayOfWeek...).
Thanks.
regards,
sw
is it possible to pre-loop a complete chart and start a final calculation after that?
Idea: I need the lastDayOfWeek, lastDayOfMonth and lastDayOfYear for a calculation. I can calc that with i.e. dayOfMonth(date) < dayofMonth(date[1]). Here I need the value a day earlier (at the lastDayOfWeek...).
Thanks.
regards,
sw
- Angelina MultiСharts
- Posts: 260
- Joined: 28 Dec 2016
- Has thanked: 28 times
- Been thanked: 66 times
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: Pre-loop a chart
Hello,
is it possible to pre-loop a complete chart and start a final calculation after that?
Idea: I need the lastDayOfWeek, lastDayOfMonth and lastDayOfYear for a calculation. I can calc that with i.e. dayOfMonth(date) < dayofMonth(date[1]). Here I need the value a day earlier (at the lastDayOfWeek...).
Thanks.
regards,
sw
You can get lastDayOfMonth and lastDayOfYear without a pre-loop.
Re: Pre-loop a chart
Hello signalworks,is it possible to pre-loop a complete chart and start a final calculation after that?
you could try with a condition
Code: Select all
If LastBarOnChart the begin
...
end;
Massimo
-
- Posts: 401
- Joined: 19 Jan 2011
- Location: Netherlands
- Has thanked: 85 times
- Been thanked: 125 times
Re: Pre-loop a chart
What I understand from your post, you want to have the values of lastDayOfWeek, lastDayOfMonth and lastDayOfYear
on bar one of the chart to use in the calculation of other values. The problem is that these values are not known yet at bar 1.
Maybe you can have a separated indicator get those values and send these from the indicator to the signal with GV or ADE.
Just be sure to run the indicator first.
on bar one of the chart to use in the calculation of other values. The problem is that these values are not known yet at bar 1.
Maybe you can have a separated indicator get those values and send these from the indicator to the signal with GV or ADE.
Just be sure to run the indicator first.
-
- Posts: 60
- Joined: 21 Dec 2007
- Has thanked: 3 times
- Been thanked: 9 times
Re: Pre-loop a chart
Code: Select all
Var: Datei("D:\Temp\test.csv");
if dayOfMonth(date) < dayofMonth(date[1]) then value1 = 1 else value1 = 0;
if dayOfMonth(date) < dayofMonth(date[1]) then value2 = barnumber else value2 = 0;
if value1 = 1 then arw_new_bn(value2-1,low,false);
if value1 = 1 then plot10(low*0.99);
If value1 = 1 then
begin
print(File(Datei),
ELDateToString(date[1]),";",
O[1] :0:0,";",
H[1] :0:2,";",
L[1] :0:2,";",
C[1] :0:2);
end;
- Attachments
-
- EndofMonth.png
- (55.77 KiB) Downloaded 1436 times
Re: Pre-loop a chart
Hello signalworks,
For my understanding you recalc on close of every last bar
and can not look into the future.
what do you mean for a day earlier ?I need the value a day earlier
For my understanding you recalc on close of every last bar
Code: Select all
i.e. dayOfMonth(today date) < dayofMonth(yesterday date)
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: Pre-loop a chart
Someone asked the same question not too long ago.
I have already given the solution.
It is in the forum somewhere.
No pre-loop required.
I have already given the solution.
It is in the forum somewhere.
No pre-loop required.
- signalworks
- Posts: 65
- Joined: 06 Oct 2013
- Location: Germany.Solingen
- Has thanked: 23 times
- Been thanked: 2 times
- Contact:
Re: Pre-loop a chart [SOLVED]
Hi again,
I need the info: today is the last trading day of a month. (not a day later on beginning of the new month).
My solution is running over a date-calculation (except holidays), that calculates the weekday of the last day of month and if necessary (weekend) recalculates the last session day as follows (includes a bit overhead to check any relevant values). Thanks to you for your ideas above. I would be glad about your comments/criticism.
Function 1 "SWF_DayOfWeek_v1.1"
Function 2 "SWF_LastDayOf_v1.1"
Indicator "SWI_LastDayOf_v1.1"
I need the info: today is the last trading day of a month. (not a day later on beginning of the new month).
My solution is running over a date-calculation (except holidays), that calculates the weekday of the last day of month and if necessary (weekend) recalculates the last session day as follows (includes a bit overhead to check any relevant values). Thanks to you for your ideas above. I would be glad about your comments/criticism.
Function 1 "SWF_DayOfWeek_v1.1"
Code: Select all
///////////////////////////////////////////////////////////
//MODUL: Function SWF_DayOfWeek
//DESCRIPTION: calculates DayOfWeek of last day of month (adapted from: https://de.wikipedia.org/wiki/Wochentagsberechnung#Eine_Methode_zum_Kopfrechnen)
//Author: Signalworks
//Version: 1.1
//Date: 26.04.2017
//////////////////////////////////////////////////////////
inputs: odd(numericRef), omd(numericRef), omd_last(numericRef), ome(numericRef), oyd(numericRef),
ocd(numericRef), olc(numericRef), owd(numericRef);
vars: da(0), mo(0), ye(0), yds(0);
//LastMonthDigit|YearDigit
if currentbar = 1 or year(date) <> year(date[1])
then begin
omd_last = 0;
omd = 0;
//YearDigit
ye = 1900 + year(date);
yds = round(fracportion(ye / 100) * 100, 0);
oyd = mod(yds + floor(yds / 4), 7);
//CenturyDigit
ocd = (3 - mod(intPortion(ye / 100), 4)) * 2;
//LeapYear correcture
if (mod(ye, 4) = 0 and mod(ye, 100) <> 0) or mod(ye, 400) = 0
then
olc = -1
else
olc = 0;
//
end;
//
//DayDigit|MonthDigit
if (currentbar = 1 and month(date) = 1) or month(date) <> month(date[1])
then begin
ome = month(date);
switch(ome)
begin
case 1,3,5,7,8,10,12:
odd = mod(31, 7);
//January starts with md=0, dd is for next month calc
if ome = 1
then
omd = 0;
case 4,6,9,11:
odd = mod(30, 7);
case 2:
if olc = -1
then
odd = mod(29, 7)
else
odd = mod(28, 7);
end;
//
if ome > 1
then begin
omd = omd[1] + odd[1];
if omd >= 7
then
omd = mod(omd, 7);
end;
end;
//
//RESULT WEEKDAY OF LAST DAY OF MONTH
owd = mod(odd + omd + ocd + oyd + olc, 7);
SWF_DayOfWeek_v1.1 = 0;
Code: Select all
///////////////////////////////////////////////////////////
//MODUL: Function SWF_LastDayOf
//DESCRIPTION: calculates LastDayOf (week|month|year)
//Author: Signalworks
//Version: 1.1
//Date: 26.04.2017
//////////////////////////////////////////////////////////
Inputs: MODE_LDO(numericSimple), oflag_ldo(numericRef), odd(numericRef), omd(numericRef),
omd_last(numericRef), ome(numericRef), oyd(numericRef), ocd(numericRef), olc(numericRef),
owd(numericRef), oda(numericRef), omo(numericRef);
vars: dow(0);
oflag_ldo = 0;
oda = round(fracportion(date / 100) * 100,0);
omo = month(date);
value1 = SWF_DayOfWeek_v1.1(odd, omd, omd_last, ome, oyd, ocd, olc, owd);
switch(MODE_LDO)
begin
case 0:
//LastDayOfWeek
dow = dayOfWeek(date);
if dow = 5
then
oflag_ldo = 1;
case 1:
//LastDayOf->month|year
switch(omo)
begin
case 1,3,5,7,8,10,12:
if (owd > 0 and owd < 6 and oda = 31)
or (owd = 0 and oda = 29)
or (owd = 6 and oda = 30)
then
oflag_ldo = 1;
case 4,6,9,11:
if (owd > 0 and owd < 6 and oda = 30)
or (owd = 0 and oda = 28)
or (owd = 6 and oda = 29)
then
oflag_ldo = 1;
case 2:
if (owd > 0 and owd < 6 and oda = 28 + olc * (-1))
or (owd = 0 and oda = 26 + olc * (-1))
or (owd = 6 and oda = 27 + olc * (-1))
then
oflag_ldo = 1;
end;
end;
SWF_lastDayOf_v1.1 = 0;
Code: Select all
///////////////////////////////////////////////////////////
//MODUL: Indicator SWI_LastDayOf
//DESCRIPTION: calculates LastDayOf (week|month|year)
//Author: Signalworks
//Version: 1.1
//Date: 26.04.2017
//////////////////////////////////////////////////////////
Inputs: MODE_LDO(1), //0: LastTradingDayOfWeek (Friday), 1: LastTradingDayOfMonth|Year
DEBUG_OnOff(false),
___TXT_Date1(ELDate(03, 16, 2017)),
___TXT_Date2(ELDate(03, 16, 2017));
vars: owd(0), oflag_ldo(0), odd(0), omd(0), omd_last(0), ome(0), oyd(0),
ocd(0), olc(0), oda(0), omo(0), otest(0);
if currentbar = 1 then
begin
if DEBUG_OnOff = true
then
ClearDebug;
end;
value1 = SWF_LastDayOf_v1.1(MODE_LDO, oflag_ldo, odd, omd, omd_last, ome, oyd, ocd, olc, owd, oda, omo);
Plot1(oflag_ldo, "LDO_Month");
/////////////////////////////////////////////////////////////////////
//DEBUG CONTROL
/////////////////////////////////////////////////////////////////////
if DEBUG_OnOff and date >= ___TXT_Date1 and date <= ___TXT_Date2 then
begin
Print("[", round(FracPortion(date/100)*100,0):1:0, ".", month(date):1:0, ".", (1900+year(date)):4:0, "]",
"[", SecondsToTime_s ( TimeToSeconds ( time_S )):6:0, "]", " ",
"odd:", odd:1:2, " ",
"omd:", omd:1:2, " ",
"omd_last:", omd_last:1:2, " ",
"ome:", ome:1:2, " ",
"oyd:", oyd:1:2, " ",
"ocd:", ocd:1:2, " ",
"olc:", olc:1:2, " ",
"owd:", owd:1:2, " ",
"oda:", oda:1:2, " ",
"omo:", omo:1:2, " ",
"oflag_ldo:", oflag_ldo:1:2, " "
);
end;
- Attachments
-
- lastDayOfMonth.PNG
- (116.92 KiB) Downloaded 1393 times
Re: Pre-loop a chart
Hello signalworks,
I would say:
You probably could have kept it all simpler, this way:
Please check the code, I do not have enough historical data available.
Best regards
Massimo
please check your code, maybe the conditions in the switch-cases are not correct.Thanks to you for your ideas above. I would be glad about your comments/criticism.
Code: Select all
or (owd = 0 and oda = 29)
or (owd = 6 and oda = 30)
Code: Select all
or (owd = 5 and (oda = 29 or oda = 30))
Code: Select all
// By Massimo Rizzi (Italy)
Vars:
Is_LastDayOfMonth(0);
// When month changes resets Is_LastDayOfMonth
if currentbar=1 or Month(date)<>Month(date)[1] then Is_LastDayOfMonth=0;
switch(month(date))
begin
// months with 31 days
case 1,3,5,7,8,10,12:
if (dayofweek(date)>0 and dayofweek(date)<6 and dayofmonth(date)=31)
or(dayofweek(date)=5 and (dayofmonth(date)=29 or dayofmonth(date)=30))
then Is_LastDayOfMonth=1;
// months with 30 days
case 4,6,9,11:
if (dayofweek(date)>0 and dayofweek(date)<6 and dayofmonth(date)=30)
or(dayofweek(date)=5 and (dayofmonth(date)=28 or dayofmonth(date)=29))
then Is_LastDayOfMonth=1;
// february
case 2:
if mod(year(date),4)=0 then begin
if(dayofweek(date)>0 and dayofweek(date)<6 and dayofmonth(date)=29)
or(dayofweek(date)=5 and (dayofmonth(date)=27 or dayofmonth(date)=28))
then Is_LastDayOfMonth=1;
end
else begin
if(dayofweek(date)>0 and dayofweek(date)<6 and dayofmonth(date)=28)
or(dayofweek(date)=5 and (dayofmonth(date)=26 or dayofmonth(date)=27))
then Is_LastDayOfMonth=1;
end;
end;
plot1(Is_LastDayOfMonth);
Best regards
Massimo
- signalworks
- Posts: 65
- Joined: 06 Oct 2013
- Location: Germany.Solingen
- Has thanked: 23 times
- Been thanked: 2 times
- Contact:
Re: Pre-loop a chart
Hi Massimo,
thank you for your solution. That works too and with less code (but why simple, if it can do complicated )
Only the leap-year calc in your code:
nice regards
sw
thank you for your solution. That works too and with less code (but why simple, if it can do complicated )
The code related #wd is correct, because #wd is the calculated dayOfWeek of the last day of month. Is #wd a Sunday (0) so it is the 29th of month (1,3,5,8,10,12) the last trading-day (is #wd a saturday (6), so it is the 30th the last day for the above month's). #wd = 5 means, that the last day of month would be a friday, so it is the 31th the last day of above month's.please check your code, maybe the conditions in the switch-cases are not correct.
Only the leap-year calc in your code:
should be:// february
case 2:
if mod(year(date),4)=0 then begin
Code: Select all
(mod(year(date), 4) = 0 and mod(year(date), 100) <> 0) or mod(year(date), 400) = 0
sw
Re: Pre-loop a chart
Hello signalworks,
The correct version will only make a difference in 2100, but then maybe we will not be there.
Best regards
Max
yes, I like to keep it simple.Only the leap-year calc in your code:should be:Code: Select all
// february
case 2:
if mod(year(date),4)=0 then beginCode: Select all
(mod(year(date), 4) = 0 and mod(year(date), 100) <> 0) or mod(year(date), 400) = 0
The correct version will only make a difference in 2100, but then maybe we will not be there.
Best regards
Max
-
- Posts: 60
- Joined: 21 Dec 2007
- Has thanked: 3 times
- Been thanked: 9 times
Re: Pre-loop a chart
In 2010 the last trading day in SPY was on Friday 05/28, in 2013 Thursday 03/28 . In this cases a modification is required.
- Attachments
-
- Chart6dfer.png
- (56.29 KiB) Downloaded 1325 times
Re: Pre-loop a chart
Hello Helmut,
I suppose it is not a bug of the code but an anomaly of the market.
Let us know if you discover something.
Best regards.
Massimo
the question is why those days were the last trading day of the month ?In 2010 the last trading day in SPY was on Friday 05/28, in 2013 Thursday 03/28 . In this cases a modification is required.
I suppose it is not a bug of the code but an anomaly of the market.
Let us know if you discover something.
Best regards.
Massimo
-
- Posts: 60
- Joined: 21 Dec 2007
- Has thanked: 3 times
- Been thanked: 9 times
Re: Pre-loop a chart
Hello Massimo,
in every timeseries there are some exeptions.
With this code you can be sure to catch all last trading days for a timeseries and export to a csv.
Copy and paste the list of
lasttradingday[1] = 980130;
...
lasttradingday[231] = 1170331;
to a signal or import from csv into a signal so you can trade on last trading day every month
Cheers
Helmut
in every timeseries there are some exeptions.
With this code you can be sure to catch all last trading days for a timeseries and export to a csv.
Code: Select all
//Indicator Monatsende
Var: Datei(" "), counter(0);
Datei = "D:\Temp\" & "LTD" & getsymbolname & ".csv" ;
if dayOfMonth(date) < dayofMonth(date[1]) then value1 = 1 else value1 = 0;
if dayOfMonth(date) < dayofMonth(date[1]) then value2 = barnumber else value2 = 0;
if value1 > value1[1] then counter = counter + 1;
If value1 = 1 then
begin
arw_new_bn(value2-1,high,true);
print(File(Datei), "lasttradingday[", counter :0:0,"] = ",date[1] :0:0,";");
end;
lasttradingday[1] = 980130;
...
lasttradingday[231] = 1170331;
to a signal or import from csv into a signal so you can trade on last trading day every month
Code: Select all
{Signal: Monatsende
Positionseroeffnung am Monatsende plus x Tage
Style = 1: long, Style = 2: short,
Daily Zeitreihe benutzen}
Input: DayDiff(0), nBarExit(10), Style(1);
Var: j(0), NumCts(0), CmpDate(0);
Arrays: LastTradingDay[400](0);
lasttradingday[1] = 980130;
lasttradingday[2] = 980227;
lasttradingday[3] = 980331;
lasttradingday[4] = 980430;
lasttradingday[5] = 980529;
lasttradingday[6] = 980630;
lasttradingday[7] = 980731;
lasttradingday[8] = 980831;
lasttradingday[9] = 980930;
lasttradingday[10] = 981030;
lasttradingday[11] = 981130;
lasttradingday[12] = 981230;
lasttradingday[13] = 990129;
lasttradingday[14] = 990226;
lasttradingday[15] = 990331;
lasttradingday[16] = 990430;
lasttradingday[17] = 990531;
lasttradingday[18] = 990630;
lasttradingday[19] = 990730;
lasttradingday[20] = 990831;
lasttradingday[21] = 990930;
lasttradingday[22] = 991029;
lasttradingday[23] = 991130;
lasttradingday[24] = 991230;
lasttradingday[25] = 1000131;
lasttradingday[26] = 1000229;
lasttradingday[27] = 1000331;
lasttradingday[28] = 1000428;
lasttradingday[29] = 1000531;
lasttradingday[30] = 1000630;
lasttradingday[31] = 1000731;
lasttradingday[32] = 1000831;
lasttradingday[33] = 1000929;
lasttradingday[34] = 1001031;
lasttradingday[35] = 1001130;
lasttradingday[36] = 1001229;
lasttradingday[37] = 1010131;
lasttradingday[38] = 1010228;
lasttradingday[39] = 1010330;
lasttradingday[40] = 1010430;
lasttradingday[41] = 1010531;
lasttradingday[42] = 1010629;
lasttradingday[43] = 1010731;
lasttradingday[44] = 1010831;
lasttradingday[45] = 1010928;
lasttradingday[46] = 1011031;
lasttradingday[47] = 1011130;
lasttradingday[48] = 1011228;
lasttradingday[49] = 1020131;
lasttradingday[50] = 1020228;
lasttradingday[51] = 1020328;
lasttradingday[52] = 1020430;
lasttradingday[53] = 1020531;
lasttradingday[54] = 1020628;
lasttradingday[55] = 1020731;
lasttradingday[56] = 1020830;
lasttradingday[57] = 1020930;
lasttradingday[58] = 1021031;
lasttradingday[59] = 1021129;
lasttradingday[60] = 1021230;
lasttradingday[61] = 1030131;
lasttradingday[62] = 1030228;
lasttradingday[63] = 1030331;
lasttradingday[64] = 1030430;
lasttradingday[65] = 1030530;
lasttradingday[66] = 1030630;
lasttradingday[67] = 1030731;
lasttradingday[68] = 1030829;
lasttradingday[69] = 1030930;
lasttradingday[70] = 1031031;
lasttradingday[71] = 1031128;
lasttradingday[72] = 1031230;
lasttradingday[73] = 1040130;
lasttradingday[74] = 1040227;
lasttradingday[75] = 1040331;
lasttradingday[76] = 1040430;
lasttradingday[77] = 1040531;
lasttradingday[78] = 1040630;
lasttradingday[79] = 1040730;
lasttradingday[80] = 1040831;
lasttradingday[81] = 1040930;
lasttradingday[82] = 1041029;
lasttradingday[83] = 1041130;
lasttradingday[84] = 1041230;
lasttradingday[85] = 1050131;
lasttradingday[86] = 1050228;
lasttradingday[87] = 1050331;
lasttradingday[88] = 1050429;
lasttradingday[89] = 1050531;
lasttradingday[90] = 1050630;
lasttradingday[91] = 1050729;
lasttradingday[92] = 1050831;
lasttradingday[93] = 1050930;
lasttradingday[94] = 1051031;
lasttradingday[95] = 1051130;
lasttradingday[96] = 1051230;
lasttradingday[97] = 1060131;
lasttradingday[98] = 1060228;
lasttradingday[99] = 1060331;
lasttradingday[100] = 1060428;
lasttradingday[101] = 1060531;
lasttradingday[102] = 1060630;
lasttradingday[103] = 1060731;
lasttradingday[104] = 1060831;
lasttradingday[105] = 1060929;
lasttradingday[106] = 1061031;
lasttradingday[107] = 1061130;
lasttradingday[108] = 1061229;
lasttradingday[109] = 1070131;
lasttradingday[110] = 1070228;
lasttradingday[111] = 1070330;
lasttradingday[112] = 1070430;
lasttradingday[113] = 1070531;
lasttradingday[114] = 1070629;
lasttradingday[115] = 1070731;
lasttradingday[116] = 1070831;
lasttradingday[117] = 1070928;
lasttradingday[118] = 1071031;
lasttradingday[119] = 1071130;
lasttradingday[120] = 1071231;
lasttradingday[121] = 1080131;
lasttradingday[122] = 1080229;
lasttradingday[123] = 1080331;
lasttradingday[124] = 1080430;
lasttradingday[125] = 1080530;
lasttradingday[126] = 1080630;
lasttradingday[127] = 1080731;
lasttradingday[128] = 1080829;
lasttradingday[129] = 1080930;
lasttradingday[130] = 1081031;
lasttradingday[131] = 1081128;
lasttradingday[132] = 1081230;
lasttradingday[133] = 1090130;
lasttradingday[134] = 1090227;
lasttradingday[135] = 1090331;
lasttradingday[136] = 1090430;
lasttradingday[137] = 1090529;
lasttradingday[138] = 1090630;
lasttradingday[139] = 1090731;
lasttradingday[140] = 1090831;
lasttradingday[141] = 1090930;
lasttradingday[142] = 1091030;
lasttradingday[143] = 1091130;
lasttradingday[144] = 1091230;
lasttradingday[145] = 1100129;
lasttradingday[146] = 1100226;
lasttradingday[147] = 1100331;
lasttradingday[148] = 1100430;
lasttradingday[149] = 1100531;
lasttradingday[150] = 1100630;
lasttradingday[151] = 1100730;
lasttradingday[152] = 1100831;
lasttradingday[153] = 1100930;
lasttradingday[154] = 1101029;
lasttradingday[155] = 1101130;
lasttradingday[156] = 1101230;
lasttradingday[157] = 1110131;
lasttradingday[158] = 1110228;
lasttradingday[159] = 1110331;
lasttradingday[160] = 1110429;
lasttradingday[161] = 1110531;
lasttradingday[162] = 1110630;
lasttradingday[163] = 1110729;
lasttradingday[164] = 1110831;
lasttradingday[165] = 1110930;
lasttradingday[166] = 1111031;
lasttradingday[167] = 1111130;
lasttradingday[168] = 1111230;
lasttradingday[169] = 1120131;
lasttradingday[170] = 1120229;
lasttradingday[171] = 1120330;
lasttradingday[172] = 1120430;
lasttradingday[173] = 1120531;
lasttradingday[174] = 1120629;
lasttradingday[175] = 1120731;
lasttradingday[176] = 1120831;
lasttradingday[177] = 1120928;
lasttradingday[178] = 1121031;
lasttradingday[179] = 1121130;
lasttradingday[180] = 1121228;
lasttradingday[181] = 1130131;
lasttradingday[182] = 1130228;
lasttradingday[183] = 1130328;
lasttradingday[184] = 1130430;
lasttradingday[185] = 1130531;
lasttradingday[186] = 1130628;
lasttradingday[187] = 1130731;
lasttradingday[188] = 1130830;
lasttradingday[189] = 1130930;
lasttradingday[190] = 1131031;
lasttradingday[191] = 1131129;
lasttradingday[192] = 1131230;
lasttradingday[193] = 1140131;
lasttradingday[194] = 1140228;
lasttradingday[195] = 1140331;
lasttradingday[196] = 1140430;
lasttradingday[197] = 1140530;
lasttradingday[198] = 1140630;
lasttradingday[199] = 1140731;
lasttradingday[200] = 1140829;
lasttradingday[201] = 1140930;
lasttradingday[202] = 1141031;
lasttradingday[203] = 1141128;
lasttradingday[204] = 1141230;
lasttradingday[205] = 1150130;
lasttradingday[206] = 1150227;
lasttradingday[207] = 1150331;
lasttradingday[208] = 1150430;
lasttradingday[209] = 1150529;
lasttradingday[210] = 1150630;
lasttradingday[211] = 1150731;
lasttradingday[212] = 1150831;
lasttradingday[213] = 1150930;
lasttradingday[214] = 1151030;
lasttradingday[215] = 1151130;
lasttradingday[216] = 1151230;
lasttradingday[217] = 1160129;
lasttradingday[218] = 1160229;
lasttradingday[219] = 1160331;
lasttradingday[220] = 1160429;
lasttradingday[221] = 1160531;
lasttradingday[222] = 1160630;
lasttradingday[223] = 1160729;
lasttradingday[224] = 1160831;
lasttradingday[225] = 1160930;
lasttradingday[226] = 1161031;
lasttradingday[227] = 1161130;
lasttradingday[228] = 1161230;
lasttradingday[229] = 1170131;
lasttradingday[230] = 1170228;
lasttradingday[231] = 1170331;
NumCts = InitialCapital/close;
for j=0 to 400 begin if Date = LastTradingDay[j] then CmpDate = JulianToDate(DateToJulian(Date) + DayDiff); end;
{Open Position at last trading day + x days }
if date = CmpDate then begin
if Style = 1 then buy NumCts shares this bar close;
if Style = 2 then Sell short NumCts shares next bar Open;
end;
{Sell after x tradingdays}
if barssinceentry = nBarExit and Style = 1 then sell this bar close;
if barssinceentry = nBarExit and Style = 2 then buy to cover this bar close;
Helmut
- Attachments
-
- mibtelEOM.png
- (69.46 KiB) Downloaded 1307 times
Re: Pre-loop a chart
Hi Helmut,
unfortunately what you propose does not meet the requirements of signalworks
but with a day of delay !!!
Then you plot the arrow at barnumber-1, but it is an artificial adjustment.
I think the right approach is to integrate the signalworks code, or my simplified version, which calculate the last day in correct time, with an input of dates for handling exceptions (holidays or special closures).
Best regards.
Max
unfortunately what you propose does not meet the requirements of signalworks
Your code surelyI need the info: today is the last trading day of a month. (not a day later on beginning of the new month).
catch all last trading days for a timeseries
but with a day of delay !!!
Then you plot the arrow at barnumber-1, but it is an artificial adjustment.
I think the right approach is to integrate the signalworks code, or my simplified version, which calculate the last day in correct time, with an input of dates for handling exceptions (holidays or special closures).
Best regards.
Max
- signalworks
- Posts: 65
- Joined: 06 Oct 2013
- Location: Germany.Solingen
- Has thanked: 23 times
- Been thanked: 2 times
- Contact:
Re: Pre-loop a chart
Hello Helmut,
http://www.wincalendar.com/Holiday-Calendar/May-2010
http://www.wincalendar.com/Holiday-Calendar/March-2013
For both (and in general) holidays is an additional logic necessary.
For my purposes, in those cases is sufficient enough for me, because of lowly commonness of holidays accross the end of a month.
However, here an update of the function SWF_LastDayOf to "solve" those cases with my "solution":
best regards,
sw
The 2010/05/31 was the Memorial Day in USA. The 2013/03/28 was the Good Friday.In 2010 the last trading day in SPY was on Friday 05/28, in 2013 Thursday 03/28. In this cases a modification is required.
http://www.wincalendar.com/Holiday-Calendar/May-2010
http://www.wincalendar.com/Holiday-Calendar/March-2013
For both (and in general) holidays is an additional logic necessary.
For my purposes, in those cases is
Code: Select all
month(date) <> month(date[1])
However, here an update of the function SWF_LastDayOf to "solve" those cases with my "solution":
Code: Select all
///////////////////////////////////////////////////////////
//MODUL: Function SWF_LastDayOf
//DESCRIPTION: calculates LastDayOf (week|month|year)
//Author: Signalworks
//Version: 1.2
//Date: 02.05.2017
//////////////////////////////////////////////////////////
Inputs: MODE_LDO(numericSimple), oflag_ldo(numericRef), odd(numericRef), omd(numericRef),
omd_last(numericRef), ome(numericRef), oyd(numericRef), ocd(numericRef), olc(numericRef),
owd(numericRef), oda(numericRef), omo(numericRef);
vars: dow(0);
oflag_ldo = 0;
oda = round(fracportion(date / 100) * 100,0);
omo = month(date);
value1 = SWF_DayOfWeek_v1.1(odd, omd, omd_last, ome, oyd, ocd, olc, owd);
switch(MODE_LDO)
begin
case 0:
//LastDayOfWeek
dow = dayOfWeek(date);
if dow = 5
then
oflag_ldo = 1;
case 1:
//LastDayOf->month|year
switch(omo)
begin
case 1,3,5,7,8,10,12:
if (owd > 0 and owd < 6 and oda = 31)
or (owd = 0 and oda = 29)
or (owd = 6 and oda = 30)
then
oflag_ldo = 1;
case 4,6,9,11:
if (owd > 0 and owd < 6 and oda = 30)
or (owd = 0 and oda = 28)
or (owd = 6 and oda = 29)
then
oflag_ldo = 1;
case 2:
if (owd > 0 and owd < 6 and oda = 28 + olc * (-1))
or (owd = 0 and oda = 26 + olc * (-1))
or (owd = 6 and oda = 27 + olc * (-1))
then
oflag_ldo = 1;
end;
end;
if month(date) <> month(date[1]) and oflag_ldo[1] <> 1
then
oFlag_ldo = 1;
SWF_LastDayOf_v1.2 = 0;
sw
- Attachments
-
- ldo_v1.2_spx_2010.PNG
- (76.72 KiB) Downloaded 1281 times