Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

chart trader access

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    chart trader access

    I am making my own risk reward, but I want to bring the contracts that the user has in their "chart trader"



    Code:
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name = "Multiplicador", GroupName = "Parámetros", Order = 0)]
    public int Multiplicador { get; set; }​
    Code:
    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
                    
                }​
    Code:
     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"

    Code:
    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;
    }​​

    #2
    Hello leojimenezp,

    To do this in a drawing tool you would need to do that from OnRender. You would need to set a class level variable to the value that the quantity selector has.



    Code:
    private int quantity = 1; 
    public override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {​
    
       chartControl.Dispatcher.InvokeAsyn c((Action)(() =>
       {
          NinjaTrader.Gui.Tools.QuantityUpDown quantitySelector = (Window.GetWindow(chartControl.Parent).FindFirst(" ChartTraderControlQuantitySelector") as NinjaTrader.Gui.Tools.QuantityUpDown);
    
           quantity = quantitySelector.Value;
       }));
    }

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X