Use second plot as input ?

Spin

Well-known member
Joined
May 22, 2019
Posts
361
Likes
121
Hello there fellow coders :)

It's been a while that I launched a thread of my own, but I am afraid the time has come. Again :D

I am looking to use the 'values' or 'data' from a secondary plot to use in calculations.
More specifically, I would like to add fractals to a second Study
Fractals are calculated like so:
Java:
List<SwingPoint> swingPoints = series.calcSwingPoints(getSettings().getInteger(Inputs.STRENGTH, 2));

so I need to create a secondary series that holds the data from a 'Study B'
OR
I need to figure out a way to use calcSwingPoints on the data/values of Study B (Study B stores floats for Open, High, Low, Close to the dataseries)

Did anyone on this expert forum try something similar before ?
What would be a good way to tackle this ?

Thanks for all hints, tips & snippets !! (y)
 
Last edited:

Spin

Well-known member
Joined
May 22, 2019
Posts
361
Likes
121
Yep, but it took me several coding hours:
I dove in a few rabbit holes first, to no avail (see below).
And then I realized that good advice that @MotiveWave_Joe once gave me, and put all of the logic into a single study.
https://support.motivewave.com/foru...ing-values-in-a-different-study.273/post-1103

A few of the rabbit holes (that did NOT work):
(I need to add here that Studies A and B both 'live' in a different Plot: A is calculated on Price, B is some sort of oscillator that takes volume into account and is drawn on a secondary plot)

  • tried to create a secondary DataSeries on the primary plot, to hold data from a different Study
    (I don't think this can be done ?)
  • export Values from Study A to DataSeries and import them into Study B
    (apparently each 'window' uses a different DataSeries, although values from both are shown in the Cursor Data Window, seemingly identical; who can shed light onto this ? :unsure:)
  • export Values from Study A to DataSeries and have a 'ulility'-class-method read them from within Study B
    (tried something similar to what STARC-bands does with Bollinger Bands - epic fail, hit the same wall)
  • save Values from Study A to a file and have Study B read them from that file
    (somewhat worked, but laggy)
  • thought of this, but did not try it in the end: store Values from A in a Redis-DB and have B read from it
    (should work imo, and faster too)
But the end result is this:
I drop Study B and have it draw markers on the secondary plot.
I drop Study A, that now holds (part of) the code from Study B, so it calculates the same oscillator / volume thing. Does not draw anything, since I only need the Values.
In Study A I added logic to draw BUY / SELL arrows; this logic uses Values from both Studies A and B.
(sorry for the pixelation; I am not allowed to share details :cool:)
1670011209295.png
 
Last edited:

Per

Member
Joined
Jun 12, 2021
Posts
23
Likes
5
Yeah that's what I sort of assumed. I had to update one of the indicators and decorate it with something else so I had to do it in one place, like you did.

I think it doesn't yet mean it is impossible, just that we don't know how to. It would be rather sad if this use case isn't covered because it would severely limit complex studies.
 

Spin

Well-known member
Joined
May 22, 2019
Posts
361
Likes
121
I fully agree, @Per !

And since everything is written to the DataSeries anyway, it shouldn't be too hard, no ? :unsure:
 
Top