Login Page - Create Account

Support Board


Date/Time: Thu, 06 Mar 2025 19:26:00 +0000



Post From: ACSIL string

[2022-02-07 13:03:25]
User909252 - Posts: 20
Here is the code. Figured it would be simple enough.


#include "sierrachart.h"

SCDLLName("Prefixer")

SCSFExport scsf_Prefixer(SCStudyInterfaceRef sc)
{
  int& MenuID = sc.GetPersistentInt(1);
  if (sc.SetDefaults)
  {
    sc.GraphName = "Drawing Prefixer";
    sc.AutoLoop = 1; //Automatic looping is enabled.
    sc.Input[0].Name = "Prefix";
    sc.Input[0].SetString("");
    sc.GraphRegion = 0;
    return;
  }
  
  
  if (sc.Index == 0)// Only do this when calculating the first bar.
  {
    // Add chart short cut menu item
    if (MenuID <= 0)
      MenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Update Drawings");

    if (MenuID < 0)
      sc.AddMessageToLog("Add ACS Chart Shortcut Menu Item failed", 1);
  }

  if (sc.MenuEventID != 0 && sc.MenuEventID == MenuID){
    int DrawingIndex = 0;
    s_UseTool DrawingObject;
    const SCString Prefix = sc.Input[0].GetString();
    while( sc.GetUserDrawnChartDrawing(sc.ChartNumber, DRAWING_HORIZONTAL_RAY , DrawingObject, DrawingIndex) )
    {
      int strLen = DrawingObject.Text.GetLength();
      const SCString curStr = DrawingObject.Text.GetSubString(strLen);
      sc.AddMessageToLog(curStr,1);
      sc.AddMessageToLog(Prefix,1);
      if(curStr!=Prefix){
        DrawingObject.Text = Prefix + " " + DrawingObject.Text;
        DrawingObject.TextAlignment = DrawingObject.TextAlignment;
        sc.UseTool(DrawingObject);
      }
      DrawingIndex++;
    }
  }
  
  if (sc.LastCallToFunction)
  {
    // Be sure to remove the menu command when study is removed
    sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, MenuID);
  }
}


curString and Prefix will output fine to the message log, and will be the same, yet it will continue to add the prefix to the text.
As you can see, it also moves the text from bottom of line to top of line.

Draw a horizontal ray, then right click the chart and do Update Drawings.

Ideally I wanted this to run automatically after a new drawing is added but it doesn't really need to run on every tick or every new candle so I couldn't find another way to do it besides a menu option.
Date Time Of Last Edit: 2022-02-07 13:04:05