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 NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          62 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          134 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X