Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLong()

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

    #16
    Hello rockmanx00,

    The error is stating it is coming from OnOrderUpdate() and not the .Click event handler method.

    Further, "After exit" is printing which suggests the run-time error is not occurring in this this code as if it were, no code below the code causing the error would be reached.

    I don't think that code is causing the run-time error.

    "No Pop ups, no errors and the strategy remains enabled."

    A run-time error will disable the script unless you are circumventing the the default behavior by using a try and catch.

    The syntax error was my mistake, the second pair of parenthesis is not needed.

    Try the following:
    Code:
    TriggerCustomEvent((Action) =>
    {
    Print("Position.Quantity: " + Position.Quantity);
    if (Position.MarketPosition == MarketPosition.Long && Position.Quantity != 0)
    {
    Print("Trying to exit long");
    ExitLong();
    Print("After exit");
    }​​
    }, null);
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      It would make sense that the error is somehow coming from OnOrderUpdate, but I would not know what needs to be fixed as I have Print() statements at the beginning of both OnOrderUpdate and OnExecutionUpdate and it doesn't seem to be getting that far. It does when I do Shorts, but never long.

      I have tried your new version of the code and it disables with this error:
      System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult]

      This is the error in context of the output.
      Position.MarketPosition: Long
      Position.Quantity: 14
      Trying to exit long
      Disabling NinjaScript strategy 'PullBackStrategy/278923527'
      System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult]
      After exit
      End of CloseAllButton Code​

      So now it simply disables it and gives that threading task error...

      ****
      I just realized that my print statement within OnOrderUpdate was not at the very top. I'm going to check if the things I was trying to initialize before that was causing the error.
      Last edited by rockmanx00; 02-03-2025, 03:13 PM.

      Comment


        #18
        Ok. That did not seem to do anything. None of the Print statements from OnOrderUpdate are firing. So the output remains the same as before.

        ***

        Scratch that. I had tried some other things and forgot to take that out. Also forgot to uncomment my ExitLong.
        Now it seems to be entering OnOrderUpdate. Still making errors and crashing, but I have some print statements that are giving me clues. I'll work on this and get back to you if I have anything further.
        Last edited by rockmanx00; 02-03-2025, 03:36 PM.

        Comment


          #19
          Ok. I got it figured out. It had to do with my logic of creating signal names for my entries and stops which usually had the format of "entryType " + unique number. or "stopType " + unique number. I wanted to be able to have the code do actions regardless of the unique numbers, so I have been using IndexOf(" ") looking for space in the names I was using.
          It turns out that for Shorts, it just so happens to be named "Buy to cover" which is why it was working fine as a short. But for Longs, it was only a simple "Sell" which was giving my index "-1" which was where the Out of Bounds error was coming from.

          Thank you Chelsea for your patience and wisdom and ultimately helping me fix my code. I appreciate it.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X