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

How to move a Profit Target

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

    #16
    if ((Position.MarketPosition == MarketPosition.Long)
    && (doOnce == true)
    && (UseRSICrossForExit == true))
    {
    doOnce = false;
    ExitLongStopMarket(0, true, Convert.ToInt32(Position.Quantity), (Position.AveragePrice + (-StopLoss * TickSize)), @"ProgStopLoss", "");
    ExitLongLimit(0, true, Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (ProfitTarget * TickSize)) , @"ProgProfitT", "");
    }

    fix == same results

    Comment


      #17
      OK thanks thanks again and thanks again

      GOT IT !!!!!!!!!!!!!!! (DO NOT ask me how)

      orders do not move back if I move them

      I HAVE an order rejection every time i exit a postion with the clean up of the other orders i believe



      followed by this






      i think my trail order is sending an update when the exit takes place

      GOING TO wait an see what the OnExecutionUpdate() does for that first
      searching the forum for info on that now

      Comment


        #18



        i put print on all exits order in the script the Above only shows my "StopMarketTrailStop" and "ExitShortTrendLineExit"

        the print from the StopLoss and Profit target never show up (AS IF THEY ARE NEVER SENT) but I know they are sent because they are on my Charts when i run the Strategy

        if ((Position.MarketPosition == MarketPosition.Short)
        // && (doOnceShort == true)
        && (doOnce == true)
        && (UseRSICrossForExit == true))
        {
        doOnce = false;
        // doOnceShort = false;
        ExitShortStopMarket(0, true,Convert.ToInt32(Position.Quantity), (Position.AveragePrice + (StopLoss * TickSize)), @"ProgStopLoss", "");
        ExitShortLimit(0,true, Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (-ProfitTarget * TickSize)) , @"ProgProfitT", "");
        Print("StopMarketStopLoss");
        Print("LimitProfitT");
        }

        ALSO AS stated in previous post I can move the Profit Target and it does not recalculate back to original value - so the exit order are being sent
        but I think they are the ones sending the error and are Not filling and causing the error

        Comment


          #19
          i try to install the onexecutionupdate

          // Example #2
          protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
          {
          // Remember to check the underlying Order object for null before trying to access its properties
          if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
          Print(execution.ToString());
          }

          and this rendered hundreds of error into my script and it is NOW non working - NOT sure i can fix it

          Comment


            #20
            this morning in reviewing my StopMarketStopLoss and ProfitTarget prints

            If i use doOnce they do not send prints, if i do not use doOnce the prints do send

            i further tested with playback connection, I set Long Trades with doOnce being used for Stop Loss and Profit Target Orders

            WITH doOnce in the Long Exits they do work as we planned and can be moved and NOT recalculate ONBARCLOSE

            I set Short Trades without doOnce being used for Stop Loss and Profit Target Orders

            THE SHORTS without the doOnce also work now

            I had added another logic do get around the onexecution update that seems to have also fixed both issues

            have no idea why prints did not work

            i do still have my error popups when exiting NOT every time so really an issue figuring out what is the cause



            Comment


              #21
              Hello DTSSTS,

              The error means the stop loss has been moved to an invalid level and cannot be moved there. (Sell Stop Market orders cannot be placed above the market.) If the strategy hits an error it will panic and abort. In this process it does as is mentioned: it will attempt to cancel orders, close the position, and then terminate itself. You can reproduce the occurence in the Playback Connection, and then use debugging prints to see which order changes are submitting the stop loss to an invalid level.

              We always recommend starting small when working with new NinjaScript concepts. You will save yourself a lot of trouble by first setting up a small test script to practice new concepts before plugging them into an existing strategy. This will ensure that you know how the functionality can be implemented and will give you better direction when implementing into your main strategy.

              The advanced order handling methods are also reserved for experienced developers. If they are too difficult to work with, we may suggest then sticking with submitting orders in OnBarUpdate, or using the Strategy Builder. Otherwise, I would suggest reviewing the SampleOnOrderUpdate example in depth, understand how it works, and then build a new script that performs the same so you can better grasp how the concepts are used. You would then be able to reference the working example along the way should you run into any difficulties.

              We look forward to being of further assistance.
              JimNinjaTrader Customer Service

              Comment


                #22
                Crazy turned on with Live Data testing this morning 1st trade I have NO stoploss or Profit target at all
                10 minutes ago with play back i had both

                Comment


                  #23
                  i can really figure out what order is sending the error, the StopLoss and Profit Target should NOT be as they are stationary and not near the level of the exit when this occurs
                  so think in related to the trail stop which is always changing THAT order is a Exit StopMarket order (is that considered a Buy Stop ? as indicated in the image






                  i do not know what the Print statement needs to include to gather the info to debug

                  Print("StopMarketTrailStop");

                  next item is the onExecutionUpdate, my trend line indicator and the onexectionupdate are having a huge conflict SO THAT WILL NOT WORK for submitting the orders immediately when position is created

                  Thanks

                  Comment


                    #24
                    Hello DTSSTS,

                    The error mentions that a buy stop order is being placed below the market. The error is also mentioning it is a BuyToCover order, so this would be an exit for a short position.

                    The market could have moved past Position.AveragePrice + (StopLoss * TickSize) when OnBarUpdate is processed and your stop loss for the short position is submitted, or if you are moving the stop loss in another part of the script. If you are moving the stop loss elsewhere in the script, you can comment that code out and test again in Playback to see if that section of code is moving the stop loss to an invalid level.

                    I also suggest placing prints before the order submission methods. The goal of adding prints will be to see how far the script gets before an error is seen. If the order is submitted to an invalid level, and the script terminates on the invalid submission, you will not see any prints after the order method.

                    As for OnExecutionUpdate, this will not interfere with an indicator. My recommendation remains to start with a very basic test script following the concepts outlined in SampleOnOrderUpdate. This will be the best way to grasp the concepts without complicating the matter with an existing script. Once you have a working implementation and understand how it is used, you will be better able to implement it in your existing strategy. If it is too difficult to work with, you could also consider enlisting the services of a NinjaScript Consultant to have them write the code for you.

                    Please let me know if there is anything else we can do to help.
                    JimNinjaTrader Customer Service

                    Comment


                      #25
                      i do not know what the Print statement needs to include to gather the info to debug

                      Print("StopMarketTrailStop");

                      i cannot figure out why stop orders are not sending more quickly, not even after bar close
                      and i do not know what the print statement need to include to figure it out

                      as well as the error on stop out with trailstop sending another order

                      Comment


                        #26
                        Hello DTSSTS,

                        Make the print statements meaningful to you. You are trying to see which order submission method is moving the stop loss to the invalid level. Adding a unique print above each order method will help to understand which order method is submitting the order to an invalid level. The strategy logic will print first, and then error out. The last print will tell you the order method that causes the strategy to error out.

                        Once you know the order method that is moving the stop to the invalid level, you will want to answer the following questions with your debugging prints:

                        1. What price is the order being submitted to?
                        2. What is the current market price?

                        Note that it is possible in live market scenarios for a strategy to calculate a price level to move the stop, submit the order, then the market moves. By the time the stop reaches the exchange, it is at an invalid level. You could respond to this by using RealtimeErrorHandling.IgnoreAllErrors, and then use OnOrderUpdate to have the strategy check if the order received an ErrorCode of UnableToChangeOrder. You can then have the strategy take a different action, like exiting via a market order.

                        RealtimeErrorHandling - https://ninjatrader.com/support/help...orhandling.htm

                        OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

                        I look forward to assisting.
                        JimNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by mattbsea, Today, 05:44 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post mattbsea  
                        Started by RideMe, 04-07-2024, 04:54 PM
                        6 responses
                        31 views
                        0 likes
                        Last Post RideMe
                        by RideMe
                         
                        Started by tkaboris, Today, 05:13 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post tkaboris  
                        Started by GussJ, 03-04-2020, 03:11 PM
                        16 responses
                        3,282 views
                        0 likes
                        Last Post Leafcutter  
                        Started by WHICKED, Today, 12:45 PM
                        2 responses
                        20 views
                        0 likes
                        Last Post WHICKED
                        by WHICKED
                         
                        Working...
                        X