Quote Editor - Entering negative values

Hello,
I am taking daily New High - New Low data from BarChart.com and calculating in excel a rolling 5 day summation to have a "Weekly" NHNL ticker. Yesterday I calculated a historical data and could import it into AmiBrolker as a ticker using the Import Wizard. This weekly NHNL has negative numbers which I could import with the Import Wizard.

Today I wanted to add the new days value via the Quote Editor but it seems like the Quote Editor does not accept negative numbers. Is that correct or is there some setting to allow negative numbers to be entered in the Quote Editor.

Cheers

PS: Ideally I would like AmiBroker to calculate the rolling 5-day weekly sum, but I have not figured out the code how to do it so I still need to calculate in excel and enter the values by hand.

Quote editor does NOT allow to enter negative prices for good reason. Negative prices generally are not welcome because attempting to calculate many indicators and/or backtest may lead to bizarre results if prices swing between negative and positive and also negative prices exclude log scale (as log is NOT defined for negative arguments).
If you want to import NON-PRICE data that is negative, you can do this using $ALLOWNEG 1 flag of ASCII import wizard.

@maccra Another method to consider is to load both New High and New Low data separately, and then you have the ability to create various indicators including a simple NH-NL calculation in an afl file.

An example (but use your data which will have different symbols)

SP500nh52 	= Foreign( "#SPX52WHI", "C" );
SP500nl52 	= Foreign( "#SPX52WLO", "C" );

HiLoDiff	= SP500nh52 - SP500nl52;

FiveDayDiff	= Sum(HiLoDiff, 5);

Or you can arrive at the same indicator in a different way

FiveDayNH	= Sum(SP500nh52, 5);
FiveDayNL	= Sum(SP500nl52, 5);
SecondWay	= FiveDayNH - FiveDayNL;

1 Like

@Tomasz Thank you for the clarification why it is not a good idea to enter negative prices. Much appreciated

@portfoliobuilder
Yes, I have been trying to calculate the Weekly NHNL . I have used the following code, which is similar to yours, but it does not chart properly.

![image|603x73](upload://jSc6tBKZ9oTHCl63URHMB2JI75A.png) // NHNL Data from BarChart.com
US12M_NHNL = Foreign("&NHNL_12M_NH","Close")-Foreign("&NHNL_12M_NL","Close");
NHNLWeekly = Sum(US12M_NHNL,5);
Plot(NHNLWeekly,"NHNL_Weekly",colorRed,styleline);

image The last 5 days NHNL (New Highs - New Lows) from Barchart.com are as following:
16.03; 1-2678 = -2677
17.03; 14-1767 = -1753
18.03; 17-2414 = -2397
19.03; 14-1134 = -1120
20..03; 4-507 = -503

So the Weekly (5 day rolling sum) value is -2677-1753-2397-1120-503 = -8450

On the Daily chart it is correct but on the Weekly chart I can not get it to plot correctly . The Weekly chart shows a value of -3854 and I have no idea where that value comes from, see charts below.

2020-03-23_15-29-02

2020-03-23_15-27-54

image I tried with your formula (many thanks for writing that) and I get the same chart results as above.

After reading about AddtoComposites and trying a few things I finally found a solution with the AddtoComposites using following formula, Just need to run scan to calculate the result.

![image|603x162](upload://w2Ck56ZVFEoeDgfvpvBxLhNLmcF.png) // NHNL Data from BarChart.com
US12M_NHNL = Foreign("&NHNL_12M_NH","Close")-Foreign("&NHNL_12M_NL","Close");
NHNLWeekly = Sum(US12M_NHNL,5);

AddToComposite(NHNLWeekly,"&NHNL_Weekly","X");

Plot(Foreign("&NHNL_Weekly","C",1),"US_Weekly_NHNL",colorRed,styleline);
PlotGrid(0,colorBlack);
PlotGrid(-4000,colorAqua);

2020-03-23_15-30-18

Thank you all for the help.

@maccra,

On the Daily chart it is correct but on the Weekly chart I can not get it to plot correctly . The Weekly chart shows a value of -3854 and I have no idea where that value comes from, see charts below.

On a weekly chart Sum() array function calculates on weekly array not on daily array so in your formula the last 5 weekly closes are used.

After reading about AddtoComposites and trying a few things I finally found a solution with the AddtoComposites using following formula, Just need to run scan to calculate the result.

In addition to running ATC via Scan, you can also run it in indicator pane (and on specific interval only and just once if there is new quote).

Below code executes ATC in indicator in addition and executes ATC creation only in daily interval.

US12M_NHNL = Foreign("&NHNL_12M_NH","Close")-Foreign("&NHNL_12M_NL","Close");

if ( Interval() == inDaily ) { // execute in daily interval only
	NHNLWeekly = Sum(US12M_NHNL,5);

	/// @link https://www.amibroker.com/kb/2015/11/29/how-to-execute-part-of-the-formula-only-when-new-bar-is-added/
	/// @link https://forum.amibroker.com/t/quote-editor-entering-negative-values/17833/5
	// read last bar date/time
	lastBartime = LastValue( DateTime() );

	// we use per-symbol variable
	// you may consider to add GetChartID() key if you want
	// to use the formula in multiple charts shown at the same time
	varName = Name() + "_lastdt";

	// read recorded date/time from last execution
	recordedTimestamp = Nz( StaticVarGet( varName ) );

	// code runs conditionally only when new bar is detected
	scan = Status("action" ) == actionScan;
	trigger = lastBarTime != recordedTimestamp OR scan;
	if (trigger)	{
		// record new bar datetime
		StaticVarSet( varName, lastBartime );
		//	
		// Allow running ATC in indicator pane also
		AddToComposite(NHNLWeekly,"~NHNL_Weekly","X", atcFlagDefaults | atcFlagEnableInIndicator );
		//
		Say("ATC created");
	}
} else // if in weekly
	NHNLWeekly = Foreign("~NHNL_Weekly","C",1);

Plot(NHNLWeekly ,"US_Weekly_NHNL",colorRed,styleline);
PlotGrid(0,colorBlack);
PlotGrid(-4000,colorAqua);

@fxshrat, Thanks for the code and the explanantion regarding my Weekly numbers. I compared with my excel calculations and see where the numbers are coming from. One thing I am not sure about with code. I just updated my New High and New low values from Barchart.com and also S&P500, but the code did not run when a new bar was detected, I had to run the scan manually. Should it update on a new daily or weekly bar (the code looks to me it should update on a new daily bar though)?
Cheers