Weekly open  [SOLVED]

Questions about MultiCharts and user contributed studies.
waldem
Posts: 115
Joined: 18 Nov 2013
Has thanked: 3 times
Been thanked: 4 times

Weekly open

Postby waldem » 23 Sep 2014

Hall all, i cannot solve this problem:
i have weekly bar strategy, the strategy start the trade on monday at open; therefore I need to get on monday the open value (=to Entryprice) to calculate the stop and targets.

i cannot understand why even the expert commentary than the function Print, doesn't work until the bar is not closed, see picture, therefore i cannot save the "open" value into one variable.

I have also tried with data2 but with no success. if i put daily on data2 i cannot calculate for example: dayofweek (date of data2) = 1, to find monday and calculate open.

thanks
walter
Attachments
1.png
(317.52 KiB) Downloaded 891 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Weekly open

Postby JoshM » 23 Sep 2014

i cannot understand why even the expert commentary than the function Print, doesn't work until the bar is not closed,
Have you tried using Intra-bar order generation in your strategy?

Btw, if your comment also applies to real-time data then I would guess this is caused by a coding issue, because in real-time you do not have to wait before the bar is closed before values of variables are updated.

waldem
Posts: 115
Joined: 18 Nov 2013
Has thanked: 3 times
Been thanked: 4 times

Re: Weekly open

Postby waldem » 23 Sep 2014

thanks for the reply, i have tried even with "bar magnifier" than with intrabarordergeneration.

if i use intrabarordergeneration the day will be multiplied by 4 in print and the strategy enter in different bar.

i think is working only with tick not with daily..

walter
Attachments
3.png
(194.6 KiB) Downloaded 884 times

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Weekly open

Postby Andrew MultiCharts » 23 Sep 2014

thanks for the reply, i have tried even with "bar magnifier" than with intrabarordergeneration.

if i use intrabarordergeneration the day will be multiplied by 4 in print and the strategy enter in different bar.

i think is working only with tick not with daily..

walter
Hello Walter,

Please read how signals with/without IOG/BM are calculated.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Weekly open

Postby JoshM » 23 Sep 2014

i have weekly bar strategy, the strategy start the trade on monday at open; therefore I need to get on monday the open value (=to Entryprice) to calculate the stop and targets.

i cannot understand why even the expert commentary than the function Print, doesn't work until the bar is not closed, see picture, therefore i cannot save the "open" value into one variable.
Can you describe your problem again and provide a code example that shows it?

I have no trouble trading the Monday open:

Image

Nor are there any troubles with accessing the open value on Monday:

Code: Select all

21-7-14: Open = 1.4398
28-7-14: Open = 1.4293
4-8-14: Open = 1.4423
11-8-14: Open = 1.4452
18-8-14: Open = 1.4377
25-8-14: Open = 1.4177
1-9-14: Open = 1.4073
8-9-14: Open = 1.3833
15-9-14: Open = 1.4395
22-9-14: Open = 1.4364

Code: Select all

{
23-9-14
Forum_TradeAtMondayOpen
}

[IntrabarOrderGeneration = true];

once ClearDebug;

if (MarketPosition(0) = 0) then begin

if (DayOfWeek(DateTime) = Monday) then begin
Buy ("EL") 1 contract next bar at market;
Print(FormatDate("d-M-y", DateTime), ": Open = ", NumToStr(Open, 4));
end;

end;

if (MarketPosition(0) > 0) then begin

if (DayOfWeek(DateTime) = Friday) then
Sell ("XL") all contracts next bar at market;

end;
Attachments
scr.23-09-2014 15.22.45.png
(5.6 KiB) Downloaded 967 times

waldem
Posts: 115
Joined: 18 Nov 2013
Has thanked: 3 times
Been thanked: 4 times

Re: Weekly open

Postby waldem » 23 Sep 2014

Thanks a lot Andrew, now the functionality is much more clear for me.

should i ask you if i can calculate only one variable on IOG?
the problem is that if i use IOG for all the code the entry is completely different because i look for close.

why i cannot use for exhample IntraBarPersist to calculate the open?

if i decide to use Data2 why i find more results for same variable?

if i ask: EP = open of data2;

i got 2 results for the same bar:
19/09/2014 0.00 95.00
19/09/2014 0.00 94.42

the first is related always to data1 and the second to data2.
thanks

waldem
Posts: 115
Joined: 18 Nov 2013
Has thanked: 3 times
Been thanked: 4 times

Re: Weekly open

Postby waldem » 23 Sep 2014

maybe i have solved with this string:

if dayofweek (date of data2) = monday then EP = open of data2;

i cannot understand why if i use it, the last buy disappear from the chart...

but anyway in print still remain...

walter

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Weekly open

Postby Andrew MultiCharts » 24 Sep 2014

Please give me the piece of code that prints the values.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Weekly open

Postby TJ » 24 Sep 2014

maybe i have solved with this string:
if dayofweek (date of data2) = monday then EP = open of data2;
::
What happens if Monday is a holiday?

waldem
Posts: 115
Joined: 18 Nov 2013
Has thanked: 3 times
Been thanked: 4 times

Re: Weekly open

Postby waldem » 24 Sep 2014

maybe i have solved with this string:
if dayofweek (date of data2) = monday then EP = open of data2;
::
What happens if Monday is a holiday?
you are rigth, therefore i need to do a counter of the Data2 to solve this.
i will try in the next days...
w.

waldem
Posts: 115
Joined: 18 Nov 2013
Has thanked: 3 times
Been thanked: 4 times

Re: Weekly open

Postby waldem » 24 Sep 2014

Please give me the piece of code that prints the values.
Henry, this is the extracted code for you (Data 1 weekly, Data2 Dayly):

Code: Select all

input: Capital (10000),LChnEn(5);

vars: TrdQty (0), Bar2 (0),MyDate (0),EP(0);


//ENTRY


if marketposition = 0 and C >= Highest(H[1],LChnEn) then begin


TrdQty = IntPortion(Capital / C );

buy ("buy CBO") TrdQty shares next bars at open ;

Bar2 = barnumber of data2;


end;

if marketposition = 1 then begin

sell ("sell CBO") TrdQty shares next bars at open;

end;

//Debug
if currentbar = 1 then cleardebug;

MyDate = datetojulian (Date of data2) ;

print (datetostring (MyDate) ," " , Barnumber of data2," " , Bar2 ," ", EP ," " );
as you see now following TJ, i'm looking for one counter and no more "monday open".

the problem is that i cannot isolate the 1st barnumber of data2 because the main bar is weekly and is always 1.
to sole it i guess i need to invert the situation, daily for entry and weekly to calculate the channel breakout.
but the complete code is very long and complex, for this reason i was looking at this solution.

any idea?
Attachments
1.png
(39.34 KiB) Downloaded 874 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Weekly open  [SOLVED]

Postby TJ » 24 Sep 2014

maybe i have solved with this string:
if dayofweek (date of data2) = monday then EP = open of data2;
::
What happens if Monday is a holiday?
you are rigth, therefore i need to do a counter of the Data2 to solve this.
i will try in the next days...
w.
Actually the logic is quite simple...

try this:

Code: Select all


if dayofweek (date) data2 < dayofweek (date[1]) data2 then ...

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Weekly open

Postby TJ » 24 Sep 2014

::
the problem is that i cannot isolate the 1st barnumber of data2 because the main bar is weekly and is always 1.
to sole it i guess i need to invert the situation, daily for entry and weekly to calculate the channel breakout.
but the complete code is very long and complex, for this reason i was looking at this solution.

any idea?
As a practice, you should always make the fastest fractal as data1, and slower fractals as secondary datas. You will save a lot of headache in managing timing problems.

waldem
Posts: 115
Joined: 18 Nov 2013
Has thanked: 3 times
Been thanked: 4 times

Re: Weekly open

Postby waldem » 25 Sep 2014

TJ, you are a genius!
thank you so much, i would never thought about that simple solution....

Walter

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Weekly open

Postby TJ » 25 Sep 2014

TJ, you are a genius!
thank you so much, i would never thought about that simple solution....
Walter
You are welcome Walter... coding is fun. :-)


Return to “MultiCharts”