NexusFi: Find Your Edge


Home Menu

 





Implictl convert 'Double' Error - Calc Avg


Discussion in EasyLanguage Programming

Updated
    1. trending_up 2,291 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Implictl convert 'Double' Error - Calc Avg

  #1 (permalink)
 JoeyZaza 
MA/USA
 
Experience: Intermediate
Platform: Multicharts 64
Broker: AMP Futures
Trading: emini es
Posts: 72 since Oct 2015
Thanks Given: 30
Thanks Received: 53

Hi Traders,

I am using Multicharts .NET64. Unfortunately or fortunately, MC.NET supports C# and VB. The .NET version does not support easy language so I am forced to use the OO construct.

I understand programming and a bit of OO, but by far not a hard core programmer (although I pretend to be one during the day).

I am having a bit of trouble with some of the errors being thrown. Looks like a type mismatch in my coding, but I just "don't get it"..

Getting error "Cannot Implicitly convert type 'DOUBLE' to PowerLanguage.ISeries<double>'...

My intent with the signal is to create an Avg of an already calculated value.

The entire code is here with the line in question highlights in RED.

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
public class ZJZ_OpenCloseTrend_Avg_001 : IndicatorObject {
private AverageFC m_AverageFC;

public ZJZ_OpenCloseTrend_Avg_001(object _ctx):base(_ctx)
{
// assign default values to inputs
length = 8;
}

// define the inputs
[Input]
public int length { get; set; }


private IPlotObject Open_Close_Trend;

public interface IAlert
{
bool CheckAlertLastBar { get; } // true if it is the last bar now
bool Enabled { get; } // true - if alerts are on
void Alert(); // to generate Alert with an empty text
void Alert(string Format, params object[] _args); // generate alert with message.
void Cancel(); // finish Alert generation on this bar.
}

private double SumOpenVal( int length )
{
double sumoval = 0.0;
sumoval = Bars.Open.Summation(length);
return sumoval;
}

private double SumCloseVal( int length )
{
double sumcval = 0.0;

sumcval = Bars.Close.Summation(length);
return sumcval;
}


protected override void Create() {
// create variable objects, function objects, plot objects etc.
// instantiated once
m_AverageFC = new AverageFC(this);

Open_Close_Trend = AddPlot(new PlotAttributes("OCTrend", EPlotShapes.Line, Color.Blue));

// create the ema of the trend
Open_Close_Trend = AddPlot(new PlotAttributes("AvgTrend", EPlotShapes.Line, Color.Yellow));
}
protected override void StartCalc() {
// assign inputs
}
protected override void CalcBar(){
// Avg of trend


// indicator logic
double sumopen = SumOpenVal(length);
double sumclose = SumCloseVal(length);
double trend = sumclose - sumopen;

m_AverageFC.price = trend;
m_AverageFC.length = length;
double m_avg = m_AverageFC[0];

Open_Close_Trend.Set(trend);
// dim m_trenddir string;
Open_Close_Trend.Set(m_avg);
}
}
}

TIA
JoeyZaza

Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
REcommedations for programming help
Sierra Chart
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #3 (permalink)
 JoeyZaza 
MA/USA
 
Experience: Intermediate
Platform: Multicharts 64
Broker: AMP Futures
Trading: emini es
Posts: 72 since Oct 2015
Thanks Given: 30
Thanks Received: 53


reviewing other sample codes from other indicators.. Looks like if I just eliminate the Double Type definitions, that will keep the types and assignments consistent... A bit of rework is in order..

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #4 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


JoeyZaza View Post
I am having a bit of trouble with some of the errors being thrown. Looks like a type mismatch in my coding, but I just "don't get it"..

Getting error "Cannot Implicitly convert type 'DOUBLE' to PowerLanguage.ISeries<double>'...

You're setting the `price` property of your `AverageFC` instance to a double value:

 
Code
double trend = sumclose - sumopen;

m_AverageFC.price = trend;
That `price` property, however, requires a series of a values to compute on, and not a single double value. This kind of makes sense when we think about what the `AverageFC` function does: computing the average from a range of different values. And to do that, it needs at least two different values to calculate the average of.

In normal English, what you're trying to do here is calculating the 8-bar average value of a single value (like 103.05, or whichever value `trend` has).

Reply With Quote
Thanked by:
  #5 (permalink)
 JoeyZaza 
MA/USA
 
Experience: Intermediate
Platform: Multicharts 64
Broker: AMP Futures
Trading: emini es
Posts: 72 since Oct 2015
Thanks Given: 30
Thanks Received: 53

Hi Jura,

Yes, I understand what you are saying. I am having a hard time discerning what applies to double series, etc. and the correct syntax. I have tried several permutations. As well as tried to use the same approach as the standard Mov_Avg_1_Line study. In that follows the same construct of taking multiple individual values and then average them:

....
protected override void StartCalc(){
price = Bars.Close;
m_averagefc1.price = price;
m_averagefc1.length = length;
}

protected override void CalcBar(){
m_avg.Value = m_averagefc1[0];
if (displace >= 0 || Bars.CurrentBar > Math.Abs(displace)){
Plot1.Set(displace, m_avg.Value);
if (displace <= 0){
if (this.CrossesOver(price, m_avg)){
Alerts.Alert("Price crossing over average");
}
....

Technically the Price should not care what value is given it, no? Wouldn't I be able to just pass 'trend' and 'length' to m_averagefc1.price and m_averagefc1.length respectively. Or just assign 'trend' to m_avg.Value...

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #6 (permalink)
 JoeyZaza 
MA/USA
 
Experience: Intermediate
Platform: Multicharts 64
Broker: AMP Futures
Trading: emini es
Posts: 72 since Oct 2015
Thanks Given: 30
Thanks Received: 53

Thank you Jura.

It took a while for it all to click.. here is the (relevant) working code...

Protected Overrides Sub Create()
' create variable objects, function objects, plot objects etc.

Me.m_ocFastAvg = New AverageFC(Me)

Me.m_ocFastMA = New VariableSeries(Of Double)(Me)
End Sub

Protected Overrides Sub StartCalc() 'called once per bar

'assign inputs
Me.m_ocFastAvg.Price = m_ocFastMA
Me.m_ocFastAvg.length = FastMALen

End Sub

Protected Overrides Sub CalcBar() 'called for each tick

Dim m_ATR As Double = (Me.AverageTrueRange(Me.histLen))

Dim trend As Double = (Me._openCloseTrendFunc(0) / m_ATR)

Me.m_ocFastMA.Value = trend

Open_Close_Trend_FastMA.[Set](m_ocFastAvg(0))
End Sub
End Class
End Namespace

Best Regards,

Visit my NexusFi Trade Journal Started this thread Reply With Quote




Last Updated on September 27, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts