Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reverse Code is not working

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

    Reverse Code is not working

    Hello,

    I have this code. It is suppose to reverse the whole strategy. It should close open positions, cancel orders and, also, submit orders and positions in the other direction. However, the algorithm is close open positions and cancelling orders, but it is not submitting orders or positions in the other side. Would you please help me finding the solution? I don't see the error.
    Also, if you need the full code or a bigger piece, I need to send it privately. Thank you so much in advance!

    if ( TimeToTrade() && barNumberOfShortEntries == 0 && okToEnter )
    {
    if (ShortSignal())
    {
    //Reverse if we are long or have open long orders
    if ( Position.MarketPosition == MarketPosition.Long || barNumberOfLongEntries > 0 )
    {
    LongReverse();
    }

    PlaceShortEntries();
    }
    }

    #2
    Hello Jorge.andres.o, thanks for your question.

    From the structure of the code, it looks like the PlaceShortEntries() method is in an incorrect place. If this becomes true it will do a long order, but right after that you call PlaceShortEntries:

    HTML Code:
    if ( Position.MarketPosition == MarketPosition.Long || barNumberOfLongEntries > 0 )
    {
    LongReverse();
    }
    It looks like you just need to re-structure the code. There are existing examples that do reversals, like the SampleMACrossover. In the Managed approach it's quite easy to do a reversal on a position. If you call EnterLong(), then subsequently call EnterShort(), NinjaTrader will automatically close out the long position and enter the short position. There is also a reversal example here:



    Please let me know if I can assist any further.

    Disclaimer: The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X