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

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.

    JesseNinjaTrader Customer Service

    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.





        JesseNinjaTrader Customer Service

        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 fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,403 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          94 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          6 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          158 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          8 views
          0 likes
          Last Post Belfortbucks  
          Working...
          X