Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to exit on a reverse signal and enter again

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

    how to exit on a reverse signal and enter again

    Hi,
    How do i have stop and reverse logic? I want to get in short on a cross over and if there is long cross over i want to exit my short and enter long..... And reverse for Shorts. I am a bit confused how to deal with ExitLong stop markets and limits.... With logic below when in long, on crossShort it doesnt reverses position


    EnterLong(PositionSize, "Cross Long");
    if ((Position.MarketPosition == MarketPosition.Long && EMACrossShort == true) )
    {
    ExitLong();
    EnterShort(PositionSize, "Cross Short");
    }​

    if(Position.MarketPosition == MarketPosition.Long)


    ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - (TickSize * StopLossTicks), "SLL", "Cross Long");

    ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "Cross Long");​
    Last edited by tkaboris; 07-03-2023, 06:52 AM.

    #2
    Hello tkaboris,

    Because you are using targets you would need to either have those targets fill first and become flat before entering into the opposite direction or you would need to cancel them and then enter the opposite direction after the cancellation is complete. When using the managed approach you can have an automatic reversal if you call the opposite entry method while in a position, that both exits the position and enters the opposite. With what you have here you will run into the managed approach order handling rules.

    Another item is that you cannot call Exit methods at the same time as entry methods, The code you have shown will cause a duplicate exit and lead to a duplicate reversal, you need to remove the exit order you have before EnterShort. If you are in a long position and call entershort that will reverse the position.

    You can read the general rules of orders in the following page: https://ninjatrader.com/support/help...antedPositions

    To know when you are hitting a rule you can enable TraceOrders https://ninjatrader.com/support/help...ub=TraceOrders

    Comment


      #3
      Ok got it. I simply used ExitLong() ExitShort() before making an apposite trade. however
      during backtesting market replay i sometimes get this messed up screen. Its like taking one of mine EMAs cyan and ploting it to 0 values.. Like tests run fine for couple of hours, taking all trades but suddenly occasioanll i get this chart

      Click image for larger version

Name:	image.png
Views:	294
Size:	609.7 KB
ID:	1258717

      Comment


        #4
        Hello tkaboris,

        I wouldnt be able to say what may be causing that from the image, you would have to add prints into the script and see what may be happening there. If thats an EMA plotting at 0 that wouldn't be related to your trading question, I would suggest to break that into a seperate post based on what you find after adding prints.

        One note on your comment about using exits before an opposing trade, if you are doing the following that will result in a double reversal. The following is not valid:

        Code:
        if ((Position.MarketPosition == MarketPosition.Long && EMACrossShort == true) )
        {
        ExitLong();
        EnterShort(PositionSize, "Cross Short");
        }​​​
        this would be valid:

        Code:
        if ((Position.MarketPosition == MarketPosition.Long && EMACrossShort == true) )
        {
        EnterShort(PositionSize, "Cross Short");
        }​
        You would only see a problem when running the script in realtime, it would exit the position then try to reverse which also exts the position leading to 2 in the opposite direction. ​

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        53 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
        70 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