Indicator calculating even if data field is n/a

Questions about MultiCharts and user contributed studies.
jorange
Posts: 6
Joined: 20 Sep 2018
Has thanked: 2 times

Indicator calculating even if data field is n/a

Postby jorange » 21 Jul 2019

Hi,

I'm having an issue with understanding what's happening below;
Prob3.png
(85.26 KiB) Downloaded 315 times
Prob4.png
(91.67 KiB) Downloaded 315 times
The code I'm using is this:

Code: Select all

//----------------------------------------------
var: spread(0);

//Spread calculation
spread = close data1 - close data2;

//Plots
plot1(spread, "SPREAD", blue);

//----------------------------------------------
I applied this to the first picture, where data1 is HAS and data2 is the /ES. When there's an n/a for HAS, the indicator also is n/a.

However, if I add /ES above, such as in the second picture [/ES is now data1, HAS is now data2, and /ES is data3], the indicator is now yielding a value, but it seems like it's calculating from the previously printed value, even if the current value is n/a.

The code I used in picture 2 is the same code from above, except

Code: Select all

spread = close data2 - close data3;
Can someone explain what's going on here, and how can I go about correcting this? Why are my results different in the two cases above, when the data that's being used should be the same in both cases (?)
Last edited by jorange on 21 Jul 2019, edited 2 times in total.

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

Re: Indicator calculating even if data field is n/a

Postby TJ » 21 Jul 2019

See post #1 & post #2
1. [FAQ] How to Post Codes ... so that people can read.
viewtopic.php?t=11713

jorange
Posts: 6
Joined: 20 Sep 2018
Has thanked: 2 times

Re: Indicator calculating even if data field is n/a

Postby jorange » 25 Jul 2019

I've been working on this on/off while doing other projects the past few days and just wanted to provide more info/what I've found:

1. In pictures 1 and 2 of this post, the code makes explicit reference to data1. If data1 has a value, then the indicator will print a value. If I switch the data around, such that data1 becomes data2, the program will not print a value. The code again is;

Code: Select all

var: spread(0);

//Spread calculation
spread = close data1 - close data2;

//Plots
plot1(spread, "SPREAD", blue);
A1.png
(77.96 KiB) Downloaded 293 times
A2.png
(139.2 KiB) Downloaded 293 times

2. The problem persists, dependent on if data1 has a value or not, even if the below code makes NO reference to data1. In pictures 3 and 4 are snapshots taken at the same time, using the same assets.

Code: Select all

var: spread(0);

//Spread calculation
spread = close data2 - close data3;

//Plots
plot1(spread, "SPREAD", blue);
A3.png
(82.75 KiB) Downloaded 293 times
A4.png
(79.08 KiB) Downloaded 293 times
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
I'd expect the indicator to print N/A if either data field is lacking a value, so I'm still not sure why there's a discrepancy.

Is there anyway that I can force the indicator to print N/A? This is a round-about way, but I'd still like to know why this issue persists.

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

Re: Indicator calculating even if data field is n/a

Postby TJ » 25 Jul 2019

Try this
Attachments
Matching.JPG
(49.84 KiB) Downloaded 290 times

jorange
Posts: 6
Joined: 20 Sep 2018
Has thanked: 2 times

Re: Indicator calculating even if data field is n/a

Postby jorange » 30 Jul 2019

Hey TJ,

Thanks for the suggestion, I went ahead and tried un-checking the real-time history matching options but the result was the same.

However, I did play around with the "Base Study On" field and noticed that if I switched the data, I was able to get the results I was expecting. See the pictures below for explanations.
A1.png
(72.19 KiB) Downloaded 262 times
A2.png
(165.75 KiB) Downloaded 262 times
A3.png
(149 KiB) Downloaded 262 times
While I'm happy that I'm getting the results I'm looking for, I'm still unsure why this solution is working. I'm still using the same code from before (see post above), so nothing is changing there.

I checked the wikis for more information and found that this https://www.multicharts.com/trading-sof ... ng_Studies page referred to something about "Setting Base Data Series" but I couldn't find anything related to that (there's something on selecting base data, I'm assuming that's what this was referring to, but it just explains how to select and not really the why).

In any case, the implications here are that I can't apply certain strategies due to discrepancies in the calculations, post regarding that below.

jorange
Posts: 6
Joined: 20 Sep 2018
Has thanked: 2 times

Re: Indicator calculating even if data field is n/a

Postby jorange » 30 Jul 2019

As in the previous posts, I start by making sure that the indicator is printing values that I expect.

1) The code for the below picture is:

Code: Select all

inputs: pairslen(5);
var: spread(0), pairs(0);

//Spread calculation
spread = close data1 - close data2;

//Pairs calculation
pairs = RSI(spread, pairslen);

//Plots
plot1(pairs, "pairs", blue);
IndTest1.png
(75.39 KiB) Downloaded 262 times
2) Then, because I want to apply a strategy on data2 (in this case ES), I make a new workspace with data2 now becoming data1, and then reloading the previous data1 as data2, and the previous data2 as data3.

The code I used for this workspace is:

Code: Select all

inputs: pairslen(5);
var: spread(0), pairs(0);

//Spread calculation
spread = close data2 - close data3;

//Pairs calculation
pairs = RSI(spread, pairslen);

//Plots
plot1(pairs, "pairs", blue);
IndTest2.png
(89.68 KiB) Downloaded 262 times
3)After confirming that both workspaces are printing the same values for the respective studies, I now try to apply the below code on the first workspace:

Code: Select all

inputs: pairslen(5), overbought(20), oversold(60);
var: spread(0), pairs(0);

//Spread calculation
spread = close data1 - close data2;

//Pairs calculation
pairs = RSI(spread, pairslen);

//Strategy
//Long Entry + Exit Logic
if pairs crosses above overbought then buy this bar on close;
if pairs crosses above oversold then sell this bar on close;

//Short Entry + Exit Logic
if pairs crosses below oversold then sellshort this bar on close;
if pairs crosses below overbought then buytocover this bar on close;
The results for this code are displayed in this image:
StratT1.png
(82.9 KiB) Downloaded 262 times
4) Now, here's where the issue that stems from the question that started this whole thread arises (or at least I think this is the same issue). When I try to apply similar code to the second workspace, I now get different results (consistent with results that would happen if I didn't change the base study drop down box).


The code that I used for the second workspace is the same as the previous, except spread is now, spread = close data2 - close data3.

Code: Select all

inputs: pairslen(5), overbought(20), oversold(60);
var: spread(0), pairs(0);

//Spread calculation
spread = close data2 - close data3;

//Pairs calculation
pairs = RSI(spread, pairslen);

//Strategy
//Long Entry + Exit Logic
if pairs crosses above overbought then buy this bar on close;
if pairs crosses above oversold then sell this bar on close;

//Short Entry + Exit Logic
if pairs crosses below oversold then sellshort this bar on close;
if pairs crosses below overbought then buytocover this bar on close;
StratT2.png
(99.13 KiB) Downloaded 262 times
5) Finally, to confirm that the positions aren't aligning, I set the signal to allow for multiple positions.
StratT3.png
(96.37 KiB) Downloaded 262 times
----------------------------------------------------------------------------------------------------------------------------------------------------------------

The above is the workflow I used to try to explain the issue that I think is related to my original question/problem.

I believe that now my question is; how can I change the signal/strategy in a similar way that I did with the indicator/study? Is there a button or field similar to the previous post, but specifically for signals? Or, do I need to force N/A values in the code? If so, how would I do that?

jorange
Posts: 6
Joined: 20 Sep 2018
Has thanked: 2 times

Re: Indicator calculating even if data field is n/a

Postby jorange » 15 Aug 2019

Bump/update;

I did some digging around the settings and couldn't find a solution. Checked the manual and no dice, but I did find this floating on the forums:

viewtopic.php?t=46806

Reading through this thread from 2014, it seems like the thread author had a similar issue (that the frequency of one of the data series is having an impact on their signals). The second to last post by JoshM suggested this;

"Given that your data 1 is not very active compared to data 2, have you tried using the Recalculate reserved word together with IOG? For more, see how signals are calculated."

I thought this would be the solution, but I don't understand the logic of using recalculate + IOG to remedy the above issues.

Any input would be appreciated!


Return to “MultiCharts”