Login Page - Create Account

Support Board


Date/Time: Thu, 18 Apr 2024 16:47:27 +0000



[Programming Help] - Study to manage position with breakeven and trailstop/target

View Count: 1600

[2021-04-03 18:29:58]
AlexPereira - Posts: 197
Hi,

so as mentioned here: is it possible to create a line "move SL to BE when touched"? , I am posting this study for Sierrachart that I use to manage positions with a adjustable breakeven and trailstop/target.

The study creates 3 drawings/subgrapths:
* Breakeven
* Trailtarget
* Trailstop.

Breakeven is kinda explanatory ( one detail, only is activated if stop is further away than configured offset. Also it only moves stop if it has at least an "offset" distance from where the stop will be put. ex: if offset is 4, even if breakeven line is reached, it will only move stop when there is at least 4 ticks difference from where stop will be put )

"Tailtarget" is the price that when touched, will move the stop into the "trailstop". When this happens, it will then increase ( or decrease depending on the direction of the trade ) the trailtarget and trailstop with the offset.

Also, if the position limit/target is within the offset, it will move the position limit/target further away.

This study needs a position with a stop and a target ( haven't used it with multiple targets/stops ). The breakeven and trailstop/target are configured through a percentage based between position stop and target ( it was used mainly for a strategy with fibonacci ratios.

Also, to adjust the breakeven and trailstop/targets, it has to be by keyboard shortcuts. Currently its hardcoded to listen to ACS_BUTTON_21 (breakeven) , ACS_BUTTON_22 (trailstop) and ACS_BUTTON_23 (trailtarget). Just set the mouse pointer in the chart on the price you wish to set and press the keyboard shortcut.
( documentation about setting these shortcuts: Advanced Custom Study Interaction With Menus, Control Bar Buttons, Pointer Events: ACS Control Bar Button Keyboard Shortcuts )


Disclaimer: I am just a programmer, so please don't use this on live accounts until you tested it in all your conditions. I used this together with a trading system based on swings and fibonacci ratios. But your usage may be very different than mine and it might not work the way you want it.
Also i am just uploading the dll, but if anyone really wants to use this, I don't mind posting the source code ( although I will have to look at what is currently being done in terms of licensing for posting SC studies source code )

Documentation of study parameters:

* Real:1/Simulation trading:0 -> if using the study live, set this to 1. If in simulation, set this to 0. always keep it in 0 unless you really tested it in your conditions.
* Auto Trail ON -> enable auto trail. if disabled (0), it will just do breakeven.
* Study Enabled -> if the study will do anything. if 0, the study will be disabled and not do anything.
* Trail Offset in ticks -> offset in ticks which will be the ticks to increase when trailing target reached and number of ticks offset of breakeven ( breakeven stop will be placed in position + this offset in ticks )
* Breakeven Style/Trail Target Style/Trail Stop Style -> the style of the graphs. configure it how you would do any other graph.
* Trail Target Ratio Fib -> The percentage where to place the trail target by default. the calculation will be the percentage from the position target into the position stop ( for example, draw a fib from the position target to position stop ).
* Trail Stop Ratio Fib -> Same as above but for the trail stop.
* Breakeven Ratio Fib -> Same as above but for breakeven.
* External ATR Study -> if you have an ATR study, you can point to that study and it will autoset the "Trail Offset in ticks" with its value.
* ATR Multiplier -> In case of setting the "Trail Offset in ticks" automatically, use this to apply a multiplier to that value. ( ex: atr is 10, if this field is 2, the offset is gonna be 20 )
* USE External ATR Study for ATR Offset -> 1 to enable the usage of the external ATR study. If 0, it will try to read the atr in a file in Sierrachart Data/conf/"NAME OF CHARTBOOK"/atr.conf
* Ticksize Multiplier -> multiplier for ticksize, mainly set this to 1, unless analysing a instrument and trading in another with a different tick size.

Hope it helps.
attachmentajp_study_position_64.dll - Attached On 2021-04-03 18:28:41 UTC - Size: 969.5 KB - 280 views
Attachment Deleted.
[2022-11-12 22:22:35]
SierraTraders - Posts: 67
downloaded study as it looks awsome
is there any updates
as im getting an error conf/realsim.conf

any suggestions thanks kindly

Version SC-2425-64-bit
[2023-03-24 02:17:19]
AlexPereira - Posts: 197
sorry for late reply and sorry, but no updates since I stopped using SC (at least in the meanwhile).

you can just create the file conf/realsim.conf , with 0 or 1 if real or simulation trading.

that setting will set up the studies that do trade management, and will update "Real=1/ Sim=0 Account" setting ( you can test changing it and reloading the study to see it changing ).

If you know c++ or know people that know c++, I can set up a github repo with the source code and make it available.

Let me know if interested!
[2024-03-21 03:28:05]
Ed C. - Posts: 98
I know C and C++, is it possible to gain access to the study source? Thanks!
[2024-03-23 18:59:25]
bradh - Posts: 853
I would like access to the source code too. I sent you a DM.

Brad at Forgiving Computers dot Com
[2024-03-25 22:45:57]
AlexPereira - Posts: 197
Hi,

I will put the source code in a github repo in the next few days. You can use it however you like, hope it helps!
[2024-03-31 19:44:38]
AlexPereira - Posts: 197
Hi,

Sorry for the delay, the code is here:

https://github.com/alexjp/sierrachart_ajp_study


I unfortunately haven't used SierraChart for some years, so don't know if it works at all in new versions of SierraChart. :(
[2024-04-01 16:57:47]
User61168 - Posts: 340
Thanks Alex. May I ask why you stopped using SC and which platform are you using now?
[2024-04-09 01:46:58]
AlexPereira - Posts: 197
Thanks Alex. May I ask why you stopped using SC and which platform are you using now?

Stopped using when AMP stopped giving SC free version. I think I bought then 6 months or 1 year more (don't really remember which one) but being subscription based is not great for me, because I have periods of trading and then periods almost off.

So I bought Motivewave, which is "Buy once" and then pay cheaper subscription yearly.

Anyway, SierraChart is a top platform, I do miss it, and I understand the need for subscription, but I am happy with Motivewave.

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

Login

Login Page - Create Account