Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Pass Event with parameters from indicator to other indicator

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

    Pass Event with parameters from indicator to other indicator

    Hello,

    I am using custom 3rd party tool for pure order management that doesn't work well on tick replay data. I want to separate indicator logic - and basically pass information when signal occurs to another indicator which in turn will be called by that 3rd party order management tool on each tick.

    I am able to create add-on with static event
    namespace NinjaTrader.NinjaScript.AddOns
    {
    public static class EventClass
    {
    public static event EventHandler PropChanged;
    private static double TestDoubleValue;

    public static double TestDoubleEvent
    {
    get{ return TestDoubleValue; }
    set{
    TestDoubleValue = value;
    if(PropChanged != null) {PropChanged(value, EventArgs.Empty);
    }
    }
    }
    }
    }​

    And I can pass and receive "Double" values:

    (here is indicator below)
    public class testSMA : Indicator
    {
    private double priorSum;
    private double sum;
    private double EventValue;
    bool fired = false;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "TestSMA";
    Name = "TestSMA";
    IsOverlay = true;
    IsSuspendedWhileInactive = true;
    Period = 14;

    AddPlot(Brushes.Goldenrod, "SMAPlot");
    }
    else if (State == State.Configure)
    {
    priorSum = 0;
    sum = 0;
    Print("subscribe to event");
    AddOns.EventClass.PropChanged += OnPropChanged;
    }
    else if (State == State.Terminated)
    {
    if (ChartControl == null) return;
    Print("Unsubscribe from event");
    AddOns.EventClass.PropChanged -= OnPropChanged;
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsArray[0].BarsType.IsRemoveLastBarSupported)
    {
    if (CurrentBar == 0)
    Value[0] = Input[0];
    else
    {
    double last = Value[1] * Math.Min(CurrentBar, Period);

    if (CurrentBar >= Period)
    Value[0] = (last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period);
    else
    Value[0] = ((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
    }
    }
    else
    {
    if (IsFirstTickOfBar)
    priorSum = sum;

    sum = priorSum + Input[0] - (CurrentBar >= Period ? Input[Period] : 0);
    Value[0] = sum / (CurrentBar < Period ? CurrentBar + 1 : Period);
    }
    if (State == State.Realtime)
    {
    if (!fired)
    {
    AddOns.EventClass.TestDoubleEvent = 122;
    fired = true;
    }
    }
    }

    void OnPropChanged(object sender, EventArgs e)
    {
    EventValue = (double)sender;
    Print("Event fired from within chart indicator. Prop changed to " + EventValue.ToString());
    }

    region Properties
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
    public int Period
    { get; set; }
    #endregion
    }
    }​


    Is it possible to pass class structure through event which includes side to take (long/short), limit price to place order, potential stop and target (sending class object through event)?

    Also, what would be best practice if I want to pass data across multiple accounts/instruments/strategies? Will I have to code "Shared Event" for each account/instrument/strategy combination or is there a better way?

    Thanks

    #2
    Hello, thanks for writing in. You are asking if this is possible, It likely is possible to do in some way but the methods and techniques are more in the realm of general C# programming, so the question does fall out of the scope of support we are able to provide for this. Any shared code/events also go outside of the scope of support we can provide, so you will need to do your own research on this subject, or possibly another forum member can help out.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jpapa, Today, 07:22 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by kevinenergy, 02-17-2023, 12:42 PM
    116 responses
    2,757 views
    1 like
    Last Post kevinenergy  
    Started by franatas, 12-04-2023, 03:43 AM
    7 responses
    106 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Jltarrau, Today, 05:57 AM
    3 responses
    8 views
    0 likes
    Last Post Jltarrau  
    Started by f.saeidi, Today, 05:56 AM
    2 responses
    8 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X