Jump to content
Medved Trader Forums

compare function in a paintbar


dennishh2024

Recommended Posts

Hi,

I am trying to replicate a market-gauge.

The preferred way to do this is to standardize the change on different instruments and compare them

For example, take the standardized change of 3 more offensive ETF's (XLC, XLK, XLY( and compare then to 3 more defensive ETF's (XLP, XLU, XLV) to gauge if the market move is a risk sentiment one:
 
(other example would be to take largecaps vs smallcaps)


To standardize it a good way is good to use the daily ATR(14). 

So 
change XLC/ATR_XLC + change XLK/ATR_XLK + change XLY/ATR_XLK
divided by
change XLP/ATR_XLP + change XLU/ATR_XLU + change XLV/ATR_XLV

That supposedly gives a line we can plot on an intraday chart. Let's call it the OD-line.


I made a script for the scanner on a 1 day historical chart to calculate the ATR.
It scans a list of 60 stocks/ETF's and displays the corresponding ATR in the scanner.

How exactly is this stored? 
How is the link to the symbol made?
How can I use this in a paintbar?

My idea is to plot the OD-line on some chart, like using the compare symbol function to plot it on the $TICK-NYSE chart that already goed from +1000 to -1000.

Is it possible to do this? 
I tried it but my program skills are lacking.  See my attempt...
Do I have to retrieve and store individual symbol ATR by an unique name?

For reference I included the Pinescript from TradingView.

Any help is appreciated.  

 

Pinescript_odline.txt scan 1day historical.txt attempt at ODline.txt

Link to comment
Share on other sites

No just on one chart. You treat it like the NYSE-Advance-Decline, or TICK-NYSE. TRIN-NYSE.
o gauge where the market is going and if it is a sustained broad move or just on a few names. 

But the standardized way of comparing is the interesting part. It allows in a single line/paintbar all this information.
You could do it with offensive sector ETF vs Defensive sector ETF. 
Or Mag7 stocks vs  SPY/NDX. Or Mega caps ETF vs Small Caps ETF. 

It just needs the historical ATR and store it. And then recall it in an intraday paintbar script, and use it in the calculation.  

Link to comment
Share on other sites

Here is the easiest and most efficient way..

1. Make a portfolio that contains XLP, XLC, XLY etc. - the 6 symbols.

2. Make a historical scan that just has ATR in it, calculates Change/ATR (make sure to check for 0) and does a SetInterVar(SymbolData.Symbol+"-ATR") for it. Run it on that 6 symbol portfolio separately.

3. In your paintbar or scan that wants to utilize those values, do the GetInterVar("XLC-ATR"), GetInterVar("XLP-ATR") etc, then use those values to do your calculation (again, check for 0 when you divide :)) and do a SetYValue() for that in order to show  it on the chart.

Link to comment
Share on other sites

historical scan script:

See picture of scanresults.

 

Paintbar script:
 

And then I get these errors on line 18 "double ODline = offense_move - defense_move;" 

Error CS0650 CS0270 about matrix declaration.
And I can't figured what to change. I searched the internet for these codes but that didnt help. 

Could you point me in the right direction?

 

 

scan_result_hist_atr.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...