Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

suggestion re Trailing Stops?

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

    suggestion re Trailing Stops?

    Hello. I'm working in unmanaged framework where I have created a list of stops, and then run a for each loop to update the stops according to trail frequency, etc. This works fine.

    However, I'd like to enhance this such that I can update the frequency/ size of each stop as a function of the profit or loss in the associated trade, so as such I need to associate an original entry execution level with each stop in the list.

    Theoretically, I could create another list that has an execution associated with each stop, so there would be one to one correspondence, but my coding ability is limited so I'm not clear on non-cumbersome way to reference the Nth item in a list. Should I instead use an array for something like this? Are there any examples you could point me to?

    Thanks

    #2
    Hello stewarco,

    Thank you for the question.

    Which overload set for the unmanaged orders are you using, are you providing a SignalName? If so, likely you could use a dictionary with the Key being the signal name and the Value is the Entry. That would allow you to skip using indexes or for loops and just lookup a specific entry by name.

    In the OnOrderUpdate or OnExecution where you gather the order objects, you could check the dictionary to see if that key is taken or not, and assign the order to the list. Later where you check the stops, you could reference the entry by the name for the type of stop to access the order.

    Perhaps something like the following:
    Code:
    private Dictionary<string, Order> entryOrders = new Dictionary<string, Order>();
    private Order myOrder;
    
    protected override void OnOrderUpdate()
    {
            //use .Add method to add a new key
    	entryOrders.Add("signalName", myOrder);
            // or re assign by key
    	entryOrders["signalName"] = myOrder;
    
    	if (entryOrders.ContainsKey("signalName"))
    	{
    		Print(entryOrders["signalName"].AverageFillPrice);
    	}
    This, of course, wouldn't work as pictured in without submitting orders or anything. This is more of a simple demonstration of the logic could potentially use and to demonstrate using a dictionary and accessing the objects stored in it. You would need to modify the above syntax to fit within your script however it needs to be used.

    You could also do some research on C# classes if you wanted to maintain 1 list that contains both entry and targets and associates them into a single object, a class and list would be good for that use. to learn more on this, you could look at the sample here which uses a List and custom object to store level 2 data: https://ninjatrader.com/support/foru...ead.php?t=3478

    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 07-26-2018, 07:41 AM.

    Comment


      #3
      thanks

      thanks jesse i'll see if I can familiarize myself with using a dictionary... hadn't heard of that before but sounds promising

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      83 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      150 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      79 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      52 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      59 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X