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

Closing an Order

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

    Closing an Order

    Hi,

    I have a strategy to manage a pairs trade using stops and targets.The original trade is placed manually.

    The following code works fine and the Debug message is correct, but the position is not closed.

    Any pointer would be gratefully received.

    Thanks

    Ian

    if ((( aPair.PandL[0] >= Target1 ) || ( aPair.PandL[0] <= Stop1 )) && LiveData && ManageTrade && Lot1_T1 == OrderSize1_T1)
    {
    /// Target1 or Stop1 have been hit
    if ( aPair.PandL[0] >= Target1 )
    {
    Mess = "T1";
    triggerPrice = Target1;
    }
    else
    {
    Mess = "Stop1";
    triggerPrice = Stop1;
    }
    if (aPair.OrderSize1 > 0)
    {
    ExitLong(1, Lot1_T1, Mess + " Lot 1", "");
    // Param 1 is barsInProgressIndex
    // Param 2 is OrderSize
    // Param 3 is SignalName
    // Param 4 is fromEntryName

    ExitShort(2, Lot2_T1, Mess + " Lot 2", "");
    }
    else
    {
    ExitShort(1, Lot1_T1, Mess + " Lot 1", "");
    ExitLong(2, Lot2_T1, Mess + " Lot 2", "");
    }

    OrderSize1_T1 = 0;

    if(Debug)
    Print("Hit " + Mess + " for " + Inst1 + " / " + Inst2 + " . . . @ " + Time[0] +
    " Trigger Price " + triggerPrice.ToString("0.0") + " Actual Price " + aPair.PandL[0].ToString("0.0") );

    }


    #2
    Hello IanC28,

    Thank you for the post.

    The Managed order handling methods like EnterLong and ExitLong will not apply toward manual actions that happen outside the strategy. your strategy is only aware of orders it places and positions it makes.

    If your goal is to enter manually you have a few options. The first is to make a custom button which your strategy adds to a chart, you can click the button to manually enter. The button would then use a Managed order handling method like EnterLong to place the entry.
    https://ninjatrader.com/support/help...ub=usercontrol

    The other approach would be using the addon framework and observing an account directly. For that a strategy is not suggested but an indicator could instead be used. The reason a strategy is not suggested is that the Managed order methods and Addon methods do not mix so it is best to remove the strategy from the equation. You can use custom logic to control or otherwise submit orders using the addon framework/account.

    https://ninjatrader.com/support/help...t_overview.htm

    https://ninjatrader.com/support/helpGuides/nt8/submit.htm

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse, that worked well. I added the order control using Account CreateOrder and Submit. I don't have any managed orders in the strategy and all seems fine.

      I will also work on submitting orders from the strategy, but since the strategy can close before the trades do it was important that I could pick up exisiting orders and work with them when the strategy was restarted.

      I would like to add a Draw.TextFixed command to display the account name and other info on a panel used by an indicator displayed by the strategy. I have added the indicator using:

      AddChartIndicator(aPair);

      and called the Draw.TextFixed using

      Draw.TextFixed(aPair, "MyTag", "Account : " + Account.Name, TextPosition.BottomRight, false, "");

      but the text does not appear. If I use "this" instead of "aPair" the text appears on its own panel.

      Can you please advise what I am doing wrong.

      Thanks

      Ian

      Comment


        #4
        Hello IanC28,

        Thank you for the post.

        As a test could you comment out the code you are using that references aPair and replace the indicator aPair with an SMA then re test the code you were using to draw text? This could relate to the indicators settings, it would be helpful to know if one of the stock indicators allows this to work. You may also try using the MACD as that adds a second panel to see if that changes the result.



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, Yesterday, 04:22 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by stafe, 04-15-2024, 08:34 PM
        5 responses
        28 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by StrongLikeBull, Yesterday, 04:05 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Mestor, 03-10-2023, 01:50 AM
        14 responses
        375 views
        0 likes
        Last Post z.franck  
        Started by molecool, 10-09-2017, 10:48 AM
        5 responses
        1,621 views
        0 likes
        Last Post trader-ap  
        Working...
        X