C# help  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
market
Posts: 2
Joined: 12 Apr 2013
Has thanked: 1 time

C# help  [SOLVED]

Postby market » 13 Apr 2014

I need some help with C# as I’ve never done any coding before and I am getting errors when I modify the standard floor pivot indicator to add an additional support and resistance lines as per Frank Ochoa’s extended Floor Pivot indicator. As there are no comments with the code I am finding it hard to understand what each line does. For instance I first thought the line containing 5 or 7 was how many days were being calculated, which will probably give someone a laugh, I have since seen a post say it’s for the amount of support and resistance lines with the Pivot Point. Based on that, I changed it to 7 or 9 as I had 9 lines with my additional support and resistance line. Also in the original Floor_Trader_Pivots indicator at lines 43 I don’t understand why the 5 or 7 is 5 where it says:

public Floor_Trader_Pivots(object ctx) :
base(ctx){
plot_5or7 = 5;

and then at line 48 where it says:

[Input]
public int plot_5or7 { get; set; }

Then at line 133:

if ((plot_5or7 == 7))

I would like someone explain what I’m doing wrong.

The modified version I did is below with the errors underneath:

using System;
using System.Drawing;

namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class Ochoa_Floor_Pivot : IndicatorObject
{
private VariableObject<Double> m_s1;

private VariableObject<Double> m_s2;

private VariableObject<Double> m_s3;

private VariableObject<Double> m_s4;

private VariableObject<Double> m_r1;

private VariableObject<Double> m_r2;

private VariableObject<Double> m_r3;

private VariableObject<Double> m_r4;

private VariableObject<Double> m_pp;

private VariableObject<Double> m_todayshigh;

private VariableObject<Double> m_todayslow;

private VariableObject<Int32> m_counter;

private IPlotObject Plot1;

private IPlotObject Plot2;

private IPlotObject Plot3;

private IPlotObject Plot4;

private IPlotObject Plot5;

private IPlotObject Plot6;

private IPlotObject Plot7;

private IPlotObject Plot8;

private IPlotObject Plot9;

public Ochoa_Floor_Pivot(object _ctx):
base(_ctx){
plot_7or9 = 9;
}

[Input]
public int plot_7or9 { get; set; }

protected override void Create(){
m_s1 = new VariableObject<Double>(this);
m_s2 = new VariableObject<Double>(this);
m_s3 = new VariableObject<Double>(this);
m_s4 = new VariableObject<Double>(this);
m_r1 = new VariableObject<Double>(this);
m_r2 = new VariableObject<Double>(this);
m_r3 = new VariableObject<Double>(this);
m_r4 = new VariableObject<Double>(this);
m_pp = new VariableObject<Double>(this);
m_todayshigh = new VariableObject<Double>(this);
m_todayslow = new VariableObject<Double>(this);
m_counter = new VariableObject<Int32>(this);
Plot1 =
AddPlot(new PlotAttributes("R4", EPlotShapes.LeftTick,
Color.Magenta, Color.Empty, 2,
0,
true));
Plot2 =
AddPlot(new PlotAttributes("R3", EPlotShapes.LeftTick,
Color.Magenta, Color.Empty, 2,
0,
true));
Plot3 =
AddPlot(new PlotAttributes("R2", EPlotShapes.LeftTick, Color.Blue,
Color.Empty, 2, 0, true));
Plot4 =
AddPlot(new PlotAttributes("R1", EPlotShapes.LeftTick,
Color.Yellow, Color.Empty, 2,
0,
true));
Plot5 =
AddPlot(new PlotAttributes("PP", EPlotShapes.LeftTick, Color.Cyan,
Color.Empty, 2, 0, true));
Plot6 =
AddPlot(new PlotAttributes("S1", EPlotShapes.LeftTick,
Color.Yellow, Color.Empty, 2,
0,
true));
Plot7 =
AddPlot(new PlotAttributes("S2", EPlotShapes.LeftTick, Color.Blue,
Color.Empty, 2, 0, true));
Plot8 =
AddPlot(new PlotAttributes("S3", EPlotShapes.LeftTick,
Color.Magenta, Color.Empty, 2,
0,
true));
Plot9 =
AddPlot(new PlotAttributes("S4", EPlotShapes.LeftTick,
Color.Magenta, Color.Empty, 2,
0,
true));
}

protected override void CalcBar()
{
EResolution resolution = Bars.Info.Resolution.Type;
if (resolution == EResolution.Quarter ||
EResolution.Week <= resolution && resolution <= EResolution.Year) return;

if (Bars.Time[0].Date != Bars.Time[1].Date)
{
m_counter.Value = (m_counter.Value + 1);
var m_yesthigh = m_todayshigh.Value;
var m_yestlow = m_todayslow.Value;
var m_yestclose = Bars.Close[1];
m_todayshigh.Value = Bars.High[0];
m_todayslow.Value = Bars.Low[0];
m_pp.Value = (((m_yesthigh + m_yestlow)
+ m_yestclose)
/((3)));
m_r1.Value = ((m_pp.Value*2)
- m_yestlow);
m_r2.Value = ((m_pp.Value + m_yesthigh)
- m_yestlow);
m_r3.Value = ((m_r1.Value + m_yesthigh)
- m_yestlow);
m_r4.Value = ((m_r3.Value + m_r2)
- m_r1);
m_s1.Value = ((m_pp.Value*2)
- m_yesthigh);
m_s2.Value = ((m_pp.Value - m_yesthigh)
+ m_yestlow);
m_s3.Value = ((m_s2.Value - m_yesthigh)
+ m_yestlow);
m_s4.Value = ((m_s3.Value - m_s1.Value)
- m_s2.Value);
}
else{
if (PublicFunctions.DoubleGreater(Bars.High[0], m_todayshigh.Value)){
m_todayshigh.Value = Bars.High[0];
}
if (PublicFunctions.DoubleLess(Bars.Low[0], m_todayslow.Value)){
m_todayslow.Value = Bars.Low[0];
}
}
if (m_counter.Value >= 2)
{
if ((plot_7or9 == 9))
{
Plot1.Set(0, m_r4.Value);
}
Plot2.Set(0, m_r3.Value);
Plot3.Set(0, m_r2.Value);
Plot4.Set(0, m_r1.Value);
Plot5.Set(0, m_pp.Value);
Plot6.Set(0, m_s1.Value);
Plot7.Set(0, m_s2.Value);
Plot8.Set(0, m_s2.Value);
if ((plot_5or7 == 7))
{
Plot7.Set(0, m_s4.Value);
}
}
}
}
}


///////////////////////////////////////////////////////////////////////////////////////////
Errors:
Operator '+' cannot be applied to operands of type 'double' and 'PowerLanguage.VariableObject<double>' "Ochoa_Floor_Pivot" [Indicator] Ln 136
The name 'plot_5or7' does not exist in the current context "Ochoa_Floor_Pivot" [Indicator] Ln 168

I hope someone can help a novice sort this out as I really want to start trading.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: C# help

Postby Henry MultiСharts » 14 Apr 2014

Hello market,

1) Operator '+' cannot be applied to operands of type 'double' and 'PowerLanguage.VariableObject<double>' "Ochoa_Floor_Pivot". [Indicator] Ln 136
This error says that you are trying to sum up the things that cannot be summed up. You need to perform mathematical operations with the values of the objctes, not with the objects themselves. Here is hte proper code:

Code: Select all

m_r4.Value = ((m_r3.Value + m_r2.Value) - m_r1.Value);
2) The name 'plot_5or7' does not exist in the current context "Ochoa_Floor_Pivot" [Indicator] Ln 168

This error says that the operator (plot_5or7) is not declared. In the code you have provided plot_5or7 is indeed not declared. But you have plot_7or9 declared. Make sure you do not mix them up.


Return to “MultiCharts .NET”