• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to add a straight line for each stop loss?

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

    How to add a straight line for each stop loss?

    I know how to add a straight for each signal I define, like MA cross. But I don't know how to add a straight line for each stop loss so that I can easily spot where I take loss.
    Please enlighten me. THANK YOU!

    #2
    Hello alantse123,

    Thanks for your post.

    Your statement/question is somewhat confusing. Can you clarify what you need help with specifically?

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      By adding the following code, I can see a straight line whenever my program enters/exits a position in the strategy analyser so that i can spot each entry and exit more easily.

      if (CrossAbove(EMA(10), EMA(20), 1))
      {
      EnterLong();
      Draw.VerticalLine(this, "tag1", 10, Brushes.Black);
      }
      if (CrossBelow(EMA(10), EMA(20), 1))
      {
      ExitLong();
      Draw.VerticalLine(this, "tag1", 10, Brushes.Black);
      }

      For exiting a position, a straight line can only be plot when the aforementioned signal appears. But there are two type of exits, one is by signal and one is by stop loss. How can I add a straight line whenever a stop loss is hit?

      SetStopLoss(CalculationMode.Currency, 500);

      and then what next?

      Thank you!!!

      Comment


        #4
        Hello alantse123,

        Thanks for your reply and clarification.

        So the issue is detecting when the set stop has been filled, not in drawing the line which is a vertical line.

        Just to check, do you see the text and marker notation on the charts that show the bar and the exact entry/exit point on the bar where the entry/exit occurs, along with their labels?

        The vertical lines you are drawing at drawn 10 bars before the entry or exit, I'm not sure how you relate that to entry/exits.

        To detect when the stoploss is filled,you can use the OnExecutionUpdate() method. Here is an example you can add in your code to test with:

        protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity,
        Cbi.MarketPosition marketPosition, string orderId, DateTime time)
        {
        if (execution.Name == "Stop loss") // note spelling of signal name must be exact.
        {
        Print("StopLoss filled price: "+execution.Price+" at: "+execution.Time );
        }


        Instead of printing as shown in the example you could assign the values to class level variables so that in OnBarUpdate() you could use the values to then draw the vertical line.

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          THANK YOU! I made it.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ralett, Today, 03:09 PM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by martyn73, Today, 02:54 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by Zigfried, Today, 01:59 PM
          3 responses
          9 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by giogio1, 11-10-2019, 11:21 PM
          2 responses
          30 views
          0 likes
          Last Post bltdavid  
          Started by w0lverine, Today, 12:39 PM
          4 responses
          9 views
          0 likes
          Last Post w0lverine  
          Working...
          X