Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 21:19:53 +0000



[Programming Help] - Retracement Levels not showing

View Count: 290

[2024-02-08 02:54:18]
User895355 - Posts: 55
I can't figure out why the RetracementLevels aren't showing up. The only level that shows is the %50 level. Any help would be greatly appreciated:

#include "sierrachart.h"

SCDLLName("My Risk Reward")

SCSFExport scsf_MyRiskReward(SCStudyInterfaceRef sc)
{
// Section 1 - Set the configuration variables and defaults
{
sc.GraphName = "My Risk Reward";
sc.AutoLoop = 0;
sc.GraphRegion = 0;
sc.ReceivePointerEvents = ACS_RECEIVE_POINTER_EVENTS_WHEN_ACS_BUTTON_ENABLED;
sc.BlockChartDrawingSelection = 0;

return;
}

// Section 2 - Do data processing here
int CONTROL_BTN = 10;
int &r_MenuID = sc.GetPersistentInt(13);
int &r_CheckedMenuID = sc.GetPersistentInt(14);
int &r_GreyedMenuID = sc.GetPersistentInt(15);
int &r_HideMenuID = sc.GetPersistentInt(16);
int &r_CheckedState = sc.GetPersistentInt(17);
int &r_SeparatorMenuID = sc.GetPersistentInt(18);
int &r_LineNumber = sc.GetPersistentInt(19);

if (sc.LastCallToFunction)
{
// Set default hover text and button text.
sc.SetCustomStudyControlBarButtonHoverText(CONTROL_BTN, "");
sc.SetCustomStudyControlBarButtonText(CONTROL_BTN, "");

// be sure to remove menu items when study is removed
sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, r_MenuID);
sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, r_SeparatorMenuID);
sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, r_CheckedMenuID);
sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, r_GreyedMenuID);
sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, r_HideMenuID);

return;
}

SCString Msg;
if (sc.UpdateStartIndex == 0)
{
sc.SetCustomStudyControlBarButtonHoverText(CONTROL_BTN, "My Risk Reward");
sc.SetCustomStudyControlBarButtonText(CONTROL_BTN, "RR");

if (r_MenuID <= 0)
{
r_MenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "My Risk Reward");

// add a menu separator
r_SeparatorMenuID = sc.AddACSChartShortcutMenuSeparator(sc.ChartNumber);
}

r_CheckedState = 1;

if (r_CheckedMenuID <= 0)
{
r_CheckedMenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Checked Toggle Menu Item");
sc.SetACSChartShortcutMenuItemChecked(sc.ChartNumber, r_CheckedMenuID, true);
}

if (r_GreyedMenuID <= 0)
r_GreyedMenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Greyed When Not Checked");

if (r_HideMenuID <= 0)
r_HideMenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Hidden When Not Checked");

if (r_MenuID < 0 || r_CheckedMenuID < 0 || r_HideMenuID < 0 || r_GreyedMenuID < 0)
{
Msg.Format("Add ACS Chart Shortcut menu item failed");
sc.AddMessageToLog(Msg, 1);
}
}

s_UseTool Tool;
Tool.Clear();
if (r_LineNumber != 0)
Tool.LineNumber = r_LineNumber;

// wait for an event
if (sc.MenuEventID != 0)
{
Tool.ChartNumber = sc.ChartNumber;
Tool.DrawingType = DRAWING_PRICE_PROJECTION;
Tool.LineStyle = LINESTYLE_DASH;
Tool.LineWidth = 1;
Tool.Color = RGB(255, 0, 255); // Magenta
Tool.AddMethod = UTAM_ADD_OR_ADJUST;
Tool.ShowPrice = 1;
Tool.ShowPercent = 1;
Tool.ShowLabels = 1;
Tool.RoundToTickSize = 0;
Tool.TextAlignment = DT_VCENTER; // label vertical alignment
Tool.ExtendRight = 1;
Tool.AddAsUserDrawnDrawing = 1;

Tool.RetracementLevels[0] = 10.0f;
Tool.RetracementLevels[1] = 23.6f;
Tool.RetracementLevels[2] = 50.0f;
Tool.LevelStyle[0] = LINESTYLE_DASH;
Tool.LevelColor[0] = COLOR_WHITE;
Tool.LevelStyle[1] = LINESTYLE_DASH;
Tool.LevelColor[1] = COLOR_WHITE;
Tool.LevelStyle[2] = LINESTYLE_DASH;
Tool.LevelColor[2] = COLOR_WHITE;

if (sc.PointerEventType == SC_POINTER_BUTTON_DOWN && sc.BlockChartDrawingSelection == 0)
{
sc.BlockChartDrawingSelection = 1;

Tool.BeginDateTime = sc.BaseDateTimeIn[sc.ActiveToolIndex];
Tool.EndDateTime = sc.BaseDateTimeIn[sc.ActiveToolIndex];
Tool.BeginValue = sc.ActiveToolYValue;
Tool.EndValue = sc.ActiveToolYValue;
Tool.ThirdValue = sc.ActiveToolYValue;
Tool.ThirdDateTime = sc.BaseDateTimeIn[sc.ActiveToolIndex];
}
else if (sc.PointerEventType == SC_POINTER_BUTTON_DOWN && sc.BlockChartDrawingSelection == 1)
{

sc.BlockChartDrawingSelection = 0;
if (sc.MenuEventID == ACS_BUTTON_10)
sc.SetCustomStudyControlBarButtonEnable(ACS_BUTTON_10, 0);
sc.GetPersistentInt(19) = 0;
sc.BlockChartDrawingSelection = 0;
Tool.Clear();
}
/* else if (sc.PointerEventType == SC_POINTER_BUTTON_UP)
{
if (sc.MenuEventID == ACS_BUTTON_10)
{
sc.SetCustomStudyControlBarButtonEnable(ACS_BUTTON_10, 0);
}
} */
/* else if (sc.PointerEventType == SC_POINTER_BUTTON_UP)
Msg.Append("Pointer Up Event, "); */

else if (sc.PointerEventType == SC_POINTER_MOVE && sc.BlockChartDrawingSelection == 1)
{
Tool.ThirdValue = sc.ActiveToolYValue;
}

if (sc.MenuEventID >= ACS_BUTTON_1 && sc.MenuEventID <= ACS_BUTTON_150)
{
Msg.AppendFormat("Got button event id %i, ", sc.MenuEventID);

if (sc.PointerEventType == SC_ACS_BUTTON_ON)
{
Msg.Append("ACS Button On Event, ");

// reset button to off
/* if (sc.MenuEventID == ACS_BUTTON_10)
sc.SetCustomStudyControlBarButtonEnable(ACS_BUTTON_10, 0); */
}
else if (sc.PointerEventType == SC_ACS_BUTTON_OFF)
Msg.Append("ACS Button Off Event, ");
}
else if (sc.MenuEventID == r_MenuID)
{
Msg.AppendFormat("Got menu event id %i, ", sc.MenuEventID);
}
else if (sc.MenuEventID == r_HideMenuID)
{
Msg.AppendFormat("Got hidden menu event id %i, ", sc.MenuEventID);
}
else if (sc.MenuEventID == r_GreyedMenuID)
{
Msg.AppendFormat("Got greyed menu event id %i, ", sc.MenuEventID);
}
else if (sc.MenuEventID == r_CheckedMenuID)
{
Msg.AppendFormat("Got checked menu event id %i, CheckedState=%i, ", sc.MenuEventID, r_CheckedState);

// toggle states
if (r_CheckedState == 0)
{
r_CheckedState = 1;
sc.SetACSChartShortcutMenuItemChecked(sc.ChartNumber, r_CheckedMenuID, true);
sc.SetACSChartShortcutMenuItemEnabled(sc.ChartNumber, r_GreyedMenuID, true);
sc.SetACSChartShortcutMenuItemDisplayed(sc.ChartNumber, r_HideMenuID, true);
}
else
{
r_CheckedState = 0;
sc.SetACSChartShortcutMenuItemChecked(sc.ChartNumber, r_CheckedMenuID, false);
sc.SetACSChartShortcutMenuItemEnabled(sc.ChartNumber, r_GreyedMenuID, false);
sc.SetACSChartShortcutMenuItemDisplayed(sc.ChartNumber, r_HideMenuID, false);
}
}

sc.UseTool(Tool);

r_LineNumber = Tool.LineNumber; // Remember line number which has been automatically set
Msg.Append("Y Value=");
Msg += sc.FormatGraphValue(sc.ActiveToolYValue, sc.GetValueFormat());

Msg.Append(", Bar Index=");
Msg += sc.FormatGraphValue(sc.ActiveToolIndex, 0);

sc.AddMessageToLog(Msg, 1);
}
}

Date Time Of Last Edit: 2024-02-08 02:55:12
[2024-02-08 03:57:07]
User43 - Posts: 101
I'd suspect that the settings you did in the Retracement Levels are not OK.

From the actual tool it looks like that there are 10 levels available for retracements, which are probably 0 - 9.

0 seems to be take to control the property of the leader line.

did you read the according section in the SC docu?
Using Drawing Tools From an Advanced Custom Study: s_UseTool::RetracementLevels[]

Looks like that the value setting in the retracement level float array also controls it's visibility.
When set to FLT_MAX the retracement is not visible.
But I do not know what value FLT_MAX actually represents.

You only want to draw 3 levels, so I think you should add settings to suppress the drawing of the the other 6 available settings which likely are by default 0.

I hope some of this helps to find the culprit.
[2024-02-08 06:12:33]
User895355 - Posts: 55
Thanks for your reply. But no, that's not it. I've looking at this example
scsf_UseToolExampleDrawingPriceProjection
which is a hard-coded example of levels. The difference in my application is that it's a drawing tool. I'm trying to create a Risk Reward tool that when clicked on the chart, the mousemove will establish the stop loss, and then using the retracement_levels display different risk/reward levels ie: 2:1, 3:1, etc. I know I could do this in with a couple of useTools() DRAWING_LINES, etc, but I was thinking I'd try it using retracement_levels as it seems as the functionality is similar to putting the Fibonacci study on the chart.
[2024-02-08 08:28:40]
User719512 - Posts: 264
When you put your drawing on the chart, right click it, properties, and inspect the Anchors for A, B, C and notice 2 of them, A,B are the same.
Use the Projection Tool manually and add 3 pts to your chart and determine what Anchors for that yield the desired result. From there, update your code to track that from initial mouse down to mouse up (or last known down position).
I am unclear on what exactly you want it to draw...but this might get you pointed in the right direction.
Date Time Of Last Edit: 2024-02-08 08:29:44
[2024-02-08 12:48:38]
User895355 - Posts: 55
Checking it out. Thanks.

Too bad I can't add a couple more lines to DRAWING_REWARD_RISK
[2024-02-08 14:27:40]
User43 - Posts: 101
Like user User719512 mentioned
You are setting the begin and end value to the same, that will result in all retracement lines being on top of each other.

Tool.BeginValue = sc.ActiveToolYValue;
Tool.EndValue = sc.ActiveToolYValue;


Try something like
Tool.BeginValue = sc.ActiveToolYValue;
Tool.EndValue = Tool.BeginValue + 10;

and you should see your 3 lines

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

Login

Login Page - Create Account