Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    7 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    21 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    10 views
    0 likes
    Last Post cre8able  
    Working...
    X