Refer the close of a specific bar?

Questions about MultiCharts and user contributed studies.
grt260
Posts: 6
Joined: 21 Sep 2011

Refer the close of a specific bar?

Postby grt260 » 01 Nov 2011

Hi all,

I want to know whether EL have a function that can find the close of a specific bar? for example, i want to refer the close of the bar at 10:00am , and if the close now > the close of 10:00am bar, then buy.

it is just a simple condition using time as a condition, i want even more complex condition that can mark the close of the specific bar, How can i mark it and recall it?

Thanks again!

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: Refer the close of a specific bar?

Postby furytrader » 01 Nov 2011

I imagine it would be something like this:

Code: Select all

vars: SpecialClose(0);

If Time = 1000 Then SpecialClose = Close;
If Time > 1000 and C > SpecialClose Then [Insert Trade Logic Here];
These users thanked the author furytrader for the post:
JoshM

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Re: Refer the close of a specific bar?

Postby TJ » 01 Nov 2011

grt260 wrote:Hi all,

I want to know whether EL have a function that can find the close of a specific bar? for example, i want to refer the close of the bar at 10:00am , and if the close now > the close of 10:00am bar, then buy.

it is just a simple condition using time as a condition, i want even more complex condition that can mark the close of the specific bar, How can i mark it and recall it?

Thanks again!

There are a few background questions you must decide before delving into coding:

1. what is the instrument and chart resolution?

2. is this a recurring time that you need? eg. you want the close price of 10:00am everyday?

or,

3. the time might be variable? say, the time now might be 3pm or it might be 2pm, and you want to know the close at 11:00am or 10:30am?

4. do you need to know the time from previous days? eg. comparing 10am volume with 10am price of yesterday.


Each of the scenario might require a different coding method.
These users thanked the author TJ for the post:
JoshM

grt260
Posts: 6
Joined: 21 Sep 2011

Re: Refer the close of a specific bar?

Postby grt260 » 01 Nov 2011

furytrader wrote:I imagine it would be something like this:

Code: Select all

vars: SpecialClose(0);

If Time = 1000 Then SpecialClose = Close;
If Time > 1000 and C > SpecialClose Then [Insert Trade Logic Here];


Thanks, it is easy to use time as a condition, but how about i use ES>=+5 (data2, change compare to yesterday close), and mark the bar of close in data1?
vars: var0(0),specialclose(0);
if time=0415 then close of data2=var0;
if close of data2 - var0>=5 then specialclose=close of data1

however, in the above scripts, the specialclose will change and cannot fixed to the first bar that ES>=+5.

How to mark and fix in the first bar that ES>=+5 of close of data1?
thanks.

User avatar
Henry MultiСharts
Posts: 8520
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2741 times

Re: Refer the close of a specific bar?

Postby Henry MultiСharts » 01 Nov 2011

The symbol name cannot be compared with such values as time or price.
You need to compare the symbol name with the symbol name, price with price...
You can assign the first close of calculation to the SpecialClose by writing in your script:

Code: Select all

once SpecialClose = close;

grt260
Posts: 6
Joined: 21 Sep 2011

Re: Refer the close of a specific bar?

Postby grt260 » 01 Nov 2011

Henry Multicharts wrote:The symbol name cannot be compared with such values as time or price.
You need to compare the symbol name with the symbol name, price with price...
You can assign the first close of calculation to the SpecialClose by writing in your script:

Code: Select all

once SpecialClose = close;


Thanks,
in order to make it clear what's my aim,
here is the indicator i created, and it is successfully mark the close,

Code: Select all

variables: var0(0),var1(0),var2(0);
if time  =0415 then var0=close of data2 else var0=var0[1];

if close of data2-var0 >= 5  then

var2=close of data1;

else  var2=0;

if close[1]of data2-var0 >=5 then var2=var2[1];

 plot1(var2);


However it is not working if i change it to Signal....

Code: Select all

variables: var0(0),var1(0),var2(0);

if time=0415 then var0=close of data2 else var0=var0[1];

if close of data2-var0>=5 then

var2=close of data1

else  var2=0;

if close[1]of data2-var0 >=5 then var2=var2[1];

 if var2<>0 then
 buy next bar at  market;


Why is that happen? is there any way i can simplify the script by using "Once"?

User avatar
Henry MultiСharts
Posts: 8520
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2741 times

Re: Refer the close of a specific bar?

Postby Henry MultiСharts » 02 Nov 2011

Please describe what do you mean by "it is not working ".
If you want the signal calculation to match to the indicator calculation-you need to enable Intra bar order generation for the signal.


Return to “MultiCharts”