Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy Stop Limit Orders Cant Be Placed

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

    #16
    is this would be correct?

    if ((Position.MarketPosition == MarketPosition.Long && myFreeTradeLong == true) )

    {
    double ask = GetCurrentAsk();
    double bid = GetCurrentBid();

    double tpByATRRecalculated = Instrument.MasterInstrument.RoundToTickSize(Positi on.AveragePrice + tpByATR * TickSize);
    double slRecalculated = Instrument.MasterInstrument.RoundToTickSize(Positi on.AveragePrice - slLongMinMax[1] * TickSize);
    //Buy Stop Order: Set price >= current Ask
    if (FixedStopLoss)
    {
    if(slRecalculated.ApproxCompare(bid) >= ask)
    {
    ExitLongStopMarket(0, true, Position.Quantity, slLongMinMax[1], "SLL", "TLL");
    }
    }


    if (UseTPByATR)

    {


    if(tpByATRRecalculated.ApproxCompare(ask) <= bid)
    {
    ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * tpByATR), "tpByATRRecalculated", "TLL");
    }
    }



    }​

    Comment


      #17
      Hello tkaboris,

      You would need to test this if you want to know if its correct or not. I can tell you right now that this has the same issues as the previous version and my last reply would still be relevant.

      The purpose of our support team is not to look at each change you make and figure out if that is correct or not. We can help provide suggestions or help documentation surrounding concepts to help guide you toward that goal.

      The code you are using needs to change so that you are using logic to check if the prices you are using for the order are correct. You still haven't used slRecalculated so the new condition you added does not make sense because you submit a different price with the order. You need to check the prices you use with the order if those are correct.

      Using Print statements is a very important step if you are hitting a problem. The code shown has no prints so you really cant tell how that logic would be executed, you have nothing to compare with to see how it executed.

      The take away that I can provide here is that the error you are seeing is normal and can happen when you trade close to the active price. The only way to avoid getting that type of rejection is to make sure your strategy is pricing orders correctly and placing them far enough away from the active price so that when it gets to the exchange thats still a valid price to use.

      Comment


        #18
        I am stuck. I wanted to reproduce the error but its not coming up anymore. if i have the following then SL is not being set at all, only take profit

        if ((Position.MarketPosition == MarketPosition.Long && myFreeTradeLong == true) )

        {
        double ask = GetCurrentAsk();
        double bid = GetCurrentBid();

        double tpByATRRecalculated = Instrument.MasterInstrument.RoundToTickSize(Positi on.AveragePrice + tpByATR * TickSize);
        double slRecalculated = Instrument.MasterInstrument.RoundToTickSize(Positi on.AveragePrice - slLongMinMax[1] * TickSize);

        //Buy Stop Order: Set price >= current Ask

        if (FixedStopLoss)
        {
        if(slRecalculated.ApproxCompare(bid) >= ask)
        {

        ExitLongStopMarket(0, true, Position.Quantity, slRecalculated, "SLL", "TLL");
        }
        }


        if (UseTPByATR)

        {


        if(tpByATRRecalculated.ApproxCompare(ask) >= bid)
        {

        ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * tpByATRRecalculated), "PTL", "TLL");
        }
        }



        }​​

        Comment


          #19
          Hello tkaboris,

          If the error is not coming up any more and the stoploss is not being set then you are avoiding the error because the stoploss is not active or being changed to an invalid value.

          I don't mean to repeat myself but the answer is the same here, you need to use Prints. All of the code you have provided have not contained any prints meaning you cannot see how that logic is executing. To know why its not placing the stoploss you need to know why your condition that submits it was not true.

          The same goes for checking the prices, you need to use prints to make sure whatever condition you make works to check the price to make sure a valid price is used.

          Comment


            #20
            hi, i added prints and apparently slRecalcualted and tpRecalculated values were wrong.. So I removed them all together.
            So now i have if fixed stoploss value greater then ask to enter and I assume no additional conditions for placing Take Profit? Just make sure for sell side slLongMinMax[1] < GetCurrentBid()
            Does this seem correct?

            if ((Position.MarketPosition == MarketPosition.Long && myFreeTradeLong == true) )

            {


            //Buy Stop Order: Set price >= current Ask
            //Buy stop orders must be placed above the current ask price. Sell stop orders must be placed below the current bid price.

            if (FixedStopLoss)
            {
            if(slLongMinMax[1] > GetCurrentAsk())
            {

            ExitLongStopMarket(0, true, Position.Quantity, slLongMinMax[1], "SLL", "TLL");
            }
            }


            if (UseTPByATR)

            {



            ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * tpByATR), "PTL", "TLL");


            }



            }​

            Comment


              #21
              Hello tkaboris,

              You need to test that to know if its correct and allows your script to work as expected. Prints give you a window to view what the strategy is seeing, you need to run the script an view the prints to confirm that change helped. If you no longer get the error, the order works, and the prints all look within range then yes that likely works.

              As mentioned I can provide guidance on a direction but you would need to do the tests by using the tools in the platform to make confirmations on your changes. Debugging the script is a very large part of developing a strategy and is the only way to can confirm it will execute your goals to plan.

              Comment


                #22
                I placed prints and it still not placing stop order. Is it my slLongMinMax[1] that has issue and I may need to make itslLongMinMax[2] instead? since itts firsttickofbar

                slLongMinMax[0] = Low[0] - (StopLossOffset * TickSize);

                here are my prints indicating ask is less then stop
                Entering Jump Long : 4/10/2023 10:31:00 AM- 280
                ===============================
                ask13005
                slminmax13004.5​​


                Print("ask"+GetCurrentAsk());
                Print("slminmax"+slShortMinMax[1]);
                if ((Position.MarketPosition == MarketPosition.Long && myFreeTradeLong == true) )

                {
                double ask = GetCurrentAsk();
                double bid = GetCurrentBid();

                if (FixedStopLoss && StopLossTicks > GetCurrentAsk())
                {
                ExitLongStopMarket(0, true, Position.Quantity, StopLossTicks, "SLL", "TLL");
                }


                // else if (slRecalculated.ApproxCompare(bid) >= ask)

                else if(slLongMinMax[1] > GetCurrentAsk())
                {
                ExitLongStopMarket(0, true, Position.Quantity, slLongMinMax[1], "SLL", "TLL");
                }



                if (ProfitTarget)

                {
                ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "TLL");
                }

                if (UseTPByATR )
                {
                ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * tpByATR), "PTL", "TLL");
                }


                if (ProfitTargetRR)
                {
                ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (riskLong ), "PTL", "TLL");

                }


                }​​
                Click image for larger version  Name:	image.png Views:	0 Size:	129.3 KB ID:	1255937

                Comment


                  #23
                  Hello tkaboris,

                  I placed prints and it still not placing stop order.
                  The prints you used dont match what you used in the conditions, you need to modify your prints to match your conditions.

                  Comment


                    #24
                    do you mean entry conditions or conditions when i place stop loss and take profit?
                    I dont understand something, it says
                    For a buy stop order, ensure the stop price is greater than the ask, not the bid.
                    So for buys my stop is always of the candle low, so its always be lower then ask price. stop price will not be greater then ask becacuse stop is below bar low.
                    Last edited by tkaboris; 06-13-2023, 02:39 PM.

                    Comment


                      #25
                      Hello tkaboris,

                      You would need to modify the prints to output information that is relevant to whatever issue you are trying to figure out. If the problem is with submitting or repricing a stop order the relevant prints would be with values used by the stop order such as its price or conditions surrounding that order. So far we haven't been talking about the entry conditions so that should not be relevant to the question.

                      Comment


                        #26
                        I believe i prrinted relevant information
                        I printed ask and slminmax that is used for finding value of low of the previous bar. Its in the picture. What else should i be printing?

                        Comment


                          #27
                          Hello tkaboris,

                          In the last post with code you are only printing the ask and slShortMinMax. slShortMinMax is not used at all in that code so that print is not helpful. GetCurrentask is only helpful for part of the conditions you made. You are only printing a very small part of the overall condition you made so you arent printing anything that is of real value at this point. Knowing what the ask price is won't help if you don't know what the other values you used in your conditions are.

                          Comment


                            #28
                            its been difficult... in post 22 there is no conditions surrounding buy order other then what i already posted.
                            if this is to be true
                            /Buy Stop Order: Set price >= current Ask

                            can you please tell me how to find Set Price? I know current ask.

                            Comment


                              #29
                              Hello tkaboris,

                              In post 22 you arent printing anything besides the ask, everything else is not being printed. I wouldn't expect you to be able to know what is happening with the prints you added. You need to print the variables you used in those conditions to know how that logic is working. If you don't print those values you cant expect to know the outcome.

                              Comment


                                #30
                                hi, i dont see what other conditions there are except entry conditions..
                                Strategy places stop losses alright but sometimes in violent markets it skips placing Stop loss or take profits. I need a simple solution to avoid this and from what I understand I need to make sure.
                                Buy Stop Order: Set price >= current Ask

                                I dont see any other prints that i can print.

                                I am a bit confused about this Set price in my case. What is Set Price suppose to be?
                                is this a StopLoss level that corresponds to this line slLongMinMax[1]
                                ExitLongStopMarket(0, true, Position.Quantity, slLongMinMax[1], "SLL", "TLL");

                                Click image for larger version  Name:	image.png Views:	0 Size:	144.6 KB ID:	1255969

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                58 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                133 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                73 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                45 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                50 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X