any idea of making high/low on specific bar?
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: any idea of making high/low on specific bar?
If you define 'specific bar' as a certain bar number for the current day, you could use something like (untested):
Code: Select all
Variables:
barOfDay(0);
if (BarStatus(1) = 2) then begin
if (Date <> Date[1]) then
barOfDay = 0;
barOfDay = barOfDay + 1;
if (barOfDay = 4) then begin
Print("The high on the fourth intraday bar is: ", High);
Print("The low on the fourth intraday bar is: ", Low);
end;
end;
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: any idea of making high/low on specific bar?
Do you meanamm.. how i can compile this?
(a) I do not know how to compile in the PowerLanguage Editor, or
(b) The code cannot compile due to an error?
For (a), see:
Editing study scripts in the PowerLanguage Editor
Using studies in the PowerLanguage Editor
For (b), share the error message you got (or the unexpected behaviour you experienced) and what you've tried so far.
Re: any idea of making high/low on specific bar?
hi just wanna say, best support ever.
i want to mark on the graph, something like high/low of the first 30 mins bar.
if i am more specif...
i want to mark on the graph, something like high/low of the first 30 mins bar.
if i am more specif...
- Andrew MultiCharts
- Posts: 1587
- Joined: 11 Oct 2011
- Has thanked: 931 times
- Been thanked: 559 times
Re: any idea of making high/low on specific bar?
You can plot high or low of the first bar on each bar on the chart only if you don't reference any passed values in your code and MaxBarsBack setting of the indicator is set to 0.
Code: Select all
Var: x(0);
once X=high;
Plot1(X);
Re: any idea of making high/low on specific bar?
am not so good in writing a code, i know how to open the PL and how create a study, but i dont kow what to write in it.
i just want to have a visble box of high/low of the first 30 min candle of the day.
i think it`s not so complicated and we can use the day_of_week but change a few lines to adjust it 30 mins first bar of the day.
i didnt change anything yet because i dont understand the parameters in this code.
eyal.
i just want to have a visble box of high/low of the first 30 min candle of the day.
i think it`s not so complicated and we can use the day_of_week but change a few lines to adjust it 30 mins first bar of the day.
Code: Select all
using System;
using System.Drawing;
namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class Day_of_Week : IndicatorObject
{
private IPlotObject Plot1;
private IPlotObject Plot2;
public Day_of_Week(object ctx) :
base(ctx)
{
dayofwk = DayOfWeek.Monday;
}
protected override void Create(){
Plot1 =
AddPlot(new PlotAttributes("Plot1", EPlotShapes.BarHigh,
Color.Cyan, Color.Empty, 0, 0,
true));
Plot2 =
AddPlot(new PlotAttributes("Plot2", EPlotShapes.BarLow,
Color.Cyan, Color.Empty, 0, 0,
true));
}
[Input]
public DayOfWeek dayofwk { get; set; }
protected override void CalcBar(){
if ((Bars.Time[0].DayOfWeek == dayofwk)){
Plot1.Set(0, Bars.High[0]);
Plot2.Set(0, Bars.Low[0]);
Alerts.Alert();
}
}
}
}
eyal.
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: any idea of making high/low on specific bar?
The code you posted is MultiCharts .NET, while you posted this topic in the general MultiCharts forum.
Since you mention 'change a few lines from the code' (and talked about helpful replies when those replies addressed MultiCharts and not MultiCharts .NET), it's still not obvious to me which platform you use: do you want help with MultiCharts .NET or do you want MultiCharts code based on that MultiCharts .NET code?
Please put more effort in your posts; that makes helping easier and more efficient.
Since you mention 'change a few lines from the code' (and talked about helpful replies when those replies addressed MultiCharts and not MultiCharts .NET), it's still not obvious to me which platform you use: do you want help with MultiCharts .NET or do you want MultiCharts code based on that MultiCharts .NET code?
Please put more effort in your posts; that makes helping easier and more efficient.
Re: any idea of making high/low on specific bar?
i didnt realized the different sorry, am using multicharts.net
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: any idea of making high/low on specific bar?
One way to do that is with the following code:
Which looks like:
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator
{
[SameAsSymbol(true), UpdateOnEveryTick(false), SkipIdenticalTicks(true)]
public class SessionTimePlotFirstHalfHour : IndicatorObject
{
private IPlotObject openRangeHigh, openRangeLow;
private double highOpenRange, lowOpenRange = 9999;
public SessionTimePlotFirstHalfHour(object _ctx) : base(_ctx) { }
protected override void Create()
{
// Line plots do not work here due to the plot object's Reset() method
// not actually removing the plot for that bar
// http://www.multicharts.com/discussion/viewtopic.php?f=19&t=45321&p=108493#p99558
openRangeHigh = AddPlot(new PlotAttributes("High", EPlotShapes.Point,
Color.ForestGreen, Color.Transparent, 7, EPlotStyle.Solid, true));
openRangeLow = AddPlot(new PlotAttributes("Low", EPlotShapes.Point,
Color.Firebrick, Color.Transparent, 7, EPlotStyle.Solid, true));
}
protected override void CalcBar()
{
if (IsFirstHalf())
{
lowOpenRange = Math.Min(lowOpenRange, Bars.Low[0]);
highOpenRange = Math.Max(highOpenRange, Bars.High[0]);
openRangeHigh.Set(highOpenRange);
openRangeLow.Set(lowOpenRange);
}
else
{
lowOpenRange = 99999;
highOpenRange = 0;
}
}
private bool IsFirstHalf()
{
TimeSpan sessionStart = SessionStart();
TimeSpan endHalfHour = sessionStart.Add(new TimeSpan(0, 30, 0));
if ((Bars.Time[0].TimeOfDay >= sessionStart) &&
(Bars.Time[0].TimeOfDay <= endHalfHour))
return true;
return false;
}
private TimeSpan SessionStart()
{
int ind = Math.Max(0, (int)Bars.Time[0].DayOfWeek - 1);
return Bars.Sessions[ind].StartTime;
}
}
}
- Attachments
-
- scr.23-09-2014 14.16.10.png
- (3.87 KiB) Downloaded 1392 times
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: any idea of making high/low on specific bar?
That error suggests that you have already a class with the same name as the name from the indicator you're trying to add.hi tnx! but i am getting errors trying to compile this in line 9
Code: Select all
The namespace 'PowerLanguage.Indicator' already contains a definition for 'SessionTimePlotFirstHalfHour'
Rename the line
Code: Select all
public class SessionTimePlotFirstHalfHour : IndicatorObject
Code: Select all
public class ThisHasToBeAnUniqueName : IndicatorObject
Code: Select all
public SessionTimePlotFirstHalfHour(object _ctx) : base(_ctx) { }
Code: Select all
public ThisHasToBeAnUniqueName(object _ctx) : base(_ctx) { }
Re: any idea of making high/low on specific bar?
hi am back, and i am trying to run this indcator agian and it wont complie
this is the errors same plot as above.
tnx guys!
Code: Select all
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 1
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 2
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 3
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 4
'Namespace' statement must end with a matching 'End Namespace'. "SessionTimePlotFirstHalfHour" [Indicator] Ln 6
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 7
Bracketed identifier is missing closing ']'. "SessionTimePlotFirstHalfHour" [Indicator] Ln 8
'Class' statement must end with a matching 'End Class'. "SessionTimePlotFirstHalfHour" [Indicator] Ln 9
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 9
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 10
End of statement expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 11
Keyword is not valid as an identifier. "SessionTimePlotFirstHalfHour" [Indicator] Ln 12
Explicit initialization is not permitted with multiple variables declared with a single type specifier. "SessionTimePlotFirstHalfHour" [Indicator] Ln 12
'.' expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 14
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 14
End of statement expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 16
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 17
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 18
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 19
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 20
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 20
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 21
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 22
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 24
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 25
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 26
End of statement expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 28
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 29
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 30
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 31
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 32
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 33
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 35
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 36
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 37
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 38
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 39
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 40
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 41
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 42
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 43
End of statement expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 45
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 46
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 47
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 48
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 50
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 51
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 52
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 54
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 55
End of statement expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 57
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 58
Declaration expected. "SessionTimePlotFirstHalfHour" [Indicator] Ln 59
Statement cannot appear outside of a method body/multiline lambda. "SessionTimePlotFirstHalfHour" [Indicator] Ln 61
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 62
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 63
Syntax error. "SessionTimePlotFirstHalfHour" [Indicator] Ln 64
Namespace or type specified in the Imports 'mscorlib' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. "vb_First_Bar_of_Day" [Indicator] Ln 1
Unused local variable: 'ReflectorVariable0'. "vb_First_Bar_of_Day" [Indicator] Ln 16
Using DirectCast operator to cast a value-type to the same type is obsolete. "vb_From_Broker_To_Strategy_MP_Synchronizer" [Strategy] Ln 33
Using DirectCast operator to cast a value-type to the same type is obsolete. "vb_From_Broker_To_Strategy_MP_Synchronizer" [Strategy] Ln 40
tnx guys!
- jwebster503
- Posts: 24
- Joined: 13 Mar 2014
- Has thanked: 9 times
- Been thanked: 14 times
Re: any idea of making high/low on specific bar?
Hi, eyal.
In the PowerLanguage.NET Editor, you can create studies using either the VB.Net or C# (pronounced C-sharp) languages. You select which you'd like to use when you create your study. I'm going to make a wild guess here -- I think you posted C# code into a study which was created expecting the VB.Net language -- this won't work. In PowerLanguage.NET Editor, when you click on the add a new indicator, you need to select the language to be "C#" because JoshM provided you with code written in C#. See the attached screenshot of how this dialog box should look:
I think you'll find this will work drastically better! I clicked the "OK" button after capturing the screenshot, and replaced the default code with the code JoshM provided unchanged, and it worked as intended.
Good luck!
Jeff
In the PowerLanguage.NET Editor, you can create studies using either the VB.Net or C# (pronounced C-sharp) languages. You select which you'd like to use when you create your study. I'm going to make a wild guess here -- I think you posted C# code into a study which was created expecting the VB.Net language -- this won't work. In PowerLanguage.NET Editor, when you click on the add a new indicator, you need to select the language to be "C#" because JoshM provided you with code written in C#. See the attached screenshot of how this dialog box should look:
I think you'll find this will work drastically better! I clicked the "OK" button after capturing the screenshot, and replaced the default code with the code JoshM provided unchanged, and it worked as intended.
Good luck!
Jeff