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

questions from New Subscriber

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

    questions from New Subscriber

    Hi

    A couple of questions maybe osomebody can help me with:

    1) How do I determine if a price tick is the first tick of a new bar

    2) How do I move a stop loss

    3) How do I specify the no of fx mini contracts

    Thanks



    Paul



    #2
    imported post

    Paul,

    1) Seethe Help Guide FirstTickOfBar property (this is only of value when CalculateOnBarClose == false)

    2) Are you submitting a stop loss via SetStopLoss() or ExitLongStop() or ExitShortStop()

    3) Any of the Enter() or Exit() methods have an optional quantity parameter or if not passed in, you can set the quantity when adding a strategy to a chart in the strategy dialogue window.

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Hi Ray



      I don't know - just looking at how to do it. Basically I want to place a market order with an initial stop loss then on the first tick of each new bar I want to move the stop loss to n pips from a moving average based level. Also if a certain other condition gets hit I want to close the position and obviously remove the stop loss. What would be the best way to implement this.



      Thanks for your help



      Paul


      Comment


        #4
        imported post

        Here is a snippet for the OnBarUpdate() method thatis an example that will do what you want.
        // This method will create a stop loss order 10 ticks from entry on incoming fill from an entry order
        if (Position.MarketPosition == MarketPosition.Flat)
        SetStopLoss(CalculationMode.Ticks, 10);

        // Go long if close is greater than 15 ticks above the 50 period SMA
        if (Close[0] > SMA(50)[0] + 15 * TickSize)
        EnterLong();

        // If long, change the stop price to 1 tick below the 50 period SMA
        if (Position.MarketPosition == MarketPosition.Long)
        SetStopLoss(CalculationMode.Price, SMA(50)[0] - TickSize);

        // Exit if close is less than 15 ticks above 50 period SMA and have been in trade 30 bars
        if (Close[0] < SMA(50)[0] + 15 * TickSize && BarsSinceEntry() >= 30)
        ExitLong();
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          Does this then mean that a stop loss can be changed once set for a trade?

          Part of my confusion on this is that your example...

          // If long, change the stop price to 1 tick below the 50 period SMA
          if (Position.MarketPosition == MarketPosition.Long) SetStopLoss(CalculationMode.Price, SMA(50)[0] - TickSize);
          ...is obviously for use in the OnBarUpdate() method, whereas the help file description of SetStopLoss() says it "should be called from within the strategy Initialize() method."

          So, have the rules changed on this? And what happens if additional SetStopLoss() calls are made for subsequent OnBarUpdate() calls? Will each one replace the last? And can we selectively replace the stop losses by specifying a "fromEntrySignal" parameter on each SetStopLoss() call?

          Comment


            #6
            imported post

            KBJ wrote:
            Does this then mean that a stop loss can be changed once set for a trade?
            Yes.

            Part of my confusion on this is that your example...
            // If long, change the stop price to 1 tick below the 50 period SMA if (Position.MarketPosition == MarketPosition.Long) SetStopLoss(CalculationMode.Price, SMA(50)[0] - TickSize);
            ...is obviously for use in the OnBarUpdate() method, whereas the help file description of SetStopLoss() says it "should be called from within the strategy Initialize() method."
            Documentation will be updated with the next release.

            So, have the rules changed on this? And what happens if additional SetStopLoss() calls are made for subsequent OnBarUpdate() calls? Will each one replace the last?
            Correct. Because of this, it is important to add a check in OnBarUpdate() for a flat position, and then call the SetStopLoss() method again and pass in the starting offset of a stop loss price when a new position is entered, otherwise the last known offset value will be used.
            And can we selectively replace the stop losses by specifying a "fromEntrySignal" parameter on each SetStopLoss() call?
            Yes you can.
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Rapine Heihei, Today, 08:19 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 08:25 PM
            0 responses
            6 views
            0 likes
            Last Post Rapine Heihei  
            Started by f.saeidi, Today, 08:01 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 07:51 PM
            0 responses
            8 views
            0 likes
            Last Post Rapine Heihei  
            Started by frslvr, 04-11-2024, 07:26 AM
            5 responses
            98 views
            1 like
            Last Post caryc123  
            Working...
            X