iHighest and iLowest

 

Hi,

I was trying to get the highest and lowest prices out of a group of pre-calculated prices and was wondering about the how. I assume it is done by arrays but I'd like to know the exact procedure.

double someprice, someotherprice, somemoreprice, evenmoreprice;

//then some calculations to get those prices

someprice = result of calculation 1;
someotherprice = result of calculation 2;
somemoreprice = result of calculation 3;
evenmoreprice = result of calculation 4;

//and here the code to get the highest and the lowest price among those four. something like iHighest / iLowest
 
Yojimbo:

Hi,

I was trying to get the highest and lowest prices out of a group of pre-calculated prices and was wondering about the how. I assume it is done by arrays but I'd like to know the exact procedure.

You could read the documentation then you would know that iHighest and iLowest return a bar shift number . . . maybe you could use ArraySort instead ?
 
Yojimbo:

Hi, I was trying to get the highest and lowest prices out of a group of pre-calculated prices and was wondering about the how. I assume it is done by arrays but I'd like to know the exact procedure.

Nice Try, Those Aren't Codes: Here's what I would like.

double Virtual_Order_Array;

//then get some values for the virtual order arrays for different currencies.
vPrice= open[0];
vOrderType=vBuy || vSell
vOrderSym= iOptional_Symbol;
vProfit=vPrice-open[0]*vOrderType;

//and here give me the codes for multi-currency back-testing profit
Calculate profit of Virtual orders and give me results.
Show your real attempt so people would know if you're noob code fishing or even know what an Array is.
 
RaptorUK:
You could read the documentation then you would know that iHighest and iLowest return a bar shift number . . . maybe you could use ArraySort instead ?


I've read the documentation zillion times and I know that iHighest / iLowest work with barcounts. That's why I wrote SOMETHING LIKE iHighest / iLowest since bars are irrelevant to me. I wanted to get the highest and lowest values out of a group of precalculated values to use them as coordinates for a rectangle. I figured the grouping part is done by arrays but that doesn't solve the main problem of getting the highest / lowest double values out of that array to use them as coordinates.

double range, pivot, halfrange, yesterdayopen, yesterdayclose, yesterdayhigh, yesterdaylow;

yesterdayopen = iOpen(NULL,PERIOD_D1,1);
//same for close, high and low
range = yesterdayhigh - yesterdaylow;
pivot = (yesterdayclose + yesterdayhigh + yesterdaylow) / 3;
halfrange = range / 2

double lvls[6] = {halfrange, pivot, yesterdayopen, yesterdayclose, yesterdayhigh, yesterdaylow};

double arrayhighest = //here comes the command that gets the value for whatever ends up as the highest value of the array above
//same for the lowest

@ubzen: no comment

 
Yojimbo:


I've read the documentation zillion times and I know that iHighest / iLowest work with barcounts. That's why I wrote SOMETHING LIKE iHighest / iLowest since bars are irrelevant to me.

If iHighest and iLowest are irrelevant to you and this thread then it hardly makes sense to use it for the thread title . . yet that is what you did . . . so please DONT SHOUT AT ME.
 
RaptorUK:
If iHighest and iLowest are irrelevant to you and this thread then it hardly makes sense to use it for the thread title . . yet that is what you did . . . so please DONT SHOUT AT ME.

Unfortunately I can't change the title. So sorry for the misleading title >.> Also I didn't want the BOLD and UNDERLINED part to be understood as shouting but as an emphasis. >.<
 
Yojimbo:

Unfortunately I can't change the title. So sorry for the misleading title >.> Also I didn't want the BOLD and UNDERLINED part to be understood as shouting but as an emphasis. >.<

OK :-)

I suggested ArraySort in my first post . . . won't that do what you want ? highest value at one end of the array, lowest at the other . . .

 

Meh... I don't like arrays. But I gotta create that dang Multi-Currency Back-tester so I guess I'll use this one for practice..

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void start(){
    //~~~~~~~~~~
    double range, pivot, halfrange, yesterdayopen, yesterdayclose, yesterdayhigh, yesterdaylow;
    //~~~~~~~~~~
    yesterdayopen=  iOpen(Symbol(),PERIOD_D1,1);
    yesterdayclose= iClose(Symbol(),PERIOD_D1,1);
    yesterdayhigh=  iHigh(Symbol(),PERIOD_D1,1);
    yesterdaylow=   iLow(Symbol(),PERIOD_D1,1);
    //~~~~~~~~~~
    range = yesterdayhigh - yesterdaylow;
    halfrange = range / 2;
    pivot = (yesterdayclose + yesterdayhigh + yesterdaylow) / 3;
    //~~~~~~~~~~
    //double lvls[6] = {halfrange, pivot, yesterdayopen, yesterdayclose, yesterdayhigh, yesterdaylow};---Complier didn't like---
    //---cannot inatialize arrays with variable names.
    //~~~~~~~~~~
    double lvls[6];//------Cool that line complied.
    //lvls[] = {halfrange, pivot, yesterdayopen, yesterdayclose, yesterdayhigh, yesterdaylow};---Nope I guess that short-cut didnt Work
    //~~~~~~~~~~
    //------------I better try what I know. Otherwise I'll need to go to the book to find shorter ways of assigning array values.
    lvls[0]=halfrange;//----Ok complier liked that.
    lvls[1]=pivot;
    lvls[2]=yesterdayopen;
    lvls[3]=yesterdayclose;
    lvls[4]=yesterdayhigh;
    lvls[5]=yesterdaylow;
    //~~~~~~~~~~//Hmmm... now to find that Lowest or Highest Value. 
    //I know one way of doing this. By using a good Old i Loop like in OrderSelect Loops. 
    //And assigning a variable for the Lowest when ever I see a value Lower or reverse for Highest.
    double iLowest_Value;
    double iHighest_Value;
    //~~~~~~~~~~
    for(int i=ArraySize(lvls)-1;i>=0;i--){
        if(i==ArraySize(lvls)-1){iLowest_Value=lvls[i]; iHighest_Value=lvls[i];}//First Run.... Assign Anything.
        if(lvls[i]<iLowest_Value){iLowest_Value=lvls[i];}
        if(lvls[i]>iHighest_Value){iHighest_Value=lvls[i];}
    }
    //~~~~~~~~~~//Humm... I think I better test values Here.
    /*Print("iLowest_Value="+iLowest_Value);
    Print("iHighest_Value="+iHighest_Value);
    Print("halfrange="+halfrange);
    Print("pivot="+pivot);
    Print("halfrange="+halfrange);
    Print("yesterdayopen="+yesterdayopen);
    Print("yesterdayclose="+yesterdayclose);
    Print("yesterdayhigh="+yesterdayhigh);
    Print("yesterdaylow="+yesterdaylow);*************Yea...... That Worked.*/
    //~~~~~~~~~~//Lets See if I can learn something about Array Sort and Get the values that way...Checking Docs
    //----------Nah... I'll just use the default values.
    ArraySort(lvls);//---Ok, that compiled.
    //------------------------------------Now lets Print this Baby.
    Print("iLowest_Value="+lvls[0]);
    Print("iHighest_Value="+lvls[ArraySize(lvls)-1]);
    /*--------------------------Cool, they match... I guess I learned something more about arrays today. 
    I'll read about those shortcurts later*/
    //~~~~~~~~~~
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
03:18:14 Temporary EURUSD,M5: loaded successfully
03:18:14 Temporary test started
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: iLowest_Value=0.00680000
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: iHighest_Value=1.34220000
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: halfrange=0.00680000
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: pivot=1.33590000
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: halfrange=0.00680000
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: yesterdayopen=1.32970000
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: yesterdayclose=1.33690000
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: yesterdayhigh=1.34220000
03:18:14 2011.01.02 23:00  Temporary EURUSD,M5: yesterdaylow=1.32860000
03:24:31 Temporary EURUSD,M5: loaded successfully
03:24:31 Temporary test started
03:24:31 2011.01.02 23:00  Temporary EURUSD,M5: iLowest_Value=0.00680000
03:24:31 2011.01.02 23:00  Temporary EURUSD,M5: iHighest_Value=1.34220000
 

@ ubzen: lol. Well, sorry that I need things to be spelled out for me. Unless documentation or book explicitly tell me "in order to get specific values out of an array you MUST use a for cycle" with exactly that wording and chapter title I have no other choice than try obtain a free lesson from a person. It's not code-fishing, it's my way of learning. Seeing how others do it and imitate it for future use. No documentation or book could have ever given me the practical experience your code has provided me with all those comments. Looking through it allowed me to understand that things that I already knew like the for loop can be used to solve problems like these. Docs only tell you "so folks, this is if, else, this is an array and a for loop. happy coding!" Maybe that was all you needed to learn coding. I need more. Btw, I don't intend to test multiple currencies. Anyway, thank you very much for the free lesson.

 
Its cool. I was only able to do it because you provided more codes. That give me a clear picture of what you're looking for and save me time as I could just copy and paste some variable names ;)