Firstly, I am very grateful for all your time, efforts and assistance.
@NinjaTrader_Bertrand, below is my code:
public class KayYLinePrice : Indicator
{
#region Variables
// Wizard generated variables
private double lossPerUnit6 = 0.100; // Default setting for LossPerUnit6
private double lossPerTrade6 = 10.00; // Default setting for LossPerTrade6
// User defined variables (add any user defined variables below)
private double yvalue = 0;
private Font textFont = new Font("Arial", 10, FontStyle.Regular);
private Color txtColor;
private int barsBack = 0; //default. Make this a property, and you can change it from the GUI
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Overlay = false;
}
protected override void OnStartUp()
{
foreach (IDrawObject draw in DrawObjects)
{
if (draw.DrawType == DrawType.HorizontalLine && draw.UserDrawn)
{
IHorizontalLine hLine = (IHorizontalLine) draw;
if (hLine.Tag == "0")
{
yvalue = Math.Round(hLine.Y, 2); // This is Price value
}
}
}
double StopLossP, StopLossPATR, StopLossP2, StopLossPATR2, SharesMxS, SharesMxS2, SharesATR, SharesATR2, SharesPC, SharesPC2;
StopLossP = yvalue - LossPerUnit6;
StopLossPATR = Math.Round(yvalue - ATR(14)[0],2);
SharesATR = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossPATR)),2);
SharesPC = Math.Round(Math.Abs(LossPerTrade6/(yvalue - Low[barsBack])),2);
SharesMxS = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossP)),2);
StopLossP2 = yvalue + LossPerUnit6;
StopLossPATR2 = Math.Round(yvalue + ATR(14)[0],2);
SharesATR2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossPATR2)),2);
SharesPC2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - High[barsBack])),2);
SharesMxS2 = Math.Round(Math.Abs(LossPerTrade6/(yvalue - StopLossP2)),2);
DrawTextFixed("Stop Values","EP " + yvalue + " ATR " + Math.Round(ATR(14)[0],2) + " BUY(MS/AS/PS) " + StopLossP + " [" + SharesMxS + "] / " + StopLossPATR + " [" + SharesATR + "] / " + Low[barsBack].ToString("0.00") + " [" + SharesPC + "] " + " SELL(MS/AS/PS) " + StopLossP2 + " [" + SharesMxS2 + "] / " + StopLossPATR2 + " [" + SharesATR2 + "] / " + High[barsBack].ToString("0.00") + " [" + SharesPC2 + "]" , TextPosition.BottomLeft, Color.White, textFont, Color.Transparent, Color.Transparent, 0);
Print(Low[barsBack]);
Print(High[barsBack]);
Print(SharesPC);
Print(SharesPC2);
Print(yvalue);
}
protected override void OnBarUpdate()
{
if (CurrentBar < barsBack) return;
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public double LossPerUnit6
{
get { return lossPerUnit6; }
set { lossPerUnit6 = Math.Max(0.001, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double LossPerTrade6
{
get { return lossPerTrade6; }
set { lossPerTrade6 = Math.Max(0.001, value); }
}
[Description("")]
[GridCategory("Parameters")]
[Gui.Design.DisplayName("Bar to reference")]
public int BarsBack
{
get { return barsBack; }
set { barsBack = Math.Max(0, value); }
}
#endregion
}
}
Many thanks
Dan

Comment