Help please

Questions about MultiCharts and user contributed studies.
User avatar
ACMilan
Posts: 53
Joined: 08 Feb 2013
Has thanked: 2 times
Been thanked: 2 times

Help please

Postby ACMilan » 25 May 2017

Hello there, I am wondering if anyone out there can help me with this issue.
Lets say that I have 4 different charts, different markets
On each chart I insert the ATR.
I would like to write a code that will give me the the average of all the ATR and the Lowest of all the ATR
Does anyone know how to do it?
Thank you in advance

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

Re: Help please

Postby TJ » 25 May 2017

Hello there, I am wondering if anyone out there can help me with this issue.
Lets say that I have 4 different charts, different markets
On each chart I insert the ATR.
I would like to write a code that will give me the the average of all the ATR and the Lowest of all the ATR
Does anyone know how to do it?
Thank you in advance

You will need to transfer data between indicators.

Look up these keywords:

i_getplotvalue
i_setplotvalue

User avatar
ACMilan
Posts: 53
Joined: 08 Feb 2013
Has thanked: 2 times
Been thanked: 2 times

Re: Help please

Postby ACMilan » 25 May 2017

Thank you TJ
unfortunately I need more info than that but I do appreciate your reply
Cheers

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

Re: Help please

Postby JoshM » 26 May 2017

Hello there, I am wondering if anyone out there can help me with this issue.
Lets say that I have 4 different charts, different markets
On each chart I insert the ATR.
I would like to write a code that will give me the the average of all the ATR and the Lowest of all the ATR
Does anyone know how to do it?
You will need to transfer data between indicators.

Look up these keywords:

i_getplotvalue
i_setplotvalue
Those keywords help when passing data between scripts that are on the same chart, but can unfortunately not pass data from one chart to another. So sending the ATR value from 4 different charts to get the average ATR isn't possible with that.

ACMilan, did you try the build-in functions for global variables? From my understanding there are several functions named like `GVSetNamedDouble()` and `GVGetNamedDouble()` that come with MultiCharts pre-installed (without the need to install an additional tool as EL Collection or ADE).

(Those functions all have different names but all start with 'GV'.)

User avatar
ACMilan
Posts: 53
Joined: 08 Feb 2013
Has thanked: 2 times
Been thanked: 2 times

Re: Help please

Postby ACMilan » 27 May 2017

Hi Josh
No I have not tried yet. I actually just learned about the GV options. I am going to look into it
Basically what I am trying to do is to manage profits from a previous trade using either the lowest ATR or the Av Atr from all the 4 markets I follow
I think this is beyond my capabilities however.
Thank you for our reply

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

Re: Help please

Postby JoshM » 28 May 2017

I think this is beyond my capabilities however.
It doesn't have to be, just take it step by step:

1. Create an indicator that plots the ATR on the chart.
2. Add to that indicator the function that will send out the ATR value as a global variable (probably something like `GVSetNamedDouble(SymbolName + "atr", myAtrVariable)`).
3. Create another indicator that should receive the information from the other 4 scripts.
4. Add the code to receive information through the global variables to that new script (probably something like `GVGetNamedDouble("ESatr")`).
5. Combine the code together in that new indicator to calculate the average ATR and the highest/lowest ATR value.

There are probably a bit more steps since I'm unclear what you mean with "manage" the previous trade, but if you take it step by step you'll get there. And if you get stuck, just ask us here on the forum for help. Hope this helps. :)

User avatar
ACMilan
Posts: 53
Joined: 08 Feb 2013
Has thanked: 2 times
Been thanked: 2 times

Re: Help please

Postby ACMilan » 28 May 2017

Hi. Thank you I really appreciate your help.
This is what I meant.
I follow four mkts and each one has 4 different time frames.
Same strategy on all.
Let's say I made 500 dollars in Crude oil on chart 1, if I get another signal on chart 3, I want to be able to set a stop that will protect that 500 dollars. Maybe exit if I am losing 250 of that.
A good way of doing that is averaging all the atr from all the mkts and use that value as a stop. Or using the lowest atr from all the charts. I haven't decided yet. That way I can have a stop that is somewhat dynamic and not trying to pick a set dollars amount for the stop.
That is what I m trying to do.
What you write is very helpful.
Thanks again!!!!

User avatar
ACMilan
Posts: 53
Joined: 08 Feb 2013
Has thanked: 2 times
Been thanked: 2 times

Re: Help please

Postby ACMilan » 30 May 2017

Hi Josh.
according to MC these variables are not present in the library.
* GVGetNamedDouble
* GVGetNamedInt
* GVSetNamedDouble
* GVSetNamedInt

They suggested using these instead
AccuracyGetNamedDouble
AccuracyGetNamedInt
AccuracySetNamedDouble
AccuracySetNamedInt

What do you think?
Thanks

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

Re: Help please

Postby JoshM » 31 May 2017

according to MC these variables are not present in the library.
* GVGetNamedDouble
* GVGetNamedInt
* GVSetNamedDouble
* GVSetNamedInt

They suggested using these instead
AccuracyGetNamedDouble
AccuracyGetNamedInt
AccuracySetNamedDouble
AccuracySetNamedInt

What do you think?
I haven't used those latter ones since the GV* functions are still installed with my MultiCharts version. Your forum post is the first one that mention them if I search, so they seem to be pretty new. :)

I would use these newer ones, especially if MultiCharts advises to do so. (Unless, of course, they don't work or have an issue, but we aren't there yet.)
Let's say I made 500 dollars in Crude oil on chart 1, if I get another signal on chart 3, I want to be able to set a stop that will protect that 500 dollars. Maybe exit if I am losing 250 of that.
A good way of doing that is averaging all the atr from all the mkts and use that value as a stop. Or using the lowest atr from all the charts. I haven't decided yet. That way I can have a stop that is somewhat dynamic and not trying to pick a set dollars amount for the stop.
I haven't tested the following, but to get you started this I how I would initially try to get the net profit from four charts into a signal script running on one:

Code: Select all

Variables:
profitOil(0),
profitES(0),
profitNQ(0),
profitYM(0),
strategyProfit(0);

if (GetAppInfo(aiStrategyAuto) = 1) then begin

// Set the strategy's profit in a global variable
AccuracySetNamedDouble(SymbolName + "_profit", NetProfit);

// Get the current profits from all signals
profitOil = AccuracyGetNamedDouble("oil_profit", -1);
profitES = AccuracyGetNamedDouble("es_profit", -1);
profitNQ = AccuracyGetNamedDouble("nq_profit", -1);
profitYM = AccuracyGetNamedDouble("ym_profit", -1);

if (profitOil = -1 or profitES = -1 or
profitNQ = -1 or profitYM = -1) then
RaiseRunTimeError("Failed to receive one of the instrument's profit data.");

strategyProfit = profitOil + profitES + profitNQ + profitYM;

end;
As the code shows, first we store the strategy's current net profit in a global variable with `AccuracySetNamedDouble()`. Then we use `AccuracyGetNamedDouble()` to get the net profit from the four charts/symbols.

If one of the returned values signals an error (perhaps the strategy wasn't active on that chart), we raise an error to notify us of that. (Perhaps not the most safe code to run when trading live, since those errors turn of the strategy's auto trading. But you'll need to find some way to trigger an alert or audio notification when the different charts cannot communicate with each other.)

Good luck!

User avatar
ACMilan
Posts: 53
Joined: 08 Feb 2013
Has thanked: 2 times
Been thanked: 2 times

Re: Help please

Postby ACMilan » 31 May 2017

A BIG Thank you!
I will try it


Return to “MultiCharts”