Programatically plot horizontal STUDY line

Hello,

Is there a way to plot a study using AFL. I would like to use it to detect breaks of a horizontal Support or Resistance line. I know that there are other ways to plot a trendline, as described here and here.

I would like to initially plot it programatically, and then be able to move it on the chart afterwards, using the mouse.

Is this possible? I'm using AB v6.22.

Many thanks,
Paul

It's possible to do that but your description is little bit loose ,first you need to define the criteria for the support / resistance that you like to use it on your study , also it is necessary to comprehend the following function as it would help you in controlling your studies manually

GetCursorMouseButtons() ,
GetCursorXposition() ,
GetCursorYposition(),
GetAsyncKeyState(),
(( RequestMouseMoveRefresh() OR RequestTimedRefresh() ))

Also you can find here and here some good applications and examples for how to apply and use these functions

1 Like

Thanks Sebastian,

I simply want to programatically plot the horizontal line study just below the most recent low, on the chart.
And then be able to move the study with the mouse..
You seem to be implying that it difficult, given the AFL functions you have quoted.

Hello @polomora

If you think that, what @Sebastian provide for you is difficult, then you can follow the easier way.

Getting X, Y co-ordinates of Study()

How to detect the study crossover for multiple symbols with use of SCAN

1 Like

Thank you @PanoS for your valuable inputs , i just took the easy and short way and searched the forum instead :blush:

@polomora
No i did not intend to imply any difficulty but that is the way the work can be done through , i just pointed out to that way .. and it's not difficult as you think but you are still not familiar with it .. once you understand it you would realize that fact by yourself .

You should begin with reading the above articles thankfully attached by @PanoS , then your next step would be to use the below code as a practical example that you can develop later to be better than now to satisfy your want

Here's an initial proposed solution ...

Reset = ParamTrigger("Restore the default value for support level","Reset");


Bi = BarIndex();


// Getting Coordinations of Last Support  ... 

LL = Lowest_Low  = LLV(Low,3);
C1 = Condition   = Ref(LL,0) == Low AND Ref(LL,2) == Low;
LS = Last_Signal = ExRem(Cum(C1) == LastValue(Cum(C1)),0);
X1 = Bar_Index	 = ValueWhen(LS,Bi);
Y1 = Price_Value = ValueWhen(LS,Low);


// Controlling Manually Support Line ...

//RequestTimedRefresh(0.1);		// Can be used ONLY if you like to make support Level synchoronized while you hold down a long & continous mouse key press
KY = GetAsyncKeyState(17);
MB = GetCursorMouseButtons();
MY = GetCursorYPosition(0);


Counter = Nz(StaticVarGet("Counter"));


if (Reset OR !Counter)
{
	StaticVarSet("Manual_Support_Level",LastValue(Y1));
	StaticVarRemove("Counter");
}


if (KY < 0 AND MB == 9)
{
	StaticVarSet("Manual_Support_Level",MY);
	StaticVarSet("Counter",0);
	StaticVarAdd("Counter",Counter+1);
}


MSL = StaticVarGet("Manual_Support_Level");

SL  = Support_Level = LineArray(LastValue(X1),MSL,LastValue(Bi),MSL);


Plot(Close,"Close",colorDefault,styleBar);
Plot(SL,"Support Level",colorWhite,styleLine);

When you use the code it will automatically detect the last support and draw a line at that level then you can control that line manually by holding down Ctrl and then press the left button of your mouse ( Just one click )

-- BTW thanks back to Milosz for learning this technique :slight_smile: --

Then the support line would be displaced to the same level where you mouse is located at chart.

1 Like

For what it is worth, sequences like:

StaticVarSet("Counter",0);
StaticVarAdd("Counter",Counter+1);

make little sense and can be replaced by single line:

StaticVarSet("Counter",Counter+1);
2 Likes

Thank you @Tomasz for the hint :slight_smile:

Just a minor fix for Last_Signal Variable , it should be written in this way

LS = Last_Signal = ExRem(Cum(C1) == LastValue(Cum(IIf(ValueWhen(C1,Bi) <= LastValue(Bi)-2,C1,0))),0);
1 Like

Thanks all for the hints. I'll look at this later.

@Sebastian
Counter is of no use if number of click is not set ... anyway you are better coder then me :grin: so I guess you know :smiley:

if (Reset OR Counter>5)
if (KY < 0 AND MB == 9 AND Counter<=5)
1 Like

Hi @Fossil ,

When the user try to control support line manually , a number would be assigned to counter , that number is proposed to indicate how many time the user moved manually the support line."Number of Clicks"

So if no number set to counter , it simply mean the user prefer to keep the automatic default support level as it is with no further change


if (Reset OR Counter>5)

This peace of code means that the "control flow" will not reach inside the braces of the above condition until the number of counter is larger than 5 .... But What would be the result if the user chose to keep the default support level ?

No value in this case would be assigned to MSL, Unless you used the manual control and you would be forced to do that.

While if you used Reset , in this case the user would have a chance to change the position of support level ONLY for 5 times, After that he would be obliged to use the default support level which he might not be
ready / desire to use it !

2 Likes

@Sebastian
Didn’t check your code properly using Bar Replay.... so it’s my mistake.