How to get the exitprice in the indicator

Questions about MultiCharts and user contributed studies.
flyinglight
Posts: 2
Joined: 25 Aug 2010

How to get the exitprice in the indicator

Postby flyinglight » 25 Aug 2010

Hi

I have a few questions:

1) Is it possible to get the exit price generated by a strategy in the indicator.
2) Is there a way of getting the orders from the chart hint window in the indicator?

Any assistance at all would be very helpful.

Thanks

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: How to get the exitprice in the indicator

Postby Dave Masalov » 31 Aug 2010

Dear flyinglight,

1) In strategy - original code + the following line:

Code: Select all

GVSetNamedInt("ExitPrice", exitprice);
How to get exitprice in indicator:

Code: Select all

var: exit_price(0);
GVGetNamedInt("ExitPrice", exit_price);
plot1(exit_price);
2) This is not possible, strategy does not have direct access to this info.

flyinglight
Posts: 2
Joined: 25 Aug 2010

Re: How to get the exitprice in the indicator

Postby flyinglight » 01 Sep 2010

Is it possible that DLL get the orders on the chart or the hint window?
I would like to know how to get the orders, using functions or interfaces like IEasyLanguageObject provided by the EasyLanguage Extension SDK.

Thanks a lot

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: How to get the exitprice in the indicator

Postby Dave Masalov » 01 Sep 2010

Dear flyinglight,

Unfortunately, this is not possible. There are no interfaces for orders there.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: How to get the exitprice in the indicator

Postby janus » 01 Sep 2010

Dear flyinglight,

1) In strategy - original code + the following line:

Code: Select all

GVSetNamedInt("ExitPrice", exitprice);
How to get exitprice in indicator:

Code: Select all

var: exit_price(0);
GVGetNamedInt("ExitPrice", exit_price);
plot1(exit_price);
Dave, you just gave me an idea. If I can be guaranteed that even on multi-core processes a strategy is always executed before an indicator on the same chart on each tick update, then I could put all my code in the strategy and pass only what I need to plot on the chart to an indicator using global variables. So, is that guarantee valid?

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: How to get the exitprice in the indicator

Postby janus » 02 Sep 2010

Code: Select all

var: exit_price(0);
GVGetNamedInt("ExitPrice", exit_price);
plot1(exit_price);
BTW, the code above is incorrect. It should be:

Code: Select all

var: exit_price(0), error_code(0);
exit_price = GVGetNamedInt("ExitPrice", error_code);
plot1(exit_price);

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: How to get the exitprice in the indicator

Postby Dave Masalov » 02 Sep 2010

So, is that guarantee valid?
Dear janus,

Unfortunately, there is no such guarantee.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: How to get the exitprice in the indicator

Postby janus » 02 Sep 2010

So, is that guarantee valid?
Dear janus,
Unfortunately, there is no such guarantee.
That's a pity. Something should be done in a future release to allow linkages of studies to be coordinated to realise the full potential of global variables. Otherwise, global variables will always be unpredictable and unreliable for exchanging information between studies, and be of little value for most situations.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: How to get the exitprice in the indicator

Postby Dave Masalov » 02 Sep 2010

Dear janus,

Generally, there is no order in the calculation of the scripts, but you can set it up the way that strategies will be calculated before a particular indicator. All you need to to do is use the keywords for strategies in this indicator. For example, write

Code: Select all

value1=i_MarketPosition;
in this indicator. Then you will have such guarantee.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: How to get the exitprice in the indicator

Postby janus » 02 Sep 2010

..but you can set it up the way that strategies will be calculated before a particular indicator. All you need to to do is use the keywords for strategies in this indicator. For example, write

Code: Select all

value1=i_MarketPosition;
in this indicator. Then you will have such guarantee.
Three points need clarification:
1. Will any of the 8 or so keywords starting with "i_" provide such a guarantee?
2. Using any of them in an indicator will force the strategy to be run before the indicator, not after the indicator? Is this because the indicator relies on the strategy to gather the information so it must wait for the strategy to run first?
3. This synchronization between an indicator and a strategy only applies when they are on the same chart window, worksheet, or anywhere?

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: How to get the exitprice in the indicator

Postby Dave Masalov » 03 Sep 2010

Dear janus,

Let me answer your questions one by one:

1. Yes.
2. Yes, that's correct.
3. One chart window.

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

Re: How to get the exitprice in the indicator

Postby JoshM » 28 Jul 2011

Dear flyinglight,

1) In strategy - original code + the following line:

Code: Select all

GVSetNamedInt("ExitPrice", exitprice);
How to get exitprice in indicator:

Code: Select all

var: exit_price(0);
GVGetNamedInt("ExitPrice", exit_price);
plot1(exit_price);
[..]
[..]
BTW, the code above is incorrect. It should be:

Code: Select all

var: exit_price(0), error_code(0);
exit_price = GVGetNamedInt("ExitPrice", error_code);
plot1(exit_price);
Should this still work in MultiCharts Version 7.0 Release (Build 4510)? From my testing it doesn't work.

My strategy contains this..

Code: Select all

GVSetNamedInt("ExitPrice", exitprice(1));

Print("Exitprice: ", exitprice(1));
..and the indicator:

Code: Select all

var: exit_price(0), error_code(0);

exit_price = GVGetNamedInt("ExitPrice", error_code);

plot1(exit_price);

Print(spaces(3), " indicator: ", exit_price);
..which gives the following output:
Exitprice: 1.45
Exitprice: 1.45
Exitprice: 1.45
Exitprice: 1.45
Exitprice: 1.45
85453.00 - Backtest done!
indicator: 1.00
indicator: 1.00
indicator: 1.00
indicator: 1.00
Suggesting that the indicator gets calculated when the strategy is done calculating, which prevents the indicator from using the value provided by the strategy. This is confirmed by the 'backtest done' line, which is printed in the strategy in the LastBarOnChart statement.

Another example
Strategy:

Code: Select all

vars: SetGV(0), GetGV(0);

SetGV = GVSetNamedDouble("myClose", close);
GetGV = GVGetNamedDouble("myClose", value1);

Print(date:0:0, " ", time_s:0:0, " close: ", close:0:5, " Set GV value: ", SetGV, " Get GV value: ", GetGV:0:5);
..and indicator:

Code: Select all

vars: GetGV(0), message(0);

GetGV = GVGetNamedDouble("myClose", message);

Print(date:0:0, "_", time_s:0:0, Spaces(3), " calling from Indicator. GV: ", GetGV:0:5, " error code: ", message);

Plot1(GetGV, "GV");
which gives the following output:
1110726 115705 close: 1.44698 Set GV value: 0.00 Get GV value: 1.44698
1110726 115822 close: 1.44694 Set GV value: 0.00 Get GV value: 1.44694
1110726 115908 close: 1.44746 Set GV value: 0.00 Get GV value: 1.44746
1110726 115957 close: 1.44755 Set GV value: 0.00 Get GV value: 1.44755
1110726 115959 close: 1.44754 Set GV value: 0.00 Get GV value: 1.44754
1110630_231525 calling from Indicator. GV: 1.44754 error code: 0.00
1110630_231715 calling from Indicator. GV: 1.44754 error code: 0.00
1110630_232012 calling from Indicator. GV: 1.44754 error code: 0.00
1110630_232446 calling from Indicator. GV: 1.44754 error code: 0.00
What am I missing, or can GlobalVariables only be used in real-time?

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: How to get the exitprice in the indicator

Postby SP » 28 Jul 2011

[quote="JoshM"]

[b]What am I missing, or can GlobalVariables only be used in real-time?[/b][/quote]


Josh,

GV works only realtime. Take a look at this post on bigmike: http://www.bigmiketrading.com/multichar ... #post33044

It contains a ADE version of a saver and loader modified by MC engineer ALEX so it can transfer data and marketposition between tick charts. For normal intraday interval you need to modify it a little bit.

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

Re: How to get the exitprice in the indicator

Postby JoshM » 28 Jul 2011

GV works only realtime. Take a look at this post on bigmike: http://www.bigmiketrading.com/multichar ... #post33044

It contains a ADE version of a saver and loader modified by MC engineer ALEX so it can transfer data and marketposition between tick charts. For normal intraday interval you need to modify it a little bit.
Thanks SP - for both confirming that GlobalVariables don't work on historical data and for the interesting link; will look into that. Thanks. :)


Return to “MultiCharts”