Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

{Ninjascript} NT8 - EnterLongStopMarket

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

    {Ninjascript} NT8 - EnterLongStopMarket

    Hello Everyone.
    I need to create a EnterLongStopMarket with stop Loss and Profit target, here is my code:

    -----------------------------------------------------------------------------------------------------------------------------------

    else if (State == State.Configure)
    {
    SetProfitTarget("", CalculationMode.Pips, 20);
    SetStopLoss("", CalculationMode.Pips, 20, false);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 2)
    return;

    // Set 1
    if ((Close[0] > Open[0])
    && (Close[1] > Open[1])
    && (Close[2] > Open[2]))
    {
    EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), 1.0845 , "");
    }

    }
    -------------------------------------------------------------------------------------------------------------------------------------

    When strategy meets the condition, the EnterLongStopMarket is created ok!
    When price is 1.0845 the Long position fills ok! the stop loss fills ok! and the profit target fills ok ! (see attached "one").
    But.... when price is == profit target, gives me an error and the strategy is turned off ( see attached two)

    Im running the strategy on a PlayBack connection.

    What is the problem? Could you help me please?
    Attached Files

    #2
    Hello fscabrera03,

    Thank you for the post.

    From the image you are getting an error stating that the price used was not correct for the order type used, This type of order would need to be placed on a specific side of the market.

    The error states that a buy stop market order was the reason. The EnterLongStopMarket code you used has a fixed price and it appears that would have been below the current market like the error states.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse,
      I dont understand, the 3 orders were filled ok.
      The fixed price was just for the test. My Requirement is:


      Create an order to BUY when a price is XXXX price above the actual market price.
      Set stop loss and take profit to this buy with X quantity of pips
      Is that simple but I dont resolve it

      Comment


        #4
        Hello fscabrera03,

        Thank you for the reply.

        I am not certain I understand what you are asking for help with here, are you asking how to calculate a price that's above market?

        The error you are seeing is because your orders price was not correct at the time the order was submitted.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you Jesse.
          That is the question, im not sure what it means "prcie was not correct at the time the order was submitted"
          I have placed the 3 orders above the market as is seen on the screenshots I attached.
          Strategy fails when price meet TP in this case

          Comment


            #6
            Hello fscabrera03,

            From your code you are using a fixed price with EnterLongStopMarket and the market will eventually move above that price. The order you are submitting has a specific requirement of being above the market. When the current market price moved above that fixed price the order will not be valid because the price you used is below the current market value.

            The target is not the source of the problem, the targets that would get submitted for a EnterLongStopMarket would be Sell type orders to exit the long position.

            You can try using a not fixed price for the EnterLongStopMarket, for example Close[0] + 10 * TIckSize which would be 10 ticks above the current close price.



            Please let me know if I may be of further assistance.


            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by MarianApalaghiei, Today, 10:49 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by love2code2trade, Yesterday, 01:45 PM
            4 responses
            28 views
            0 likes
            Last Post love2code2trade  
            Started by funk10101, Today, 09:43 PM
            0 responses
            8 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            37 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            8 responses
            46 views
            0 likes
            Last Post bill2023  
            Working...
            X