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 Brevo, Today, 01:45 AM
          0 responses
          6 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          3 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          384 views
          1 like
          Last Post Gavini
          by Gavini
           
          Started by oviejo, Today, 12:28 AM
          0 responses
          6 views
          0 likes
          Last Post oviejo
          by oviejo
           
          Working...
          X