Identical settings but Scanner values different to Chart!?!?

Questions about MultiCharts and user contributed studies.
kajkanjan
Posts: 33
Joined: 12 Feb 2012
Has thanked: 4 times
Been thanked: 1 time

Identical settings but Scanner values different to Chart!?!?

Postby kajkanjan » 21 Apr 2013

Hi All,

I have an indicator (Code below) that if I create a brand new watchlist and a brand new chart, so all settings identical, the value in the watchlist/scanner is different to what I see in the chart.

It all seems to do with the amount of data I have showing or available for calculation.

This is easy to monitor on the chart, as I can see how many bars back there are, but how do i know what is going on with the Scanner/Screener/Watchlist??? And why does it change so much and not match the price chart values?

I can understand if I tell the screener/watchlist to look only 5 bars back, that things may be miscalculated if i am using averages etc ... but why would the value be changing dramatically if i am looking 400 bars back compared to 500 bars back, when the max average i am using is a 60 day/bar average??

Code:

Code: Select all

inputs:
LongTerm1( 30 ),
LongTerm2( 35 ),
LongTerm3( 40 ),
LongTerm4( 45 ),
LongTerm5( 50 ),
LongTerm6( 60 ),
Price ( Close ),
FirstPercentLevel ( 0.15),
SecondPercentLevel ( 0.2),
ThirdPercentLevel ( 0.25),
FourthPercentLevel ( 0.3),
SmoothingAvg ( 8 ),
OverBColor (Cyan);


Variables:
PriceDifference (0),
AverageofLongGMMA ( 0 ),
OverboughtLevel1 (0),
OverboughtLevel2 (0),
OverboughtLevel3 (0),
OverboughtLevel4 (0),
SmoothedPriceDifference (0);

arrays:
arr1[6]( 0 ) ;
arr1[1] = Xaverage(Price ,LongTerm1);
arr1[2] = Xaverage(Price ,LongTerm2);
arr1[3] = Xaverage(Price ,LongTerm3);
arr1[4] = Xaverage(Price ,LongTerm4);
arr1[5] = Xaverage(Price ,LongTerm5);
arr1[6] = Xaverage(Price ,LongTerm6);


PriceDifference = price - (arr1[6]);
AverageofLongGMMA = arr1[6];
OverboughtLevel1 = (AverageofLongGMMA + (AverageofLongGMMA * FirstPercentLevel ))- AverageofLongGMMA ;
OverboughtLevel2 = (AverageofLongGMMA + (AverageofLongGMMA * SecondPercentLevel ))- AverageofLongGMMA ;
OverboughtLevel3 = (AverageofLongGMMA + (AverageofLongGMMA * ThirdPercentLevel ))- AverageofLongGMMA ;
OverboughtLevel4 = (AverageofLongGMMA + (AverageofLongGMMA * FourthPercentLevel ))- AverageofLongGMMA ;
SmoothedPriceDifference = XAverage(PriceDifference ,SmoothingAvg );


plot1 (SmoothedPriceDifference , "Price Diff");
Plot3 ("Normal");
plot4 (OverboughtLevel1 , "Overbought Level 1");
plot5 (OverboughtLevel2 , "Overbought Level 2");
plot6 (OverboughtLevel3 , "Overbought Level 3");
plot7 (OverboughtLevel4 , "Overbought Level 4");



if SmoothedPriceDifference >= OverboughtLevel1 then
begin
SetPlotColor( 1, OverBColor ) ;
Plot3 ("Overbought 1");
end;

if SmoothedPriceDifference >= OverboughtLevel2 then Plot3 ("Overbought 2");
if SmoothedPriceDifference >= OverboughtLevel3 then Plot3 ("Overbought 3");
if SmoothedPriceDifference >= OverboughtLevel4 then Plot3 ("Overbought 4");
The easy one to test if you are looking at it is the:
Plot1 (SmoothedPriceDifference , "Price Diff");

What is going on here and how does this all work? How do i make sure that an indicator is ALWAYS looking at the correct amount of data needed to calculate CORRECT results? How to i ensure values are consistent across the board?

Thank you for your time and help
Kindest Regards,
Kaj

kajkanjan
Posts: 33
Joined: 12 Feb 2012
Has thanked: 4 times
Been thanked: 1 time

Re: Identical settings but Scanner values different to Chart

Postby kajkanjan » 22 Apr 2013

Don't mean to unnecessarily bump this thread, but I have been looking at a few more indicators/studies and am seeing more of the same thing.... where what I see plotted on a chart/sub-chart, the values are different to what is being given in the scanner/watchlist!?

It is not just for the above code.
It has me quite worried as i didn't realise this was happening and just 'assumed' everything was the same! It makes me not want to rely on the screener!!

How can i control this and keep this consistent?

Thanks!
Karl

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Identical settings but Scanner values different to Chart

Postby Henry MultiСharts » 24 Apr 2013

Hello Karl,

In order to have the same study calculation results you need to make the chart and scanner settings the same.

First of all set the maxbarsback value for your study right in the code (setmaxbarsback) or open your study in the PowerLanguage Editor and go to File->Properties->Properties->"Max bars study will reference"->User specified. You need to do that to have the same maxbarsback value for your study (there is no other way to setup maxbarsback in the scanner) in both study instances.

Data request should be the same in the scanner and on the chart. Right click on the symbol->Format Instrument->Settings tab->set all of the parameters the same way.

Add your study to the chart and into the scanner. Right click on the study plot->Format study->specify the same inputs and set the options "Update on every tick" and "Skip identical ticks" to the same position for both chart and scanner.

Once that is done-you will have the save calculation results:
Image
Attachments
kajkanjan.png
(47.43 KiB) Downloaded 641 times

kajkanjan
Posts: 33
Joined: 12 Feb 2012
Has thanked: 4 times
Been thanked: 1 time

Re: Identical settings but Scanner values different to Chart

Postby kajkanjan » 25 Apr 2013

Thank you for the feedback and tips!
I appreciate it and will implement it now.

I was just curious though as to why this is?
I thought the math was the math and the resulting value is the value of the indicator? on chart, on scanner etc. and if the data is historically there (for any historical indicators like an MA) the math is always the same?

Why, in the scanner, if I right-click on the resolution -> Format Resolution (All Instruments) and then tick the 'Use Custom Data Range' and change the value there, why does that seem to change the calculation?
Again, I can understand if I use only say 5 bars back, but why if I look at 150 or 300 does the value calculate differently? nowhere in the study/code do I need more than that amount of bars. 150 or 300 should be sufficient and return the same results, no?

Is there something bad in my code that is causing this that i have missed?

Just trying to understand so that I can be sure in the future to set things correctly.

thank you again for your time and help,
Kindest Regards,
Kaj

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Identical settings but Scanner values different to Chart

Postby Henry MultiСharts » 26 Apr 2013

Hello Kaj,

The amount of bars the study requires for calculation depends on the code. Depending on the script logic the calculation result can be different or remain the same when data series length is changed.


Return to “MultiCharts”