function Maximum and Minimum in Lite C

Posted By: Mangal

function Maximum and Minimum in Lite C - 02/19/15 00:51

In the Tutorial it is writen that "maxv" is the function for maximun in Lite C. However it gives an error when compiling the following:

vars H1 = series(priceHigh(36));
vars H2 = series(priceHigh(35));
vars H3 = series(priceHigh(34));
vars H4 = series(priceHigh(33));
vars H5 = series(priceHigh(32));

vars A11 = maxv (H1[0],H2[0],H3[0],H4[0],H5[0]);

It gives and error saying that "maxv" is not defined. Can anyone tell me where the mistake is? The idea is to get the High from High 36 to High 32.
Posted By: boatman

Re: function Maximum and Minimum in Lite C - 02/19/15 03:03

I think the function you are after is MaxVal, not maxv.

Also, if you want to define A11 using type vars, you need to include the series definition.

vars A11 = series(MaxVal(Data, TimePeriod));

However, I'm not sure if you can use this to achieve what you want (which as I understand it is the highest high from 36 bars ago to 32 bars ago??). For this, you might need to use a series of nested if...else if statements using the function 'max' which I believe can only support two arguments at a time (hence the need for nested if...else if's).
Posted By: GPEngine

Re: function Maximum and Minimum in Lite C - 02/19/15 03:17

You can use series shift operator, '+'. http://zorro-trader.com/manual/en/series.htm

vars H = series(priceHigh());
var h32to36 = MaxVal(H+32, 5);
Posted By: GPEngine

Re: function Maximum and Minimum in Lite C - 02/19/15 03:17

That's some wicked lag.
Posted By: Mangal

Re: function Maximum and Minimum in Lite C - 02/19/15 11:03

Thank you to both you. The last solution as "var h32to36 = MaxVal(H+32, 5);" can save me a lot of time. However, when later on using it in some "if" condition it gives an error saying that it requires array or pointer type. Say for instante:

vars H = series(priceHigh());
var A11 = MaxVal(H+31, 6);
var A12 = MaxVal(H+25, 6);
var A13 = MaxVal(H+19, 6);
var A14 = MaxVal(H+13, 6);
var A15 = MaxVal(H+7, 6);


vars P = series(price(0));

if (A14[0] < A15[0] and P[0] < A14[0]) enter long();

When compiling it gives the message "subscript requires array or pointer type"

Is it because A11 should be vars type? How to go around it?

I think I got it. Thank you.

vars H = series(priceHigh());
vars A11 = series(MaxVal(H+31, 6));
vars A12 = series(MaxVal(H+25, 6));
vars A13 = series(MaxVal(H+19, 6));
vars A14 = series(MaxVal(H+13, 6));
vars A15 = series(MaxVal(H+7, 6));
Posted By: jcl

Re: function Maximum and Minimum in Lite C - 02/19/15 16:41

When you only compare the recent data, you need no series. if (A14 < A15 ...) would be sufficient.
Posted By: Mangal

Re: function Maximum and Minimum in Lite C - 03/10/15 03:16

Trying to check if it really gives the HH of the number of bars desired:

function run()

{
BarPeriod = 1440;
vars H = series(priceHigh());
var h32to36 = MaxVal(H+32,5);
printf("Result = %.f", h32to36);

}

It gives Result = 1. How to do so also it gives decimals and check what it really does? I am trying to see how it works.
Posted By: GPEngine

Re: function Maximum and Minimum in Lite C - 03/10/15 06:05

printf("\nResult = %.5f", h32to36);

http://www.cplusplus.com/reference/cstdio/printf/
Posted By: Mangal

Re: function Maximum and Minimum in Lite C - 03/10/15 13:16

Thank you GP. I am trying it and it gives a quiet long series of numbers with decimals, but no one of them coincides with the MaxVal of h32 to h36 back from yesterday (included).
Posted By: GPEngine

Re: function Maximum and Minimum in Lite C - 03/11/15 05:40

I'm not sure how to respond. Read this and check for gaps in your understanding?
http://zorro-trader.com/manual/en/run.htm
Posted By: jcl

Re: function Maximum and Minimum in Lite C - 03/11/15 09:38

I also do not understand the problem. With the suggestion by GPEngine you're printing the maximum from 32 to 36 days ago.
Posted By: Mangal

Re: function Maximum and Minimum in Lite C - 03/11/15 18:54

This is what I was expecting, but when trying to see if it really does it, it turns that it doesn't. Or the way I am trying to check it is wrong.
Posted By: swingtraderkk

Re: function Maximum and Minimum in Lite C - 03/12/15 09:55

Make sure you know what days the result refers to.

Code:
function run()

{
BarPeriod = 1440;
vars H = series(priceHigh());
var h32to36 = MaxVal(H+32,5);
printf("\n%d %d %d Result HH of 32 to 36 days ago = %.5f",year(),month(),day(),h32to36);

}

Posted By: Mangal

Re: function Maximum and Minimum in Lite C - 03/12/15 13:37

Thank you swingtraderkk. I can't find still any of the numbers generated by this script in the daily values of EURUSD.

As it is now it helps because the printed Result gives the date from where to look, but no way yet. So I don't know what is doing.
Posted By: 3DCat

Re: function Maximum and Minimum in Lite C - 03/13/15 08:11

seems to work for me. The Maxvals are not from yesterday though, as your BarPeriod is one day.
Posted By: swingtraderkk

Re: function Maximum and Minimum in Lite C - 03/13/15 11:18

Just check with printf

Code:
function run()

{
BarPeriod = 1440;
vars H = series(priceHigh());
var h32to36 = MaxVal(H+32,5);
printf("\n%d %d %d H today = %1.5f; Result HH of 32 to 36 days ago = %.5f",year(),month(),day(),H[0],h32to36);
printf("\nh32 = %1.5f; h33 = %1.5f; h34 = %1.5f; h35 = %1.5f; h36 = %1.5f;",H[32],H[33],H[34],H[35],H[36]);

}

Posted By: Mangal

Re: function Maximum and Minimum in Lite C - 03/13/15 15:28

Thank you once more swingtraderkk. The Result I am geting is

h32 = 1.24486; h33 = 1.23445; h34 = 1.23933; h35 = 1.24567; h36 = 1.23908;
2015 1 28 H today = 1.14232; Result HH of 32 to 36 days ago = 1.24875
h32 = 1.24875; h33 = 1.24486; h34 = 1.23445; h35 = 1.23933; h36 = 1.24567;
2015 1 29 H today = 1.13829; Result HH of 32 to 36 days ago = 1.24955
h32 = 1.24955; h33 = 1.24875; h34 = 1.24486; h35 = 1.23445; h36 = 1.23933;
2015 1 30 H today = 1.13682; Result HH of 32 to 36 days ago = 1.24955
h32 = 1.24855; h33 = 1.24955; h34 = 1.24875; h35 = 1.24486; h36 = 1.23445;
2015 2 2 H today = 1.13639; Result HH of 32 to 36 days ago = 1.24955
h32 = 1.24792; h33 = 1.24855; h34 = 1.24955; h35 = 1.24875; h36 = 1.24486;
2015 2 3 H today = 1.13623; Result HH of 32 to 36 days ago = 1.25705
h32 = 1.25705; h33 = 1.24792; h34 = 1.24855; h35 = 1.24955; h36 = 1.24875;
Copied to Clipboard!


Now, the High on 2015-02-03 with data from Metatatrader is 1,15332 which is quiet dfferent than the one expressed here H today 1,13623. The difference is huge. If I take Metatrader data one day before, that is on 2015-02-02, it gives 1,13616 which is closer to 1,13623.

When I look at h32, here is h32 = 1,25705 and in Metatrader data h32 is 1,21813.

2014-12-28 : 1,21813
2014-12-26: 1,22108
2014-12-24: 1,22199
Huge difference with h32 = 1,25705.

IN FXCM screen the H on 2014-12-28 is 1,21807 which is similar to Metatrader 1,21813.

I assume some discrepancy with data may be assumed, but it is too high, from 1,21813 to 1,25705.

Same for h33, h34 and so on.

No one of the numbers given as Result can be found in Metatrader data, not even close.
Posted By: Mangal

Re: function Maximum and Minimum in Lite C - 03/13/15 20:38

A further analysis of data of High today, with date on first column, Zorro Result in second column and FXCM third column:

Date Zorro Result FXCM (or Metatrader)
2015-02-03: 1,13623 1,15332
2015-02-02: 1,13639 1,13616
2015-01-30: 1,13682 1,13628
2015-01-29: 1,13829 1,1367
2015-01-28: 1,14232 1,13817

It seems to me that the Zorro Result should give one day before. That is, for instance,

2015-02-03 Zorro Result 1,13623 is the 2015-02-02 FXCM value 1,13616 (at least similar)
2015-02-02 Zorro Result 1,3639 is the 2015-01-30 FXCM value 1,3628 (at least similar)
2015-01-30 Zorro Result 1,13682 is the 2015-01-29 FXCM value 1,1367 (at least similar)
and so on.

In spite of this, however, the h32, h33, h34, h35 and so on from Zorro Result, nothing to do with the h32, h33, h34, h35 FXCM data.

FXCM data is day by day except one day a week.
Posted By: swingtraderkk

Re: function Maximum and Minimum in Lite C - 03/16/15 13:03

When you are comparing FXCM TS and/or metatrader(FXCM or other) with zorro's history files, you are probably not comparing identical feeds.

Also you need to be sure that your times are aligned, i.e. your bars cover the exact same timeperiod in both. I know that zorro assigns the time of bar close to the bar, metatrader or FXCM TS may not do so, and may assign the time of bar start to the bar. Not to speak of issues such as server times being different i.e. days starting at different times, and treatment of sunday candles i.e. are there 5 or 6 days in a week?

I'm not sure of the relevance of this for testing or trading so long as zorro is internally consistent.

HTH
© 2024 lite-C Forums