Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (7th_zorro, Aku_Aku, henrybane, flink, 1 invisible), 744 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Getting Maximum and Minimun Values from Array #473662
08/02/18 14:51
08/02/18 14:51
Joined: Aug 2018
Posts: 12
T
Tavasy Offline OP
Newbie
Tavasy  Offline OP
Newbie
T

Joined: Aug 2018
Posts: 12
Hi all

I am trying to get maximum and minimum values from an array. Am I doing it right? The maximum and minimum values are always the same. Is there a function like MQL's ArrayMaximum or ArrayMinimum? Heres is the code below

function tick()
{
var BidPrice = AskPrice - Spread;



var a[50];

var mini = 200;
var maxi = 0;

a[0]=BidPrice ;
mini = a[0];
int i;
for (i=1;i<50;i++)
{
a[i] = BidPrice ;

printf("n %f", a[i]);
if (a[i] > maxi)
{
maxi = a[i];
}
if (a[i] < mini)
{
mini = a[i];
}
}
printf("n Min: %f",(var) mini);
printf("n Max: %f",(var) maxi);

}

Re: Getting Maximum and Minimun Values from Array [Re: Tavasy] #473767
08/12/18 00:46
08/12/18 00:46
Joined: Aug 2018
Posts: 98
O
OptimusPrime Offline
Junior Member
OptimusPrime  Offline
Junior Member
O

Joined: Aug 2018
Posts: 98
Hi Tavasy:

I tried your sort code as shown below and it works:

function SortArrayContents()
{

var a[10] = {11,22,343,5,6,40,145,44,67,73}; //populate array manually

var minimum = 200;
var maximum = 0;

minimum = a[0]; // initialize minimum

int i; //initialize i

for (i=0;i<10;i++) //Start with i=0 NOT i = 1
{

if (a[i] > maximum)
maximum = a[i];

if (a[i] < minimum)
minimum = a[i];

}

// Print results

printf("Min: %f", minimum);
printf("Max: %f", maximum);

}

function main(){

SortArrayContents();

}


Thanks so much,

OptimusPrime

Re: Getting Maximum and Minimun Values from Array [Re: OptimusPrime] #473777
08/13/18 18:38
08/13/18 18:38
Joined: Aug 2018
Posts: 12
T
Tavasy Offline OP
Newbie
Tavasy  Offline OP
Newbie
T

Joined: Aug 2018
Posts: 12
Hi OptimusPrime
Thanks for having a look at the code. I tested your version it works perfectly.
My challenge now is to populate an array automatically with changing AskPrices.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1