Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to handle trades individually?

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

    How to handle trades individually?

    Hello,

    I'm having trouble with the following, I have two signal providers to enter some long/short market orders.
    I have a couple of questions

    1 - For further development, I need to know if there's currently a position open due to SMA, Stoch, or both. It seems there's no way to find this, it doesn't help much-giving tags to these trades if I cannot track them, what options do I have?

    2 - A sample screenshot is given, when there are 2 long trades going (quantity = 2), and I place an "EnterShort" (quantity = 1) these 2 trades are closed, and the short is entered. Is there a way to close just "quantity = 1"? and if I close "Stoch", "SMA" remains open, tracked, and visible on the chart? (vice versa if I close "SMA")

    Code:
    protected override void OnBarUpdate()
    {
      if (CurrentBar < BarsRequiredToTrade)
        return;
    
      if (CrossAbove(smaFast, smaSlow, 1))
        EnterLong("SMA");
      else if (CrossBelow(smaFast, smaSlow, 1))
        EnterShort("SMA");
    
      if (CrossAbove(stochastics.K, 20, 1))
        EnterLong("Stoch");
      else if (CrossBelow(stochastics.K, 80, 1))
        EnterShort("Stoch");
    }

    #2
    Hello Waxavi,

    1 - For further development, I need to know if there's currently a position open due to SMA, Stoch, or both. It seems there's no way to find this, it doesn't help much-giving tags to these trades if I cannot track them, what options do I have?
    The easiest way would be to use your own variable, the only information you can pass to an order would be the signal name so that would be the alternative.


    2 - A sample screenshot is given, when there are 2 long trades going (quantity = 2), and I place an "EnterShort" (quantity = 1) these 2 trades are closed, and the short is entered. Is there a way to close just "quantity = 1"? and if I close "Stoch", "SMA" remains open, tracked, and visible on the chart? (vice versa if I close "SMA")
    If you are trying to scale out of a position you would need to submit two separate entries that have unique signal names and then use Exit orders to close those out. If you intended to reverse 1 of the position then the second contract you can call EnterShort and that will reverse the position. The Exit orders have a parameter called FromEntrySignal which is the entry signal name to close.

    Comment


      #3
      If I type repeatedly for example

      Code:
      ExitLong("SMA");
      ExitLong("SMA");
      ExitLong("SMA");
      I don't get any error or notification, it's just mute.
      Is there a way to check if there's a signal "SMA" to exit from, beforehand?

      Comment


        #4
        Hello Waxavi,

        ExitLong("SMA"); would be trying to close an entry that was named SMA.

        To check if you are in a position you can use the MarketPosition: https://ninjatrader.com/support/help...MarketPosition

        Exit orders will be ignored if you have targets working.





        Comment


          #5
          I'd like this to be a feature if possible in the future, that at any point in time I can know how many "Entry Signals" are active and can be closed, without the use of flags.
          Thanks for your support

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          80 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          40 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          63 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          63 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          54 views
          0 likes
          Last Post CarlTrading  
          Working...
          X