How to store and take out data from another graph?  [SOLVED]

Questions about MultiCharts and user contributed studies.
treksis
Posts: 13
Joined: 18 Jul 2014
Has thanked: 4 times

How to store and take out data from another graph?

Postby treksis » 31 Jul 2014

I want to make a code which sells/buys facebook shares when s&p500 drops in price.
Facebook is the 1st/main graph I look at and s&p500 is the second graph I want to refer to.

For example, if FB reaches 20bar high but s&p500 drops in price then sell FB this bar on close.

Code: Select all

condition1=check s&p500
if close > highest(close,20) and condition1 then
sell "Sell Fb" this bar on close;
How can I make the condition1?



Also, I would like know how I can compare closing prices based on the indicator value.
I can't use adx[...] since I don't know the exact number of bars before ADX was 20 ( assuming ADX now is at 60).
For example, I want to know whether the price increased or decreased while ADX went from 20 to 60.

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

Re: How to store and take out data from another graph?  [SOLVED]

Postby JoshM » 31 Jul 2014

I want to make a code which sells/buys facebook shares when s&p500 drops in price.
Facebook is the 1st/main graph I look at and s&p500 is the second graph I want to refer to.

For example, if FB reaches 20bar high but s&p500 drops in price then sell FB this bar on close.

Code: Select all

condition1=check s&p500
if close > highest(close,20) and condition1 then
sell "Sell Fb" this bar on close;
How can I make the condition1?
Perhaps something like this, but the actual implementation is dependent on what your meaning of "drop in S&P500 is". In the code below it's defined as a S&P500 bar that closes lower than the previous S&P500 bar:

Code: Select all

Variables:
spDrop(False);

spDrop = Close Data2 < Close[1] Data2;

if (Close Data1 > Highest(Close Data1, 20)) and (spDrop = true) then
Sell "Sell FB" this bar on close;
Also, I would like know how I can compare closing prices based on the indicator value.
I can't use adx[...] since I don't know the exact number of bars before ADX was 20 ( assuming ADX now is at 60).
For example, I want to know whether the price increased or decreased while ADX went from 20 to 60.
In pseudo-code, you could try that with something like this:

Code: Select all

Variables:
adxBarNum(0);

if (ADX = 20) then
adxBarNum = CurrentBar;

Print("Close price of ADX at 20 = ", Close[CurrentBar - adxBarNum]);


Return to “MultiCharts”