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

Exit and Enter right away

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

    Exit and Enter right away

    I'm really stumped on this issue and am wondering if exiting a position also causes a "return;" to happen and kill a process.

    Upon signal==0, I want this code to flip any open short position to a long position if lettradefinish==false (and cancel the signal if lettradefinish==true). if lettradefinish==true it cancels the signal correctly. But if lettradefinish==false, it just exits the short position while not opening the new long one.

    assumptions:
    Lettradefinish is an arbitrarily set bool that i have permanently set to false
    signal==0 means the rest of my code generated a signal to go long (default for no signal is signal==-1), assume signal==0
    AllowTrade is true
    we head into this code with a short position

    if (signal==0)
    {
    if (Position.MarketPosition==MarketPosition.Short)
    {
    if(!LetTradeFinish)
    {
    Position.Close();

    }
    else
    {
    signal=-1;
    }
    }

    if(AllowTrade && (Position.MarketPosition==MarketPosition.Flat || (Position.Quantity<Quantity*this.EntriesPerDirecti on && AllowMultiEntries)))
    {
    IOrder order = this.EnterLong(0,Quantity,"Long Entry");
    }
    }

    Would greatly appreciate any help as I think I must not understand what some of these order lines are doing from a process/order of events perspective.

    #2
    entropy, please simplify your code until it is function correctly and then you can start layering on the complexity again. I don't have you full code, so I can't run it, but I have a feeling all of the long order entry conditions aren't being met.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Austin, your comments helped me focus on the values and I've solved the problem.

      I was thinking that as soon as I first exited the existing short position that marketposition would immediately be marketposition.flat, but this must not be the case until the next tick.

      Instead of counting on marketposition.flat, i'm using a bool to track if the exit happened yet and to allow the long entry if it did, and it works great.

      Thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kujista, Today, 06:23 AM
      0 responses
      1 view
      0 likes
      Last Post kujista
      by kujista
       
      Started by traderqz, Yesterday, 04:32 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by f.saeidi, Today, 05:56 AM
      1 response
      4 views
      0 likes
      Last Post Jltarrau  
      Started by Jltarrau, Today, 05:57 AM
      0 responses
      4 views
      0 likes
      Last Post Jltarrau  
      Started by Stanfillirenfro, Yesterday, 09:19 AM
      7 responses
      53 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X