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

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 fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,403 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          94 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          6 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          158 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          8 views
          0 likes
          Last Post Belfortbucks  
          Working...
          X