Login Page - Create Account

Support Board


Date/Time: Sat, 11 Jan 2025 17:42:12 +0000



Setting sc.Subgraph[].TextDrawStyleText dynamically

View Count: 1385

[2016-12-10 18:27:31]
binaryduke - Posts: 373
Is it possible to set sc.Subgraph[].TextDrawStyleText dynamically within a custom study so that depending upon the value of the Subgraph, a different text string is displayed? My attempts so far are failing and only the first value that TextDrawStyleText is set to is displayed, even if the code later changes the vale of TextDrawStyleText.

As an aside, it would be great to have a DrawStyle similar to CustomValueAtY that could display a variable text value.
[2016-12-10 19:02:24]
Sierra Chart Engineering - Posts: 104368
Yes you definitely can. If this is not working properly, then it is because there is a problem in your code. We verified this can be changed at any time just by assigning a new text string. It is simple as that.

Here is the test we put together:
  SCString NumberString;
  NumberString.Format("%u", sc.Index);
  SecondSubgraph.TextDrawStyleText = NumberString;
  SecondSubgraph[sc.Index] = sc.Close[sc.Index];

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2016-12-11 16:23:09]
binaryduke - Posts: 373
Thank you. I have tested based upon your example as below and I receive the same Index value displayed at the base of every bar, i.e. it is not displaying an incrementing value:


#include "sierrachart.h"

SCDLLName("TextDrawStyleTextTest")

SCSFExport scsf_TemplateFunction1(SCStudyGraphRef sc)
{
  // Set the configuration variables
  
  if (sc.SetDefaults)
  {
    
    
    sc.GraphName = "TextDrawStyleTextTest1";
    sc.GraphRegion = 0;
    sc.AutoLoop = 1; // true

    // During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 0;

    sc.Subgraph[0].Name = "TextTest";
    sc.Subgraph[0].DrawStyle = DRAWSTYLE_TEXT;
    
    return;
  }
  
  
  // Data processing
  
  SCString DisplayString;
  DisplayString.Format("%u", sc.Index);
sc.Subgraph[0].TextDrawStyleText = DisplayString;
  sc.Subgraph[0][sc.Index] = sc.Low[sc.Index] - (2 * sc.TickSize);
}


I am aiming to display text that is conditional based upon the bar (or my indicator), i.e.


#include "sierrachart.h"

SCDLLName("TextDrawStyleTextTest")

SCSFExport scsf_TemplateFunction1(SCStudyGraphRef sc)
{
  // Set the configuration variables
  
  if (sc.SetDefaults)
  {
    
    
    sc.GraphName = "TextDrawStyleTextTest1";
    sc.GraphRegion = 0;
    sc.AutoLoop = 1; // true

    // During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 0;

    sc.Subgraph[0].Name = "TextTest";
    sc.Subgraph[0].DrawStyle = DRAWSTYLE_TEXT;
    
    return;
  }
  
  
  // Data processing
  
  SCString DisplayString;

  // Display a string based upon the last price in the bar

  if (sc.Close[sc.Index] == sc.Close[sc.Index - 1])
  {
    DisplayString = "Unchanged";
  }
  else if (sc.Close[sc.Index] > sc.Close[sc.Index - 1])
  {
    DisplayString = "Higher";
  }
else
  {
    DisplayString = "Lower";
  }
  sc.Subgraph[0].TextDrawStyleText = DisplayString;
  sc.Subgraph[0][sc.Index] = sc.Low[sc.Index] - (2 * sc.TickSize);
}

however as with the code based upon your example, this repeats a single string for every bar based upon the conditional result of the first bar.

Am I missing something based upon AutoLoop perhaps?
Date Time Of Last Edit: 2016-12-11 16:37:08
[2016-12-11 18:55:24]
Sierra Chart Engineering - Posts: 104368
All displayed elements of a particular Subgraph using the Text Draw Style will display the same string value.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account