Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trades occasionally being exited immediately after entry issue

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

    Trades occasionally being exited immediately after entry issue

    Hello,

    I've got a weird problem in my strategy that I cannot fathom as to what's happening with it. My strategy takes a trade in a certain direction - for this example I'll use a long trade.

    Enter long position ( long NQ at 16000 )

    Use SetProfitTarget to set my target to 20 ticks. ( NQ 16005 )

    The trade wins.



    NEXT TRADE.......


    Enter long position ( long NQ at 17000 )

    Trade instantly exits usually for a tick or 2 loss

    Script tries to SetProfitTarget to my target of 20 ticks. ( NQ 17005 )

    Script errors because the position has already closed due to the trade exiting immediately.



    When I look into what's happened, as soon as it's taken the new position, there's an entry in the log that says it's setting the Profit Target to 16005, which is below the currently price, so it instantly closes the position - if you remember, the previous trade had a profit target of 16005! This happens over and over and I can't fathom why! ... I'm only ever using SetProfitTarget to 8 ticks in my script, but it's somehow using the value from the previous trade????


    myEntryOrder = EnterLong(1, "MyScriptEntry");
    SetProfitTarget("MyScriptEntry", CalculationMode.Ticks, 20);





    Here is line by line log of an actual trade that worked out, but can you see it falsely sets the target at first ... as you can see, highlighted in red, it immediately sets a target of 16787(Which was the previous trades target). Luckily in this example, the previous target of 16787 was actually higher than the entry price of 16784.75 so it didn't close instantly, you can then see the script changing the profit target to the correctly value by the a "Change submitted" line, which is modifying the profit target to what is should be(16789.75)


    Click image for larger version  Name:	image.png Views:	0 Size:	486.3 KB ID:	1286084



    Hope that makes sense​​!

    Thanks

    Andy
    Attached Files
    Last edited by ravvles; 01-11-2024, 12:32 PM.

    #2
    Hello ravvles,

    You need to call SetProfitTarget before the entry method to reset it so it does not use the average entry price from the previous order. Please try the following:

    Code:
    SetProfitTarget("MyScriptEntry", CalculationMode.Ticks, 20);
    myEntryOrder = EnterLong(1, "MyScriptEntry");

    Comment


      #3
      Oh wow, thanks I'll give that a go and report back! I always thought that you set the target once the position has been entered!

      Comment


        #4
        And just like that, it's fixed! thank you NinjaTrader_Jesse !

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        72 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X