Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sporadic Draw.TextFixed() Refresh

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

    Sporadic Draw.TextFixed() Refresh

    I have the following code in a strategy to plot PnL and display the current dollar amount centered over the plot:

    Code:
    protected override void OnBarUpdate() {
    
    if (BarsInProgress != 0 || CurrentBar < 1)
        return;
    
    // Plot cumulative strategy PnL
    cumProfit = SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit;
    
    if (IncludeUnrealizedPnL)
        PnL[0] = cumProfit + Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency);
    else
        PnL[0] = cumProfit;
    
    if (PnL[0] > 0)
        PlotBrushes[0][0] = Brushes.Green;
    else if (PnL[0] < 0)
        PlotBrushes[0][0] = Brushes.Red;
    else
        PlotBrushes[0][0] = Brushes.Gray;
    
    Draw.TextFixed(this, "PnL", cumProfit.ToString("C"), TextPosition.Center, ChartControl.Properties.ChartText, pnlFont, Brushes.Transparent, Brushes.Transparent, 0);
    
    ...
    The plot works reliably, but the dollar amount only updates sporadically, sometimes on every bar, but often not for hours. Is there a way to force Draw.TextFixed() to refresh?
    Last edited by caveat_lector; 08-26-2021, 11:24 AM.

    #2
    Hello caveat_lector,

    Thanks for your post.

    In the DrawText you are using the variable cumProfit and I think you want to be using the data series PnL[0].


    Comment


      #3
      I initially wrote the code using the data series PnL[0] as shown below and had the sporadic dollar-value display problem. I thought that might have been due someway to converting a data series array value to a string and so changed the code to use cumProfit.ToString("C") as posted above.

      Code:
      Draw.TextFixed(this, "PnL", PnL[0].ToString("C"), TextPosition.Center, ChartControl.Properties.ChartText, pnlFont, Brushes.Transparent, Brushes.Transparent, 0)
      ;

      Both methods have exactly the same sporadic updating end-result.

      Comment


        #4
        Hello caveat_lector,

        Thanks for your reply.

        So the cumProfit variable is only updated when a trade completes. Does that match your observtion?

        If not I would suggest adding a print statement and print out the value of cumProfit on each OnBarUpdate() and compare to what is displayed.

        Comment


          #5
          The cumProfit variable updates as each trade completes unless IncludeUnrealizedPnL is set true, in which case it updates each time OnBarUpdate() runs with new primary data series data. There is nothing wrong with those aspects, because correct values are plotted and the plot updates on each bar as it should. The cumProfit value is correct. The problem is that Draw.TextFixed only updates the value it displays sporadically.

          Comment


            #6
            Hello caveat_lector,

            Thanks for your reply.

            Your code will not update cumProfit with UnrealizedPNL when selected. Only the series PnL[0] is updated when unrealizedPNL added.

            In short the Draw.Text with cumProfit as currently shown will only update as each trade completes.

            To verify, please add a print statement that outputs the bar time, cumprofit and Pnl[0].


            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            56 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            132 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            73 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 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