Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why this little code is wrong ? Order limit

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

    Why this little code is wrong ? Order limit

    Hi everybody,

    Okay I would like to launch a strategy with limit orders.

    I would like to link to targets and one stop to this limit order. I would like the limit order be enable while the condition S==1

    Don't understand why my code is wrong ?

    Code:
    if (S==1){
    
    EnterShortLimit(2,niveau, "Vente");
    ExitShortLimit(1,niveau-PO, "Vente1", "Vente");
    ExitShortLimit(1,niveau-SO, "Vente2", "Vente");
    ExitShortLimit(2,niveau+FSTOP, "VenteS", "Vente");
    				}
    Thank you a lot !

    #2
    Hello After,

    Thank you for your post.

    The exit orders are likely being rejected dur to the internal order handling rules at the following link: http://www.ninjatrader.com/support/h...d_approach.htm

    If you want to set up Profit Targets and Stop Losses you can use the SetProfitTarget and SetStopLoss methods:

    Comment


      #3
      Thank you for you answer !

      Unlikely, I would like to close out partial position thanks to limit order, and I can't do this with SetProfitTarget and SetStopLoss methods.

      How could I do ?
      Last edited by After; 10-16-2014, 03:49 PM.

      Comment


        #4
        Hello After,

        Thank you for your response.

        Separate your entry order into two orders and then give them unique entrySignalNames that would be called by the SetProfitTarget and SetStopLoss methods. This would allow you to set up multiple exits.

        Comment


          #5
          Oh thank you very much !

          Sometimes I'm an idiot

          But why this code doesn't run well :

          Code:
          if (SignalVente==1) {
          				EnterShortLimit(GetCurrentAsk(), "Vente1");
          				EnterShortLimit(GetCurrentAsk(), "Vente2");
          			} else if (OV1==1) {
          				ExitShortLimit(GetCurrentAsk(), "Vente1");
          			} else if (POV2==1) {
          				ExitShortLimit(GetCurrentAsk(), "Vente2");
          			} else if (DeadV==1) {
          				ExitShortLimit(GetCurrentAsk(), "Vente1");
          				ExitShortLimit(GetCurrentAsk(), "Vente2");
          			}
          And this one works perfectly :

          Code:
          if (SignalVente==1) {
          				EnterShort(2);
          			} else if (OV1==1) {
          				ExitShort(1);
          			} else if (POV2==1) {
          				ExitShort(1);
          			} else if (DeadV==1) {
          				ExitShort(2);
          				
          			}
          Just would like to turn my EnterShort and ExitShort into limit orders.

          Comment


            #6
            Hello After,

            Thank you for your response.

            You can look into this further by enabling TraceOrders and tracking the information in the Output window (Tools > Output): http://www.ninjatrader.com/support/f...ead.php?t=3627

            Comment


              #7
              I assume this line is your stop loss? You using the wrong type, use ExitShortStopLimit if this is the case.

              Code:
              ExitShortLimit(2,niveau+FSTOP, "VenteS", "Vente");
              Code:
              if (S==1)
              {
              [COLOR="SeaGreen"]//ENTRY[/COLOR]
              EnterShortLimit(2,niveau, "Vente");
              [COLOR="SeaGreen"]//PROFIT TARGET 1[/COLOR]
              ExitShortLimit(1,niveau-PO, "Vente1", "Vente");
              [COLOR="SeaGreen"]//PROFIT TARGET 2[/COLOR]
              ExitShortLimit(1,niveau-SO, "Vente2", "Vente");
              [COLOR="SeaGreen"]//STOP LOSS CONTROL[/COLOR]
              ExitShortStopLimit(2,niveau+FSTOP, "VenteS", "Vente");
              }
              Last edited by happypappy; 10-16-2014, 11:44 PM.

              Comment


                #8
                Thank you very much for your answers !

                So I modified the code as you said happyhappy but it doesn't still work....... :

                Code:
                		if (SignalVente==1) 
                {
                EnterShortLimit(0,true,2, GetCurrentAsk(), "Vente");
                } else if (OV1==1) {
                ExitShortLimit(0,true,1, GetCurrentAsk(), "VenteT", "Vente");
                } else if (DeadV==1) {
                ExitShortLimit(0,true,2, GetCurrentAsk(), "VenteS", "Vente");
                				
                			}
                Don't understand ! Because this one works perfectly !

                Code:
                if (SignalVente==1) 
                {
                EnterShort(2);
                } else if (OV1==1) {
                ExitShort(1);
                } else if (POV2==1) {
                ExitShort(1);
                } else if (DeadV==1) {
                ExitShort(2);
                				
                			}
                Last edited by After; 10-17-2014, 05:49 AM.

                Comment


                  #9
                  Hi After, have you tried Patrick's advice and enabled the TraceOrders feature for better debugging as per this tip?



                  You would need to keep in mind that per default your limits will only last for one bar and then would expire if not filled - so perhaps you're not giving them enough time to fill with this approach, options would be then either resubmitting next bar if not filled, or using the liveUntilCancelled overload for the Enter() methods to have the order persist until filled or cancelled by the end of session handling.

                  Comment


                    #10
                    Thanks Bertrand !

                    No because in fact, orders are filled on the market, but sometimes not in the right place.

                    Look at the picture "HowItShouldBe" : everything is okay, signal and then stop

                    Then look at the picture "Issue" : why the stop isn't at the right place here ?

                    Thanks a lot everybody

                    Remind you the code :

                    if (SignalVente==1)
                    {
                    //ENTRY
                    EnterShortLimit(0,true,2, GetCurrentAsk(), "Vente");
                    } else if (OV1==1) {
                    //TARGET
                    ExitShortLimit(0,true,1, GetCurrentAsk(), "VenteT", "Vente");
                    } else if (DeadV==1) {
                    //STOP
                    ExitShortLimit(0,true,2, GetCurrentAsk(), "VenteS", "Vente");
                    }
                    Attached Files
                    Last edited by After; 10-17-2014, 05:49 AM.

                    Comment


                      #11
                      After, in your latest snippets I don't see any VenteS named stop? How do you submit that now in? In the trace orders ouput you will see exactly at which time the internal placeorder command was triggered here in addition to your ordertype and stopvalue. Perhaps the stoplimit was simply overrun by the priceaction, there's a risk using those for stops, as you you could get left unfilled.

                      Comment


                        #12
                        ExitShortLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName, string fromEntrySignal)

                        "VenteS" is the signalName, not the fromEntrySignal name !

                        Okay for TraceOrders, but can only use it in real-time, not for backtest ?

                        Comment


                          #13
                          Thanks after for editing the post to paste in the snippet.

                          The TraceOrders feature will work in a backtest as well.

                          You just place a regular limit order here, which is unusual for a stop. Recommended would be either a StopMarket or StopLimit order. StopMarket order would have the advantage firing a market order on the stop price getting hit, meaning you would get a fill / stopout, albeit not at a price you could 'control'. Limits could get overrun, as you're only suggesting to pay this price or better > not worse. Which is shown in your screenshot.

                          Comment


                            #14
                            Thanks very much !

                            "You just place a regular limit order here, which is unusual for a stop. Recommended would be either a StopMarket or StopLimit order."

                            Could you indicate how should I code ExitShortStopLimit ?

                            Tried this :
                            Code:
                            ExitShortStopLimit(2,GetCurrentAsk(), "VenteS", "Vente");
                            But nothing happens ! It would be very nice !

                            Comment


                              #15
                              You're only specifying one price here, whereas the StopLimit order would have two parts, the StopPrice and the Limit price.

                              ExitShortStopLimit(int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal)

                              For more background on all supported order types would suggest to check into - http://www.ninjatrader.com/support/f...ead.php?t=3271

                              Lastly, please run with TraceOrders as this would help indicate if an order is expiring unfilled, which could happen as per default any order would only last for one bar in the managed approach (which you're working in right now).

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              603 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              349 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              104 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              560 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              560 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X