Watchlist of Percentage Move

I would like to show the percentage move for yesterday as a percentage in a watchlist excel-like column?

Is this possible?

@tedpenner yes it is possible. Can you elaborate and give a bit more detail about what you want to measure and what you want to see?

I'm trying to find the actual calculation we used but here is the value represented as a percentage on the chart in MultiCharts.

Leverage_with_Defined_Risk

Here is the code for it originally for the chart version.
In the case above, I would like to see 0.29% in one column and 48.82% in another column

using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace PowerLanguage.Indicator
{
	public class TPJPPercent3 : IndicatorObject
    {
		private int m_font_size;
        private FontStyle m_font_style;
        private Font m_my_font;
		private double? pct1, pct2;
		private DateTime leftTime, rightTime;
		
        public TPJPPercent3(object ctx) : base(ctx)
		{
            daysAgo = 1;
			epsilonPrice = 0.00001;
			
			m_font_size = 32;
            //m_font_style = FontStyle.Bold;
            m_my_font = new Font("Courier New", m_font_size, FontStyle.Bold);
        }

		[Input]
		public int daysAgo { get; set; }
		
		[Input]
		public double epsilonPrice { get; set; }
		
		private Color color1 = Color.LimeGreen;
		[Input]
		public Color Color1 {
			get{return color1;}
			set{this.color1 = value;}
		}
		
		private Color color2 = Color.Orange;
		[Input]
		public Color Color2 {
			get{return color2;}
			set{this.color2 = value;}
		}
			

        protected override void Create(){
			
        }
		protected override void Destroy()
		{
			
		}

        protected override void StartCalc(){
         
        }
		protected override void StopCalc()
        {
            
        }
		
		
		
        protected override void CalcBar(){
			if (!Bars.LastBarOnChart && !BarsOfData(2).LastBarOnChart) return;
			
			//determine bars to check
			DateTime now = Bars.Time[0];
			DateTime checkDate = (now - TimeSpan.FromDays((double)daysAgo)).Date;
			//Output.WriteLine("CheckDate: "+checkDate.ToString());
			int leftBar = 0, rightBar = 0;
			for (int i = 0; i < Bars.CurrentBar; ++i){
				if (Bars.Time[i] < checkDate){
					leftBar = i - 1;
					break;
				}
			}
			if (leftBar < 0) leftBar = 0;
			//
			checkDate += TimeSpan.FromDays(1.0);
			//Output.WriteLine("CheckDate+1: "+checkDate.ToString());
			rightBar = 0;
			for (int i = leftBar; i >= 0; --i){				
				if (Bars.Time[i] >= checkDate){
					//Output.WriteLine("Found: "+Bars.Time[i].ToString() + " > " + checkDate.ToString());
					rightBar = i + 1;
					if (rightBar > leftBar) rightBar = leftBar;
					break;
				}
			}
			leftTime = Bars.Time[leftBar];
			rightTime = Bars.Time[rightBar];
			//Output.WriteLine(leftTime.ToString() + " - " + rightTime.ToString());
			int len = leftBar - rightBar + 1;
			double lo1 = PublicFunctions.Lowest(Bars.Low, len, rightBar);
			double hi1 = PublicFunctions.Highest(Bars.High, len, rightBar);
			double rng1 = hi1 - lo1;
			pct1 = lo1 < epsilonPrice ? null : (double?)(100.0 * rng1 / lo1);
			
			double lo2 = PublicFunctions.Lowest(BarsOfData(2).Low, len, rightBar);
			double hi2 = PublicFunctions.Highest(BarsOfData(2).High, len, rightBar);
			double rng2 = hi2 - lo2;
			pct2 = lo2 < epsilonPrice ? null : (double?)(100.0 * rng2 / lo2);
			
			
			//double? diff = pct1 == null || pct2 == null ? null : (double?)(pct1 - pct2);
            
            //if (pct1 != null) Plot1.Set(0, (double)pct1);
            //if (pct2 != null) Plot2.Set(0, (double)pct2);
            //if (pct1 != null && pct2 != null) Plot3.Set(0, (double)diff);
			
			DrawValues(hi1, lo1, hi2, lo2);
        }
		
		private void DrawValues(double hi1, double lo1, double hi2, double lo2)
		{			
			DateTime t1 = Bars.Time[0];
			DateTime t2 = BarsOfData(2).Time[0];
			//Output.WriteLine(t2.ToString());
			DateTime t = t1;
			if (t2 > t1) t = t2;
			t += TimeSpan.FromMinutes(5);
			
			const int rngBars = 40;
			if (pct1 != null){
				//double rhh = PublicFunctions.Highest(Bars.High, rngBars);
				//double rll = PublicFunctions.Lowest(Bars.Low, rngBars);
				double m = 0.5 * (hi1+lo1);
				ITextObject txt1 = DrwText.Create(new ChartPoint(t, m), ((double)pct1).ToString("    0.00")+"%", 1);
				txt1.Size = m_font_size;
				txt1.Color = color1;
				txt1.HStyle = ETextStyleH.Right;
				txt1.VStyle = ETextStyleV.Center;
				txt1.FontName = m_my_font.Name;
				
				DrawBox(leftTime, hi1, rightTime, lo1, 1, color1);
				
				//Output.WriteLine("Data 1: " + hh.ToString() + ", " + ll.ToString() + ", " + leftTime.ToString() + ", " + rightTime.ToString());
			}
			
			if (pct2 != null){
				//double hh = PublicFunctions.Highest(BarsOfData(2).High, rngBars);
				//double ll = PublicFunctions.Lowest(BarsOfData(2).Low, rngBars);
				double m = 0.5 * (hi2 + lo2);
				ITextObject txt2 = DrwText.Create(new ChartPoint(t, m), ((double)pct2).ToString("    0.00")+"%", 2);
				txt2.Size = m_font_size;
				txt2.Color = color2;
				txt2.HStyle = ETextStyleH.Right;
				txt2.VStyle = ETextStyleV.Center;
				txt2.FontName = m_my_font.Name;
				
				DrawBox(leftTime, hi2, rightTime, lo2, 2, color2);
				
				//Output.WriteLine("Data 2: " + hh.ToString() + ", " + ll.ToString() + ", " + leftTime.ToString() + ", " + rightTime.ToString());
			}
		}
		
		private void DrawBox(DateTime left, double top, DateTime right, double bottom, int series, Color color)
	    {
	        ITrendLineObject leftSideLine, rightSideLine, highLine, lowLine;
			
	        // Draw the vertical trend lines
	        leftSideLine = DrwTrendLine.Create(
	            new ChartPoint(left, top),
	            new ChartPoint(left, bottom),
				series
	            );

	        rightSideLine = DrwTrendLine.Create(
	            new ChartPoint(right, top),
	            new ChartPoint(right, bottom),
				series
	            );

	        // Draw the horizontal trend lines
	        highLine = DrwTrendLine.Create(
	            new ChartPoint(left, top),
	            new ChartPoint(right, top),
				series
	            );

	        lowLine = DrwTrendLine.Create(
	            new ChartPoint(left, bottom),
	            new ChartPoint(right, bottom),
				series
	            );

	        // Adjust the trend lines
	        leftSideLine.Size  = 1;
	        rightSideLine.Size = 1;
	        highLine.Size      = 1;
	        lowLine.Size       = 1;

	        leftSideLine.Style  = ETLStyle.ToolDotted;
	        rightSideLine.Style = ETLStyle.ToolDotted;
	        highLine.Style      = ETLStyle.ToolDotted;
	        lowLine.Style       = ETLStyle.ToolDotted;

	        leftSideLine.Color  = color;
	        rightSideLine.Color = color;
	        highLine.Color      = color;
	        lowLine.Color       = color;
	    }
		
		
		

        [Input]
        public string Font{
            get { return m_my_font.FontFamily.Name; }
            set { m_my_font = new Font(value, m_font_size, FontStyle.Bold); }
        }

        [Input]
        public int FontSize {
            get { return m_font_size; }
            set {
                m_font_size = value;
                Font = Font;
            }
        }

       

    }
}

You are not clear about what percentage but here is example of exploration at last bar and output of Daily percent range with adjustable period.

How to apply?
Read here on how to run exploration
https://www.amibroker.com/guide/h_exploration.html
https://www.amibroker.com/kb/category/analysis/explorations
https://www.amibroker.com/kb/2014/10/03/how-to-setup-perodic-scans/

new analysis window
https://www.amibroker.com/guide/h_newanalysis.html
old analysis window
https://www.amibroker.com/guide/w_analysis.html

if ( Status( "actionex" ) == actionExplore )
{    
    /// @link http://forum.amibroker.com/t/watchlist-of-percentage-move/2919/3
    period = 1;
    
    tmfrm = inDaily;
	TimeFrameSet( tmfrm );
		myroc = ROC(C, period);// percent rate of change.
		tmfrm_int = Interval(2);
	TimeFrameRestore();
	myroc = TimeFrameExpand( myroc, tmfrm, expandLast );    
    
    format = 1.2;
    Colfont = colorLightGrey;
    Colcell = colorDarkGrey;    

    SetOption( "NoDefaultColumns", True );
    //SetSortColumns( 1 );
    
    Filter = Status( "lastbarinrange" );

    AddTextColumn( Name(), "Ticker", 1.0, Colfont, Colcell, 70 );
    AddColumn( DateTime(), "Date/Time", formatDateTime, Colfont, Colcell, 120 );
    AddTextColumn(Interval(2), "Selected Interval", 1, Colfont, Colcell );
    AddColumn( myroc, tmfrm_int + StrFormat(" ROC(%g) (%%)", period), format, IIf( myroc > 0, colorGreen, colorRed), Colcell );

    AddSummaryRows( 63, format );  
}

1

3 Likes

Ok, that’s a good plan.

Can you walk me through how to implement that and get it running on my machine?

@tedpenner OK, this one time you can be spoon fed. Run an EXPLORE on your chosen Watch List.
image

image

Click "Explore"

1 Like

Your file is already applied in Analysis. Can't you see it in analysis formula address bar?

1

2 Likes

I managed to save a watchlist so that’s a start. Still not able to implement the code above.

I get a crash when I click explore or scan either one, but at least I now have that page populating some symbols.

How do I fix the crashing?

Hi @fxshrat,

Is this possible to add this exploration table to active chart window.

Thanks and regards,

You may create table via Gfx functionality.

But why would you want to go through such hassle?
Instead simply apply Window - Tile horizontally or Window - Tile vertically. Then you have chart and analysis visible at same time.

Also you can detach analysis (or any other tab) from main UI by right clicking a tab and choosing "floating" and placing it anywhere you like to.

17

12

2 Likes

Thanks @fxshrat for your guidance. My approach was wrong.

Thanks and regards.