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 NullPointStrategies, Today, 05:17 AM
    0 responses
    52 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