Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawline not as expected.

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

    Drawline not as expected.

    Hi I have a DrawLine:

    DrawLine("stop" + CurrentBar, false, fillBar, pStop.StopPrice, CurrentBar, pStop.StopPrice ,Color.Blue,DashStyle.DashDotDot,3);

    it is in OnBarUpdate for min bars and is drawn when their is a position. I expect the line to appear from the bar when the system has a position to when it no longer has a position:-

    if(Position.MarketPosition != MarketPosition.Flat)
    {

    DrawLine("stop" + CurrentBar, false, fillBar, pStop.StopPrice, CurrentBar, pStop.StopPrice ,Color.Blue,DashStyle.DashDotDot,3);
    }


    However when I apply it to a chart the lines are plotted right at the begining of the chart.

    What am I missing?

    #2
    GKonheiser, would be likely an issue with the fillbar variable? So it would not correctly update and thus reach back further than you would expect if you have a position on later in OnBarUpdate()?

    I would replace first the drawing to use for example something like a dot to really see if it's your condition or something else.

    Comment


      #3
      OK I will try that and also step thou with MS VS. But this is where I set fillbar,

      protected override void OnExecution(IExecution execution)
      {
      if(this.indPivAverage.ExtrnTrend[0] == 1) // OnExecution long trades
      {
      if (pEntry != null && pEntry == execution.Order)
      {
      if ( execution.Order.OrderState == OrderState.Filled
      || execution.Order.OrderState == OrderState.PartFilled
      || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)
      )
      {
      // Stop order
      pStop = ExitLongStop(0, true, execution.Order.Filled, lPiv - stop * TickSize, "Stop of Long", "pEntry");

      // Resets the entryOrder object to null after the order has been filled
      if (execution.Order.OrderState != OrderState.PartFilled)
      {
      longPrice = pEntry.AvgFillPrice;
      pEntry = null;
      fillBar = CurrentBar; // for the drawline
      }
      }
      }


      I dont think the dot will tell me anything as the lines are ALL right at the start of the chart

      Comment


        #4
        I just stepped through the code watching the int fillBar and it apears to behave as expected, it gets its bar value when an order is filled, the first order starting at bar 4317, so im not sure why the drawline is behaving this way?

        Comment


          #5
          GKonheiser, think it's working then as expected, since the int you supply to the DrawLine is not an absolute bar number but bars ago, so relative from where it's called to draw. So you actually want to start at CurrentBar - fillBar I feel.

          Comment


            #6
            I set fillBar=CurrentBar when an order if filled, is CurrentBar not an absolute bar number. The point of the line is to draw where the stop level for the order is while there is a posiiton. So to start at the CurrentBar when whe order is first filled ( fillBar = CurrentBar ) and to sotp drawing at the current bar before there is no longer a position so ,

            if(Position.MarketPosition != MarketPosition.Flat)
            {

            DrawLine("stop" + CurrentBar, false, fillBar, pStop.StopPrice, CurrentBar, pStop.StopPrice ,Color.Blue,DashStyle.DashDotDot,3);
            }

            Comment


              #7
              GKonheiser, no, it would be the # of bars ago you wanted to start. If set the barnumber literally in, you would actually reach ~4k bars back as the starting point - which is not what you want to see.

              Comment


                #8
                ah i get it, so i want it to start at CurrentBar - fillBar.

                Comment


                  #9
                  That working much better now, thanks very much.

                  The line is now being draw from when their is a position to when the position is closed.

                  But I also have the stop moved during the life of the position and only want the line to reflect the current stop position at the time , at the moment it draws the original line and all subsequent altered line
                  s starting when the order was first filled.

                  Is there a way to do this?

                  Comment


                    #10
                    Yes, that would be possible, however would need a different approach - currrenly you always create a new line via providing a unique tag each bar ("stop" + CurrentBar) - what you want to do only creating a new line once the stop changes, so it would show the visual trail, of course that would change your bars ago calcs for the line as well, since you then only draw the new segment of the stop trail.

                    Comment


                      #11
                      OK thanks I will give it a go

                      Comment


                        #12
                        Originally posted by GKonheiser View Post
                        I set fillBar=CurrentBar when an order if filled, is CurrentBar not an absolute bar number. The point of the line is to draw where the stop level for the order is while there is a posiiton. So to start at the CurrentBar when whe order is first filled ( fillBar = CurrentBar ) and to sotp drawing at the current bar before there is no longer a position so ,

                        if(Position.MarketPosition != MarketPosition.Flat)
                        {

                        DrawLine("stop" + CurrentBar, false, fillBar, pStop.StopPrice, CurrentBar, pStop.StopPrice ,Color.Blue,DashStyle.DashDotDot,3);
                        }
                        Your syntax is wrong. That line is drawing from the start of the chart to the fillBar. Correct for what you described would be:
                        Code:
                        DrawLine("stop" + CurrentBar, false, [B][COLOR=Red]CurrentBar - fillBar[/COLOR][/B], pStop.StopPrice, [COLOR=Red][B]0[/B][/COLOR], pStop.StopPrice ,Color.Blue,DashStyle.DashDotDot,3);
                        ref: DrawLine(string tag, bool autoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Color color, DashStyle dashStyle, int width)
                        Last edited by koganam; 03-06-2014, 08:54 AM.

                        Comment


                          #13
                          Hi koganam,

                          thanks for the heads up. Thats what I ended up with. I misread/understood the point you mentioned.

                          Thanks

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          656 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          371 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          109 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          579 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X