[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name = "Multiplicador", GroupName = "Parámetros", Order = 0)]
public int Multiplicador { get; set; }
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
AnchorLineStroke = new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1f, 50);
Description = @"Risk-Reward MagnetoCodeTraders";
Name = "McT RiskReward";
PriceLevelOpacity = 5;
StartAnchor = new ChartAnchor { IsEditing = true, DrawingTool = this };
ExtensionAnchor = new ChartAnchor { IsEditing = true, DrawingTool = this };
EndAnchor = new ChartAnchor { IsEditing = true, DrawingTool = this };
StartAnchor.DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchorStart;
EndAnchor.DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchorEnd;
ExtensionAnchor.DisplayName = Custom.Resource.NinjaScriptDrawingToolAnchorExtension;
Activeinfo = true;
Multiplicador = 1; // var
}
else if (State == State.DataLoaded)
{
// Intentar obtener la cantidad de contratos de ChartTrader al cargar los datos
try
{
var chartTrader = Window.GetChartTrader(ChartControl.OwnerChartWindow);
if (chartTrader != null)
{
Multiplicador = chartTrader.Quantity; // Inicializar Multiplicador con la cantidad de contratos
}
}
catch
{
Multiplicador = 1; // Mantener el valor predeterminado
}
}
I am making my own risk reward, but I want to bring the contracts that the user has in their "chart trader"
private string GetPriceString(double price, PriceLevel priceLevel, ChartPanel chartPanel)
{
// note, dont use MasterInstrument.FormatPrice() as it will round value to ticksize which we do not want
string priceStr = price.ToString(Core.Globals.GetTickFormatString(AttachedTo.Instrument.MasterInstrument.TickSize));
double pct = priceLevel.Value / 100;
string priceString;
double yValueEntry = AttachedTo.Instrument.MasterInstrument.RoundToTickSize(StartAnchor.Price);
double yValueEnd = AttachedTo.Instrument.MasterInstrument.RoundToTickSize(EndAnchor.Price);
double tickSize = AttachedTo.Instrument.MasterInstrument.TickSize;
double pointValue = AttachedTo.Instrument.MasterInstrument.PointValue;
var priceAtLevel = AttachedTo.Instrument.MasterInstrument.FormatPrice(price );
switch (DisplayUnit)
{
case ValueUnit.Currency:
priceString = StartAnchor.Price > EndAnchor.Price ?
Core.Globals.FormatCurrency(AttachedTo.Instrument.MasterInstrument.RoundToTickSize(StartAnchor.Price - EndAnchor.Price) / tickSize * (tickSize * pointValue) * pct):
Core.Globals.FormatCurrency(AttachedTo.Instrument.MasterInstrument.RoundToTickSize(EndAnchor.Price - StartAnchor.Price) / tickSize * (tickSize * pointValue) * pct);
break;
case ValueUnit.Ticks:
priceString =
(AttachedTo.Instrument.MasterInstrument.RoundToTickSize(pct*Math.Abs((StartAnchor.Price - EndAnchor.Price) / tickSize))).ToString("F0")+ " "+ValueUnit.Ticks.ToString();
break;
case ValueUnit.Pips:
priceString =
(AttachedTo.Instrument.MasterInstrument.RoundToTickSize(pct*Math.Abs(StartAnchor.Price - EndAnchor.Price))).ToString("F0") + " "+ValueUnit.Pips.ToString();
break;
default:
priceString = StartAnchor.Price > EndAnchor.Price ?
Core.Globals.FormatCurrency(AttachedTo.Instrument.MasterInstrument.RoundToTickSize(StartAnchor.Price - EndAnchor.Price) / tickSize * (tickSize * pointValue) * pct * Multiplicador]):
Core.Globals.FormatCurrency(AttachedTo.Instrument.MasterInstrument.RoundToTickSize(EndAnchor.Price - StartAnchor.Price) / tickSize * (tickSize * pointValue) * pct * Multiplicador);
break;
}
default:
priceString = StartAnchor.Price > EndAnchor.Price ?
Core.Globals.FormatCurrency(AttachedTo.Instrument. MasterInstrument.RoundToTickSize(StartAnchor.Price - EndAnchor.Price) / tickSize * (tickSize * pointValue) * pct * Multiplicador]):
Core.Globals.FormatCurrency(AttachedTo.Instrument. MasterInstrument.RoundToTickSize(EndAnchor.Price - StartAnchor.Price) / tickSize * (tickSize * pointValue) * pct * Multiplicador);
break;
}

Comment