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

Buy-to-cover stop market order below current price

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

    Buy-to-cover stop market order below current price

    When I print out the current high and low, as well as the location of my current stop, everything looks good.

    I know my code isn't very efficient, I'm in the process of creating a boilerplate template and I'm very much in the trial-and-error stage.

    Here's the code snippet from this attempt to modify the stop, let me know if I should paste more code.

    I must be doing something wrong, one of the errors it throws tells me I'm trying to put the stop below the market but according to my printouts that's not the case.

    Code:

    //TRAIL SHORT
    if ((Highs[1][0]+stopBufferTicks*TickSize) < origStopPriceShorts && moveStopBool && okToTrailShort)
    {
    Print(Times[1][0]);
    Print("Current Stop: " + currStopPrice + " New stop : " + (Highs[1][0]+stopBufferTicks*TickSize) + " Original stop location: " + origStopPriceShorts);
    Print("Current High: " + Highs[1][0]);
    Print("Current Low: " + Lows[1][0]);
    if (entryOrderShort != null && (currStopPrice > (Highs[1][0]+stopBufferTicks*TickSize)))
    {
    ExitShortStopMarket(1, true, Position.Quantity, newStopPriceShorts,"short exit","short entry");
    }
    }
    Attached Files
    Last edited by butt_toast; 07-22-2021, 07:13 AM.

    #2
    Let me know if I should share more code. I'm a trader learning programming so I'm not familiar with the etiquette. Recently I included too much code when asking for help, so this is an attempt to keep it short and to the point.


    Comment


      #3
      Hello butt_toast,

      The current high and low would not matter for submitting a change, you would need to make sure the price is valid and on the correct side of the market based on the ask/bid and type of order being used. If you are seeing that your calculation for the price is placing the order incorrectly you may need to increase the offset you are using to trail further away from the fast moving market.

      As a side note the chart trader and its Right click on the chart menu is helpful for determining which side of the market a given order type should go on, it will hide order types which cannot be placed at the given location.

      Please let me know if I may be of additional assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Jesse View Post
        Hello butt_toast,

        The current high and low would not matter for submitting a change, you would need to make sure the price is valid and on the correct side of the market based on the ask/bid and type of order being used. If you are seeing that your calculation for the price is placing the order incorrectly you may need to increase the offset you are using to trail further away from the fast moving market.

        As a side note the chart trader and its Right click on the chart menu is helpful for determining which side of the market a given order type should go on, it will hide order types which cannot be placed at the given location.

        Please let me know if I may be of additional assistance.
        Thanks for replying.

        The high is relevant because it shows that the buy to cover stop market is being placed above the current high of the current bar by a significant amount that is totally valid. I know that this is valid because I've done it thousands of times in the real market with real stops.

        I'm definitely doing something wrong here because if the code was actually trying to place the order where it is telling me it wouldn't reject the order.

        I've re-uploaded the errors and print out all in one image. You can see that the place "new stop" is where I'm trying to move my stop is 69.50. This is 10 ticks above the current high. Buy stops go above the market and this error seems to be telling me that I'm placing the buy stop below market.

        I hope I've explained this clearly, please let me know if I haven't and I'll try again.

        Edit:
        I'm going to try to recreate this and print the actual bid/ask at the time of the error. Either the bid/ask is impossibly above the current high of the bar or the new stop price is below the bid/ask. Will have to refer to the language reference to figure out how to print out current bid/ask.

        Comment


          #5
          I printed the current spread (bid/ask) and also the place where I'm trying to move the new stop.

          This is definitely a case of user error but I am just too new to ninjascript to figure out exactly what I'm doing wrong.
          Attached Files

          Comment


            #6
            Hello butt_toast,

            The high is the price of the bar and may not be what the current market is trading at. If you are making a change or submitting an order you would need to make sure to calculate a valid price for the current market and not based on an arbitrary bar value such as a previous high or low. While you can use the high and low as part of the calculation you can also generate invalid prices using those prices.

            The error you are seeing is specific, you used an invalid price for that order and need to make adjustments to your logic.

            You could try printing the ask/bid based on the direction or change the calculation to have a further away offset from the active market.


            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              I figured it out.

              The value I was using to print the new stop price was calculating the new stop price manually whereas the value to actually place the new stop was a variable that was equal to zero. I fixed this and now it works.

              I do have one quick question for you:

              When I make a change to the code and compile it, do I need to remove the strategy from the chart and re-apply it every single time? That's what I've been doing and I wanted to ask if this is truly necessary.

              Comment


                #8
                Hello butt_toast,

                That depends on the change. Its good practice to just remove and re add scripts when developing them. Generally only changes to OnBarUpdate can have F5 reload work.


                Please let me know if I may be of additional assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello butt_toast

                  I have the same problem i Would like to know how you solved it ??

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by cocoescala, 10-12-2018, 11:02 PM
                  6 responses
                  939 views
                  0 likes
                  Last Post Jquiroz1975  
                  Started by gbourque, Today, 06:39 AM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by cmtjoancolmenero, Yesterday, 03:58 PM
                  1 response
                  17 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by benmarkal, Yesterday, 12:52 PM
                  3 responses
                  23 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by helpwanted, Today, 03:06 AM
                  1 response
                  20 views
                  0 likes
                  Last Post sarafuenonly123  
                  Working...
                  X