MA Trend
Hey PT3 Team,
I'm just recently started to code in c# and this may be a stupid question.
This code is just to show the change in two moving average and color the line in 3 different colors:
Green: UP
Red: Down
Neutral: Grey
The isn't fully functional, because is kind of drawing the 3 different colors in a funny way. See the picture and code below.
Thanks.
Lars
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Drawing; using PTLRuntime.NETScript; using PTLRuntime.NETScript.Indicators; namespace TrendLine { /// <summary> /// Test /// /// </summary> public class TrendLine : NETIndicator { public TrendLine() : base() { #region Initialization base.Author = ""; base.Comments = ""; base.Company = ""; base.Copyrights = ""; base.DateOfCreation = "24.03.2016"; base.ExpirationDate = 0; base.Version = ""; base.Password = ""; base.ProjectName = "TrendLine"; #endregion base.SetIndicatorLine("Bull", Color.LawnGreen, 3, LineStyle.DotChart); base.SetIndicatorLine("Neutral", Color.Red, 3, LineStyle.DotChart); base.SetIndicatorLine("Bear", Color.LightGray, 3, LineStyle.DotChart); base.SeparateWindow = false; } // Make input parameter with numbers [InputParameter("Fast", 0, 1, 9999)] public int FastPeriod = 20; [InputParameter("Slow", 0, 1, 9999)] public int SlowPeriod = 30; // Choose which type of moving average to use [InputParameter("Type of Moving Average", 1, new object[] { "Simple", MAMode.SMA, "Exponential", MAMode.EMA, "Modified", MAMode.SMMA, "Linear Weighted", MAMode.LWMA} )] public MAMode MAType = MAMode.LWMA; // Choose which price type to use [InputParameter("Sources price", 2, new object[] { "Close", PriceType.Close, "Open", PriceType.Open, "High", PriceType.High, "Low", PriceType.Low, "Typical", PriceType.Typical, "Medium", PriceType.Medium, "Weighted", PriceType.Weighted })] public PriceType PriceTypes = PriceType.Close; private Indicator Fast; private Indicator Slow; /// <summary> /// This function will be called after creating /// </summary> public override void Init() { } /// <summary> /// Entry point. This function is called when new quote comes /// </summary> public override void OnQuote() { Fast = Indicators.iMA(CurrentData, FastPeriod, MAType, 0, PriceTypes); Slow = Indicators.iMA(CurrentData, SlowPeriod, MAType, 0, PriceTypes); double currFast = Fast.GetValue(); double currSlow = Slow.GetValue(); double lastFast = Fast.GetValue(0, 1); double lastSlow = Slow.GetValue(0, 1); if (currSlow > lastSlow && currFast > lastFast) { // Bull SetValue(0, Slow.GetValue()); } else if (currSlow < lastSlow && currFast < lastFast) { // Bear SetValue(1, Slow.GetValue()); } else { // Neutral SetValue(2, Slow.GetValue()); } } /// <summary> /// This function will be called before removing /// </summary> public override void Complete() { } } }
No replies yet
Join PTMC community to post your replies on forum