Easy language question

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Easy language question

Postby capgain » 07 Jan 2009

I am a newbie with easylang and was not able to find a way to do this (after going thru online tutorials). Basically, I would like an alert, let's say, when 50dma is above 200dma in both daily and weekly charts. How do I reference both time periods ...

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 07 Jan 2009

you will need to add both resolution into the same chart,
then use data1 and data2 to reference them.

e.g.

Code: Select all

var:
close1(0),
close2(0),

avg1_50(0),
avg1_200(0),

avg2_50(0),
avg2_200(0);



close1 = close of data1;
close2 = close of data2;

avg1_50 = averagefc( close1, 50);
avg1_200 = averagefc( close1, 200);

avg2_50 = averagefc( close2, 50);
avg2_200 = averagefc( close2, 200);


if avg1_50 > avg1_200 and avg2_50 > avg2_200 then
begin

{-- your instructions here ---}

end;

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 07 Jan 2009

Thanks for such a quick response. Did not expect so fast ...

Thanks! TJ
you will need to add both resolution into the same chart,
then use data1 and data2 to reference them.

e.g.

Code: Select all

var:
close1(0),
close2(0),

avg1_50(0),
avg1_200(0),

avg2_50(0),
avg2_200(0);



close1 = close of data1;
close2 = close of data2;

avg1_50 = averagefc( close1, 50);
avg1_200 = averagefc( close1, 200);

avg2_50 = averagefc( close2, 50);
avg2_200 = averagefc( close2, 200);


if avg1_50 > avg1_200 and avg2_50 > avg2_200 then
begin

{-- your instructions here ---}

end;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 12 Jan 2009

I have updated the code:

Code: Select all

var:
avg1_50(0),
avg1_200(0),

avg2_50(0),
avg2_200(0);


avg1_50 = averagefc( close data1, 50) data1;
avg1_200 = averagefc( close data1, 200) data1;

avg2_50 = averagefc( close data2, 50) data2;
avg2_200 = averagefc( close data2, 200) data2;


if avg1_50 > avg1_200 and avg2_50 > avg2_200 then
begin

{-- your instructions here ---}

end;

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 12 Jan 2009

even more correct-

var:
avg1_50(0),
avg1_200(0),

avg2_50(0,data2),
avg2_200(0,data2);


avg1_50 = averagefc( close data1, 50) data1;
avg1_200 = averagefc( close data1, 200) data1;

avg2_50 = averagefc( close data2, 50) data2;
avg2_200 = averagefc( close data2, 200) data2;


if avg1_50 > avg1_200 and avg2_50 > avg2_200 then
begin

{-- your instructions here ---}

end;

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 12 Jan 2009

Thanks a lot, TJ and Steven
One issue I am having is applying this code as part of indicator. THe problem is this indcator is also used in charts where is there is only one data stream. Is there a way to check how many data streams are there (I am using input variable datanum as in the manual but that did not work for me. )

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 13 Jan 2009

I would just make another copy of the indicator and label them 1data and 2data.(just strip out the data2 stuff on one of them)
I do that on several custom indicators, depending on the number of data streams.

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 13 Jan 2009

I would just make another copy of the indicator and label them 1data and 2data.(just strip out the data2 stuff on one of them)
I do that on several custom indicators, depending on the number of data streams.
Thanks!
I am still having problems with the code as discussed in this thread. The results don't appear to be right. I have chart with four data streams [data0 is 5 min and the rest are 15min, 30 min and 60 min]. To make it simple, I try to evaluate 3 DMA for each of these time resolutions. Please see code below:

variables: avg15_3 (0,data2), avg30_3 (0,data3), avg60_3 (0,data4), var0( 0 ), var3(0);

var0 = AverageFC( Price, Length ) ;
var3 = AverageFC( Price, 3 ) ;


avg15_3 = AverageFC( close data2, 3) data2;

avg30_3 = AverageFC( close data3, 3) data3;

avg60_3 = AverageFC( close data4, 3) data4;

These values don't match with the 3 moving average lines plotted for each of these resolutions (data2, 3 & 4). I don't know if I am missing something ...

Thanks!

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 13 Jan 2009

I suspect it has to do with the averageFC function. It has some special algo to make it fast.

try the same code with the xaverage function, see if it makes a difference.

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 13 Jan 2009

I suspect it has to do with the averageFC function. It has some special algo to make it fast.

try the same code with the xaverage function, see if it makes a difference.
Unfortunately, even XAverage is not accurate here ...

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 13 Jan 2009

are you trying to do the bnaimy method?

I have 3 data series with xaverage, and they work fine.

can you post your complete code?



p.s. make sure the indicator is scaled same as the symbole.

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 13 Jan 2009

I suspect it has to do with the averageFC function. It has some special algo to make it fast.

try the same code with the xaverage function, see if it makes a difference.
Actually I tried again and xaverage works. I was initially comparing with results from moving average plot values which uses averageFC. I would really like averageFC to work in multi-datastream situation as trends show up faster. As it looks like a bug, I hope TSSupport gets to fix it (on a different not, I have not seen much responses from TSSupport on this forum lately). Thanks TJ for all your help!

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 14 Jan 2009

you can try AVERAGE instead of AVERAGEFC.

it is "slower", but with today's computer, i don't think anybody can see the difference.

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 14 Jan 2009

you can try AVERAGE instead of AVERAGEFC.

it is "slower", but with today's computer, i don't think anybody can see the difference.
I had tried with average and it also was not accurate ..

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 14 Jan 2009

ok, i can see the root of the problem: both Average and averagefc are calling another function.

because the second function is not aware of the dataN reference, it is using data1 for its calculation... thus the wrong result.

I don't know, if this is a MC bug, or if there is a way for MC to make subsequent functions aware of the dataN reference.

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 14 Jan 2009

ok, i can see the root of the problem: both Average and averagefc are calling another function.

because the second function is not aware of the dataN reference, it is using data1 for its calculation... thus the wrong result.

I don't know, if this is a MC bug, or if there is a way for MC to make subsequent functions aware of the dataN reference.
I am currently using the lates Beta 2 version. I don't know if these functions were working properly in earlier versions. I have request - if anyone using averageFC or average functions in code for multidatastream charts (and the values match with plotted MA indicators), please post the version of MultiCharts .. Thanks.

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 15 Jan 2009

I would just make another copy of the indicator and label them 1data and 2data.(just strip out the data2 stuff on one of them)
I do that on several custom indicators, depending on the number of data streams.
Thanks!
I am still having problems with the code as discussed in this thread. The results don't appear to be right. I have chart with four data streams [data0 is 5 min and the rest are 15min, 30 min and 60 min]. To make it simple, I try to evaluate 3 DMA for each of these time resolutions. Please see code below:

variables: avg15_3 (0,data2), avg30_3 (0,data3), avg60_3 (0,data4), var0( 0 ), var3(0);

var0 = AverageFC( Price, Length ) ;
var3 = AverageFC( Price, 3 ) ;


avg15_3 = AverageFC( close data2, 3) data2;

avg30_3 = AverageFC( close data3, 3) data3;

avg60_3 = AverageFC( close data4, 3) data4;

These values don't match with the 3 moving average lines plotted for each of these resolutions (data2, 3 & 4). I don't know if I am missing something ...

Thanks!
Hi capgain,

In our tests with your code the results across different data series were the same. Could you please contact us via LiveChat (the link below) so that we could see how exactly you made the comparison?

Thank you.

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 15 Jan 2009


Hi capgain,

In our tests with your code the results across different data series were the same. Could you please contact us via LiveChat (the link below) so that we could see how exactly you made the comparison?

Thank you.
Hello Marina,

I am currently travelling and I will try livechat tomorrow. Meanwhile, what I am trying is simple. Basically, I have four datastreams same symbol but different time resolutions. I have 3dma moving average to each datastream and I can see the 3dma plot values in each subplot.

In the first subplot I add an indicator with the code above in which I calulate the 3dma moving averages of all the plots. The results (when using averagefc) don't match with the 3dma plot values ..

If you don't mind and have it handy, can you please post the workspace file that your team tested ..

Thanks a lot!

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 16 Jan 2009

Hi capgain,

As promised, I am attaching the workspace and the indicator. The indicator is basically what you were using, but we got rid of plot4.

In the workspace you will see two chart windows. The data is the same and the indicators are the same. !_example_1 is applied to data1 (the 5 minute chart) but its plots are based on data2 (red) and data3 (orange) or 15 minute and 30 minute charts respectively. Moving Average in the chart to the left is applied to data2 (15 min). Moving Average in the chart to the right is applied to data3 (30 min.) Finally, the chart on the left has everything plotted in the price series subchart. In the chart on the right, indicators are plotted in a separate subchart.

Let's concentrate on the chart to the left first. You will see that the values of the Moving Average plot based on data2 coincide with the values of the red plot of our indicator (eferencing data2) in those points where 15 bars are located. Which is perfectly correct.

Now look at the chart to the right. At a glance (if you do not analyze plots' values) it might seem that the plots of !_example_1 and the moving average plot are totally different. However, this is not true. The thing is that the indicators have different price scales. However, if you point the crosshair to where 30 min bars are located (for now we are comparing mov average that is based on data3 and the orange plot of our example that references data3), you will see that in those joints the values of the moving average plot and the orange !_example_1 plot the values are the same. Finally, if you drag the indicators into the chart window, you will see that the mov average plot and the orange plot coincide.

I hope the above explanation is not very confusing. If it is, please contact us via LiveChat again.
Attachments
comparisons.zip
(5.95 KiB) Downloaded 281 times

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 20 Jan 2009

Hello Marina,

Thanks a lot for your help and for sending the workspace. I was slightly confused by it. I was wondering if you can please take a look at the workspace I have attached to this message. It is simple - has 4 subplots of same ticker but different time resolutions (here the data is from Interactive brokers - 5min, 15 min, 30 min and 60 min). I have added moving average 1 (3 period) for subplot2, subplot3 and subplot4 - you can see the values in the status line of each of these subplots.

In subplot1, I have added an indicator (code below) which calculates the 3 dma moving averages of subplot2, subplot3 and subplot4 and shows the calculated values in the status line of subplot1. The values in the status line of subplot1 should match with the 3dma values of the other respective subplots but it does not.

Can you please see why .... Thanks a lot!

CustomLineFC:
inputs: Price( Close ), DataNum(1),Length( 3 ), Displace( 0 );

variables: avg15_3 (0,data2), avg30_3 (0,data3), avg60_3 (0,data4), var0( 0 ), var3(0), OldKeyID(-1), ID(-1), mytime(0);


var0 = AverageFC( Price, 3 ) ;


avg15_3 = AverageFC( close[0] data2, 3) data2;

avg30_3 = AverageFC( close[0] data3, 3) data3;

avg60_3 = AverageFC( close[0] data4, 3) data4;

//alert (NumToStr(avg60_3 ,4) + " " + NumToStr(avg60_3[1] ,4));


condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "Avg" ) ;
if Displace <= 0 and length = 13 then
begin
condition1 = Price crosses over var0 ;

begin
condition1 = Price crosses under var0 ;
end;
end;
end ;


Plot2("subplot2-3dma="+NumToStr(avg15_3 ,4) ,"3Dma", Blue);
Plot3("subplot3-3dma="+NumToStr(avg30_3 ,4) ,"3Dma", Blue);
Plot4("subplot4-3dma="+NumToStr(avg60_3 ,4) ,"3Dma", Blue);
Attachments
testaverragefc.wsp
(43.92 KiB) Downloaded 484 times

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 21 Jan 2009

Hi capgain,

Thank you for the workspace.

The reason why the values in the status line of your custom indicator do not match the 3dma values in real-time (they all match on history if you look at the points that all charts have - in other words they match in points where 60 min bars are plotted) for the following reason:

The mov agv plots applied to a 15, 30, and 60 minute dataseries are updated in real-time. Their values as seen in the status line of your custom indicator do not always match the values of the plots in the other subscharts in real-time because your custom indicator is not recalculated at the same time those plots are recalculated. As the time passes, and new 15, 30, and 60 minute bars are plotted you will see the values update and match - when there will be 15, 30, and 60 minute bars matching 5 minute bars.

I am not sure if my explanation is clear enough, but if you watch your workspace, you see that, as new 15, 30, and/or 60 min bars are formed, the values in the status line of your custom indicator will match those of the plots.

Regards.

capgain
Posts: 63
Joined: 14 Apr 2008
Been thanked: 3 times

Postby capgain » 23 Jan 2009

Hi capgain,

Thank you for the workspace.

The reason why the values in the status line of your custom indicator do not match the 3dma values in real-time (they all match on history if you look at the points that all charts have - in other words they match in points where 60 min bars are plotted) for the following reason:

The mov agv plots applied to a 15, 30, and 60 minute dataseries are updated in real-time. Their values as seen in the status line of your custom indicator do not always match the values of the plots in the other subscharts in real-time because your custom indicator is not recalculated at the same time those plots are recalculated. As the time passes, and new 15, 30, and 60 minute bars are plotted you will see the values update and match - when there will be 15, 30, and 60 minute bars matching 5 minute bars.

I am not sure if my explanation is clear enough, but if you watch your workspace, you see that, as new 15, 30, and/or 60 min bars are formed, the values in the status line of your custom indicator will match those of the plots.

Regards.
Hello Marina,

Thanks a lot for taking the time to look into this issue. I still do not understand as the custom indicator is also calculated on every tick (same as in the subplots as the ticker is same)

Anyway, for now, I have a workaround. I am not using multi-data stream charts. I have individual charts which send averagefc info to my dll where I do my stuff.

THanks again,

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 26 Jan 2009

Hi capgain,

Please let me know if you need any further help.


Return to “User Contributed Studies and Indicator Library”