Custom indicator Plotting horizontal lines at User specified price increments
Custom indicator Plotting horizontal lines at User specified price increments
09 Nov 2024, 01:33
I have modified a code in pine script to plot horizontal line on tradingview, I am currently trying to do the same in ctrader but to no avail.
This is what i have so far for code in Ctrader. My problem is getting the output correct
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
public class poop : Indicator
{
[Parameter("Number of Lines")]
public DataSeries NOL { get; set; } // User defines the number of lines
[Parameter("Price Increments", DefaultValue = 14)]
public int INC { get; set; } // User defines the price step increment depending on instrument they are trading
[Output("Main", LineColor = "Purple")]
public IndicatorDataSeries Result { get; set; }
protected override void Initialize()
{
var NOL = Chart.DrawHorizontalLine("line", Bars.HighPrices.Maximum(999), Color.Purple);
NOL.IsLocked = true;
}
public override void Calculate(int index)
{
}
}
}
This is the code i used in pine
study("HRT", shorttitle="SAPHIR", overlay=true)
toadd = 0.
incval = 0.
selectedprice = 0.
background = 0.
line1 = 0.
line2 = 0.
selectedprice := input(title="Type Your Start Price Here", type=input.float, defval=0)
incval := input(title="Increment Value", type=input.float, defval=0)
toadd := incval
bool h = close > (selectedprice+toadd)
bool l = close < (selectedprice-toadd)
alertcondition(h, title="Cross UP", message="{{ticker}} crossed {{close}}") //alert for when the price crosses the first upper interval
alertcondition(l, title="Cross DOWN", message="{{ticker}} crossed {{close}}") //alert for when the price crosses the first lower interval
alertcondition(h or l, title="Cross UP/DOWN", message="{{ticker}} crossed {{close}}") //alert for when the price crosses the first lower interval
plot(selectedprice+(toadd*0), title='Line', color=color.new(color.purple, 50), linewidth=1, style=plot.style_line, trackprice=true) //base line
plot(selectedprice+(toadd*1), title='Line', color=color.new(color.purple, 50), linewidth=1, style=plot.style_line, trackprice=true) // 160 lines
plot(selectedprice+(toadd*2), title='Line', color=color.new(color.purple, 50), linewidth=1, style=plot.style_line, trackprice=true)
plot(selectedprice+(toadd*3), title='Line', color=color.new(color.purple, 50), linewidth=1, style=plot.style_line, trackprice=true)
Replies
SaphirSpecs
11 Nov 2024, 15:03
( Updated at: 12 Nov 2024, 06:20 )
RE: Custom indicator Plotting horizontal lines at User specified price increments
PanagiotisCharalampous said:
so I’m not really fam with coding on this platform and currently the code does plot horizontal lines on the workspace.
the ideal output is
-user defines (current) price at which the algo starts plotting horizontal lines
-user defines increment at which each horizontal line is plotted
for example ( Gold 2000, 3, 100)
algo plots a horizontal line each $3
currently my code gives me the prompts for each parameter but does not even plot a single line.
ideally the code would plot automatically using a for loop. But worst case scenario I can manually enter the code for each line
Hi there,
Can you explain your issue in more detail? What do you expect your code to do and what does it do instead?
Best regards,
Panagiotis
@SaphirSpecs
SaphirSpecs
11 Nov 2024, 15:03
( Updated at: 12 Nov 2024, 06:20 )
RE: Custom indicator Plotting horizontal lines at User specified price increments
PanagiotisCharalampous said:
so I’m not really fam with coding on this platform and currently the code does plot horizontal lines on the workspace.
the ideal output is
-user defines (current) price at which the algo starts plotting horizontal lines
-user defines increment at which each horizontal line is plotted
for example ( Gold 2000, 3, 100)
algo plots a horizontal line each $3
currently my code gives me the prompts for each parameter but does not even plot a single line.
ideally the code would plot automatically using a for loop. But worst case scenario I can manually enter the code for each line
Hi there,
Can you explain your issue in more detail? What do you expect your code to do and what does it do instead?
Best regards,
Panagiotis
@SaphirSpecs
PanagiotisCharalampous
12 Nov 2024, 06:25
RE: RE: Custom indicator Plotting horizontal lines at User specified price increments
SaphirSpecs said:
PanagiotisCharalampous said:
so I’m not really fam with coding on this platform and currently the code does plot horizontal lines on the workspace.
the ideal output is-user defines (current) price at which the algo starts plotting horizontal lines
-user defines increment at which each horizontal line is plotted
for example ( Gold 2000, 3, 100)
algo plots a horizontal line each $3
currently my code gives me the prompts for each parameter but does not even plot a single line.
ideally the code would plot automatically using a for loop. But worst case scenario I can manually enter the code for each lineHi there,
Can you explain your issue in more detail? What do you expect your code to do and what does it do instead?
Best regards,
Panagiotis
Hi there,
I tried your indicator and it plots the lines fine.
So I do not see a problem.
Best regards,
@PanagiotisCharalampous
SaphirSpecs
12 Nov 2024, 16:33
RE: RE: RE: Custom indicator Plotting horizontal lines at User specified price increments
PanagiotisCharalampous said:
SaphirSpecs said:
PanagiotisCharalampous said:
so I’m not really fam with coding on this platform and currently the code does plot horizontal lines on the workspace.
the ideal output is-user defines (current) price at which the algo starts plotting horizontal lines
-user defines increment at which each horizontal line is plotted
for example ( Gold 2000, 3, 100)
algo plots a horizontal line each $3
currently my code gives me the prompts for each parameter but does not even plot a single line.
ideally the code would plot automatically using a for loop. But worst case scenario I can manually enter the code for each lineHi there,
Can you explain your issue in more detail? What do you expect your code to do and what does it do instead?
Best regards,
Panagiotis
Hi there,
I tried your indicator and it plots the lines fine.
So I do not see a problem.
Best regards,
Hey there,
Thanks for trying out the code. However the issue is that it's not supposed to just plot one line. It supposed to plot multiple lines as defined by the User. Could you share the code you used to get it to plot a line ? Cause I was not able able able to get my code to plot a single line.
Thank you in advance.
@SaphirSpecs
SaphirSpecs
12 Nov 2024, 16:33
RE: RE: RE: Custom indicator Plotting horizontal lines at User specified price increments
PanagiotisCharalampous said:
SaphirSpecs said:
PanagiotisCharalampous said:
so I’m not really fam with coding on this platform and currently the code does plot horizontal lines on the workspace.
the ideal output is-user defines (current) price at which the algo starts plotting horizontal lines
-user defines increment at which each horizontal line is plotted
for example ( Gold 2000, 3, 100)
algo plots a horizontal line each $3
currently my code gives me the prompts for each parameter but does not even plot a single line.
ideally the code would plot automatically using a for loop. But worst case scenario I can manually enter the code for each lineHi there,
Can you explain your issue in more detail? What do you expect your code to do and what does it do instead?
Best regards,
Panagiotis
Hi there,
I tried your indicator and it plots the lines fine.
So I do not see a problem.
Best regards,
Hey there,
Thanks for trying out the code. However the issue is that it's not supposed to just plot one line. It supposed to plot multiple lines as defined by the User. Could you share the code you used to get it to plot a line ? Cause I was not able able able to get my code to plot a single line.
Thank you in advance.
@SaphirSpecs
PanagiotisCharalampous
13 Nov 2024, 06:35
RE: RE: RE: RE: Custom indicator Plotting horizontal lines at User specified price increments
SaphirSpecs said:
PanagiotisCharalampous said:
SaphirSpecs said:
PanagiotisCharalampous said:
so I’m not really fam with coding on this platform and currently the code does plot horizontal lines on the workspace.
the ideal output is-user defines (current) price at which the algo starts plotting horizontal lines
-user defines increment at which each horizontal line is plotted
for example ( Gold 2000, 3, 100)
algo plots a horizontal line each $3
currently my code gives me the prompts for each parameter but does not even plot a single line.
ideally the code would plot automatically using a for loop. But worst case scenario I can manually enter the code for each lineHi there,
Can you explain your issue in more detail? What do you expect your code to do and what does it do instead?
Best regards,
Panagiotis
Hi there,
I tried your indicator and it plots the lines fine.
So I do not see a problem.
Best regards,
Hey there,
Thanks for trying out the code. However the issue is that it's not supposed to just plot one line. It supposed to plot multiple lines as defined by the User. Could you share the code you used to get it to plot a line ? Cause I was not able able able to get my code to plot a single line.
Thank you in advance.
Hi there,
I used the code you shared. If you want to plot several lines, you need to write the relevant code i.e. a for loop where you will plot lines at different increments.
Best regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
09 Nov 2024, 12:48
Hi there,
Can you explain your issue in more detail? What do you expect your code to do and what does it do instead?
Best regards,
Panagiotis
@PanagiotisCharalampous