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

{NinjaScript} - Stop Orders

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

    {NinjaScript} - Stop Orders

    Hello,

    I am trying to create stop orders, both sales and purchases.

    They must be able to be created no matter if a previous stopOrder already exists, whenever OnBarUpdate () is executed, the order that is written in the code must be created..

    even if they are opposing sales and purchases, they must always be created.

    Here is my code, but is not working as I described:

    protected override void OnBarUpdate()
    {
    if(condition1)
    {
    SetStopLoss(signalName,CalculationMode.Price,sl,fa lse);
    SetProfitTarget(signalName,CalculationMode.Price,t p);
    EnterLongStopMarket(0,true,10000,stopPrice,signalN ame);
    }
    if(condition2)
    {
    SetStopLoss(signalName,CalculationMode.Price,sl,fa lse);
    SetProfitTarget(signalName,CalculationMode.Price,t p);
    EnterShortStopMarket(0,true,10000,stopPrice,signal Name);
    }

    }

    Please, could you help me?

    #2
    Hello fscabrera03,

    Are you trying to place a buy stop entry and sell stop entry at the same time?

    This would violate the internal handling rules for the managed approach.

    "Methods that generate orders to enter a position will be ignored if:
    The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction"


    The unmanaged approach would be necessary to place orders in opposite directions.
    Below is a link to an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea,
      How works Stop Orders when fundamentals are happening? There are some coding tip to handle stop orders in that kind of volatile scenarios to protect the account and the strategy when price is changing so fast?
      Any recomendation?

      Comment


        #4
        Hello nandocabrera87,

        Welcome to the NinjaTrader forums!

        Fundamental data received in OnFundamentalData will not affect orders.

        Stop order will become a market or limit when the stop price is reached.

        I don't have any custom logic I can provide you for dealing with fast markets.

        Is there a specific error you having an issue with?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you!
          Yes, My strategy are having trouble when market moves fast.
          Im attaching the chart, the orders, positions, logs and 3 error windows that opens when the price is where the grafic shows.
          Can you help me?
          Site doesnt let me upload xlsx files for executions and orders but I can share you by drive if you can.
          I cant undestand what is happening.
          Thank you so much

          Attached Files

          Comment


            #6
            Hello fscabrera03,

            I suggest using debugging prints to check the price of p, when the strategy enters and the rejection is seen. You may use the Playback Connection to reproduce behaviors that have happened with realtime data.

            Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

            Playback Connection - https://ninjatrader.com/support/help...connection.htm

            Buy Stops must be above the ask and Sell Stops must be below the bid. You may use GetCurrentBid/GetCurrentAsk to check the bid/ask prices and ensure the stops will be submitted at an appropriate level.

            GetCurrentBid - https://ninjatrader.com/support/help...currentbid.htm

            GetCurrentAsk - https://ninjatrader.com/support/help...currentask.htm

            I may also suggest protecting your entry conditions with a position check so that if condition2 becomes true after you entered long, the stop loss does not get modified.

            Position.MarketPosition - https://ninjatrader.com/support/help...etposition.htm

            We look forward to assisting.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hi
              I've noticed many times that stop losses and take profits do not happen after x pips once it is reached in my custom strategies and strategies that come with NT8. Why is this not happening?
              Could you help?

              Comment


                #8
                Hello honest-trader,

                Is the order in a working state with a stop or limit price at the time the current price reaches the order?

                Have you enabled TraceOrders and added prints to show when the condition to place the order is true?

                Below is a link to a forum post that demonstrates how to use Print() and TraceOrders to understand behavior.


                Please save the output from the NinjaScript Output window to a text file and include this with your next post.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  So you need to know coding for this by inserting the print output! Is it notpossible to modify the strategy using the builder and insert this print?

                  Comment


                    #10
                    Hello honest-trader,

                    Please review the forum post I have linked which includes the video 'Debugging using prints with the Strategy Builder'.

                    No, you do not need to know C# coding to use the Strategy Builder.

                    TraceOrders is enabled in the Defaults. This will require removing and re-adding the instance of the script as noted in the forum post linked.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by geddyisodin, Today, 05:20 AM
                    2 responses
                    16 views
                    0 likes
                    Last Post geddyisodin  
                    Started by hazylizard, Today, 08:38 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post hazylizard  
                    Started by Max238, Today, 01:28 AM
                    5 responses
                    42 views
                    0 likes
                    Last Post Max238
                    by Max238
                     
                    Started by giulyko00, Yesterday, 12:03 PM
                    3 responses
                    13 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by habeebft, Today, 07:27 AM
                    1 response
                    16 views
                    0 likes
                    Last Post NinjaTrader_ChristopherS  
                    Working...
                    X