Output in Code Editor Watch window and Indicator plots are different

Hi - I while developing code in debug mode, I watch value for array ALPHA_CUMM which as per Watch window is -0.681726.. on 25-04-22, And if I plot this array as in Indicator on Chart then I see value 1244.25 for 25-04-22. I am completely confused why is this happening and how to fix it?

Yes I am ensuring that the Symbol in Watch window and Chart window are same which is ANGELONE.

image

image


_SECTION_BEGIN("AlphaBeta");
//Alpha, Beta, R2 Formula
Ticker = ParamStr("MKT Ticker", "NIFTY 50"); 
MKT = Foreign(Ticker,"C",1);
//AP=Param("Alpha Period",200,10,300,5);
prd = 30;

/*
AP = IIf( ABS(C - LLV(C,prd)) >= ABS(C - HHV(C,prd)), LLVBars(C,prd), HHVBars(C,prd) );

staticAP = LLVBars(C,prd);
*/

/*
l_p = Param( "Long", 50, 1, 100, 1 );
m_p = Param( "Mid", 30, 1, 100, 1 );
s_p = Param( "Short", 15, 1, 100, 1 );
vs_p = Param( "Very Short", 3, 1, 100, 1 );
*/

l_p = 50;
m_p = 30;
s_p = 10;
vs_p = 2;


//AP=Optimize("Alpha Period",200,100,300,5);

Beta_l_p=((l_p * Sum(ROC( C,1) * ROC(MKT,1),l_p)) - (Sum(ROC(C,1),l_p) * Sum(ROC( MKT,1),l_p)))
    / ((l_p * Sum((ROC(MKT,1)^2 ),l_p)) - (Sum(ROC(MKT,1 ),l_p)^2 ));
Alpha_l_p=Nz(l_p*(Sum(ROC( C,1) ,l_p) - (Nz(Beta_l_p)) * Sum( ROC(MKT,1),l_p )) / l_p);


Beta_m_p=((m_p * Sum(ROC( C,1) * ROC(MKT,1),m_p)) - (Sum(ROC(C,1),m_p) * Sum(ROC( MKT,1),m_p)))
    / ((m_p * Sum((ROC(MKT,1)^2 ),m_p)) - (Sum(ROC(MKT,1 ),m_p)^2 ));
Alpha_m_p=Nz(m_p*(Sum(ROC( C,1) ,m_p) - (Nz(Beta_m_p)) * Sum( ROC(MKT,1),m_p )) / m_p);


Beta_s_p=((s_p * Sum(ROC( C,1) * ROC(MKT,1),s_p)) - (Sum(ROC(C,1),s_p) * Sum(ROC( MKT,1),s_p)))
    / ((s_p * Sum((ROC(MKT,1)^2 ),s_p)) - (Sum(ROC(MKT,1 ),s_p)^2 ));
Alpha_s_p=Nz(s_p*(Sum(ROC( C,1) ,s_p) - (Nz(Beta_s_p)) * Sum( ROC(MKT,1),s_p )) / s_p);


Beta_vs_p=((vs_p * Sum(ROC( C,1) * ROC(MKT,1),vs_p)) - (Sum(ROC(C,1),vs_p) * Sum(ROC( MKT,1),vs_p)))
    / ((vs_p * Sum((ROC(MKT,1)^2 ),vs_p)) - (Sum(ROC(MKT,1 ),vs_p)^2 ));
Alpha_vs_p=Nz(vs_p*(Sum(ROC( C,1) ,vs_p) - (Nz(Beta_vs_p)) * Sum( ROC(MKT,1),vs_p )) / vs_p);


Alpha_cumm = (Alpha_l_p*.2) + (Alpha_m_p*.2) + (Alpha_m_p*.3) + (Alpha_vs_p*.3);

symname = Name();


//R2=Correlation(MKT,C,AP)^2;
//Chart Settings
dynamic_color = IIf( Alpha_cumm > 0, colorYellow, colorBrightGreen );
Plot(Alpha_cumm, "Alpha_cumm", dynamic_color,    styleHistogram | styleThick );
    
    
//Lslope = LinRegSlope(Alpha,30) > 0;
    
    //Filter = Lslope ;
    //AddColumn( Alpha , "Alpha " );
   // AddColumn( Lslope , "Slope " );
	//AddColumn( R2 , "Correlation " );
    

	        
_SECTION_END();

You should check the BARCOUNT. Typically the debugger uses LESS bars than your chart does, so any "cumulative" calculation is going to be different, if less bars are cumulated.

The other reason could be that you are using different BAR INTERVAL in debugger vs chart.

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

I have checked the Barcount taken in Watch window (less than 200 Bars) coincide with the Bar I am observing on Chart. Also the Dates in Chart v/s Watch Window Match where I observed the anomaly.

On Chart my Inerval is DAILY while I have not set any Interval in Exploration code and I have Daily EOD data in my DB.

Also I have run an exploration on ALPHA_CUMM array and even more surprised that why for Date 25-02-22 the values of ALPHA_CUMM is different in Watch Window v/s Exploration v/s Chart.

Appreciate any help please.

I don't see any _TRACE call in your formula. That is a must to know what actual number of bars is.

To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?

Quite often people assume things. Don't assume. Use _TRACE as explained in the article. The number of bars is DYNAMIC

and

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.