Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to plot exit orders on chart

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

    How to plot exit orders on chart

    My strategy exits a trade based on the value of the high or low of the previous bar. I would like to plot those values on the chart. For example: (High[0] == (High[1] + (2 * TickSize)) )

    I was thinking this: AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.Dash, 2), PlotStyle.Square, (High[0] == (High[1] + (2 * TickSize)) ));

    Added it to the exit order and couldn't get it to work.

    if (High[0] == (High[1] + (2 * TickSize)) )
    {
    ExitShort();

    AddPlot(new Stroke(Brushes.SeaGreen, DashStyleHelper.Dash, 2), PlotStyle.Square, (High[0] == (High[1] + (2 * TickSize)) ));

    }

    Guess there is a little more to it than I thought. A little help please!

    #2
    Hello EminiMES,

    Thank you for your note.

    If you wanted to plot that value in a plot for each bar, you wouldn't want to specify that in the AddPlot statement itself, rather, you'd create the plot and then assign that value to it on each bar within OnBarUpdate.

    I've created a simple example script that plots this on the chart, enters short after 2 down bars in a row, and exits if the high of the current bar exceeds this value.

    Please let us know if we may be of further assistance to you.

    Attached Files

    Comment


      #3
      Thanks Kate....

      I'm thinking maybe an indicator would be better instead of placing it in the strategy itself. Something like the pic below is what I want. I just want to visualize on the chart where the high +2 ticks and the low - 2 ticks from the previous bar is located. I want it to update at the open of each new bar.

      Comment


        #4
        Hello EminiMES,

        Thank you for your reply.

        You could do that with Draw.Line and draw a line at those prices based on the prior bar. I'm attaching a modified version of the prior example that does just this. If we are not on the same bar as the entry and the current price exceeds the high plus two ticks or the low minus two ticks, the position is exited. While in the position, on the first tick of the next bar after the entry we start drawing lines using drawing objects to represent those levels. When we exit the position, the lines are removed. The lines are updated to the prior bar values on each new bar's first tick.

        Please let us know if we may be of further assistance to you.
        Attached Files

        Comment


          #5
          Thanks Kate...

          I guess I should have told you that I run the strategy on a 5 minute bar. When the trade is entered it does not draw the lines until the next bar. I need it to draw them upon entry. Also, if it's not to much trouble could you add long entry and exit logic which is just the opposite of the short logic. Not sure if it makes a difference on the drawing of the lines.

          I really appreciate everything!

          Comment


            #6
            Hello EminiMES,

            Thank you for your reply.

            It should be noted that the samples we provide are intended to give you further direction to move forward, and are not intended to be used for copy and paste purposes or live trading.

            If you wish for the lines to be drawn as soon as the position is updated, you would simply need to remove the && IsFirstTickOfBar in the conditions for drawing those. Since the points at which you're exiting are the same regardless of whether its a long or short position, you can combine those together (Exit orders are only triggered if there's a position in that direction, so it will ignore whichever one you're not in the position for).

            For the drawing of the lines you'd just basically reverse the tags and line colors if the position is long.

            See below:

            Code:
             protected override void OnBarUpdate()
            {
            if (CurrentBar < 1)
            return;
            
            if(Position.MarketPosition == MarketPosition.Short)
            {
            // In Short Position, drawing lines
            Draw.Line(this, "MyTarget", 10, Low[1] - (2*TickSize), 0, Low[1] - (2*TickSize), Brushes.Green);
            Draw.Line(this, "MyStop", 10, High[1] + (2*TickSize), 0, High[1] + (2*TickSize), Brushes.Red);
            }
            else if (Position.MarketPosition == MarketPosition.Long)
            {
            // In Long Position, drawing lines
            Draw.Line(this, "MyStop", 10, Low[1] - (2*TickSize), 0, Low[1] - (2*TickSize), Brushes.Red);
            Draw.Line(this, "MyTarget", 10, High[1] + (2*TickSize), 0, High[1] + (2*TickSize), Brushes.Green);
            }
            
            // if the last 2 bars were down bars, enter short
            if(Close[0] < Open[0] && Close[1] < Open[1] && Position.MarketPosition == MarketPosition.Flat)
            {
            // Entering Short 
            EnterShort();
            }
            
            // if the last 2 bars were up bars, enter long
            if(Close[0] > Open[0] && Close[1] > Open[1] && Position.MarketPosition == MarketPosition.Flat)
            {
            // Entering Long
            EnterLong();
            }
            
            if((Close[0] >= High[1] + (2*TickSize) || Close[0] <= Low[1] - (2*TickSize)) && Position.MarketPosition != MarketPosition.Flat)
            {
            //Exiting any open position since the conditions for exit are the same whether it's a long or short
            ExitShort();
            ExitLong();
            // Removing Draw objects
            RemoveDrawObject("MyTarget");
            RemoveDrawObject("MyStop");
            }
            }
            Please let us know if we may be of further assistance to you.

            Comment


              #7
              Thanks Kate....

              Not sure why but when I went to test, it kept placing orders rapidly until I shut it down.

              Comment


                #8
                Hello EminiMES,

                Thank you for your reply.

                That would be because there's nothing to tell it not to enter again on a bar that's just had an exit, and it runs OnPriceChange, so if an exit is made but conditions are still correct for entry, it would enter again on the same bar. You can use BarsSinceExitExecution in your conditions for entry to prevent entries on the same bar as you've just exited on:



                Please let us know if we may be of further assistance to you.

                Comment


                  #9
                  Thanks Kate.... I have used that logic before so I understand what to do. I will update once completed and tested. Have to wait now for the market to open once again. Can a strategy be tested using market replay?

                  Comment


                    #10
                    Hello EminiMES,

                    Thank you for your reply.

                    Yes, strategies may be tested using Market Replay data in the Playback connection. The one thing to make sure of is that you use an instance of the strategy that is set to use the Playback account.

                    Please let us know if we may be of further assistance to you.

                    Comment


                      #11
                      Thanks Kate... I was able to figure it out over the weekend. I do have another request with regard to the PlotExitPointExample and DrawExitLinesExample that you provided. Is there a way to add price markers so that the prices are readily viewable?

                      Comment


                        #12
                        Hello EminiMES,

                        You could use Draw.Text to draw the price the line is placed at just above or below the line on the current bar, that'd probably be the easiest route:



                        Please let us know if we may be of further assistance to you.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NullPointStrategies, Today, 05:17 AM
                        0 responses
                        52 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        130 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        70 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        44 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        49 views
                        0 likes
                        Last Post TheRealMorford  
                        Working...
                        X