How can I capture an indicators max/min values ?

Post Reply
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

How can I capture an indicators max/min values ?

Post by lucklogic »

Hi,

Suppose that I want to use WPR indicator whose output values that varies between 0 and 100 but I want to capture that max value and the min value within a predefined lookback of 300 blocks Eg max values achieved = -5 min value achieved = - 87

Now how could I do that ???
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: How can I capture an indicators max/min values ?

Post by NeoTrader »

lucklogic wrote:Hi,

Suppose that I want to use WPR indicator whose output values that varies between 0 and 100 but I want to capture that max value and the min value within a predefined lookback of 300 blocks Eg max values achieved = -5 min value achieved = - 87

Now how could I do that ???
This is only something that i think might work...didn't tested it but you should grasp the concept.

Code: Select all

double MyMax, MyMin;
int LookBack = 100;
double WprArray[];

for ( i=0; i<=LookBack; i++) {
   WprArray[i] = Call to your WPR Indicator shift = i;
   MyMax = MathMax(MyMax, WprArray[i]);
   MyMin = MathMin(MyMin, WprArray[i]);
}
hope this helps,

happy trading,

NeoTrader

-
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

Re: How can I capture an indicators max/min values ?

Post by lucklogic »

NeoTrader wrote:
lucklogic wrote:Hi,

Suppose that I want to use WPR indicator whose output values that varies between 0 and 100 but I want to capture that max value and the min value within a predefined lookback of 300 blocks Eg max values achieved = -5 min value achieved = - 87

Now how could I do that ???
This is only something that i think might work...didn't tested it but you should grasp the concept.

Code: Select all

double MyMax, MyMin;
int LookBack = 100;
double WprArray[];

for ( i=0; i<=LookBack; i++) {
   WprArray[i] = Call to your WPR Indicator shift = i;
   MyMax = MathMax(MyMax, WprArray[i]);
   MyMin = MathMin(MyMin, WprArray[i]);
}
hope this helps,

happy trading,

NeoTrader

-

Thank you that is most helpful. I will have a play. Also might utilise function ;

int ArrayMinimum( double array[], int count=WHOLE_ARRAY, int start=0)
Searches for the element with minimum value. The function returns position of this minimum element in the array.
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: How can I capture an indicators max/min values ?

Post by NeoTrader »

hi lucklogic,
lucklogic wrote:Thank you that is most helpful. I will have a play. Also might utilise function ;

int ArrayMinimum( double array[], int count=WHOLE_ARRAY, int start=0)
Searches for the element with minimum value. The function returns position of this minimum element in the array.
Sure, this would be also possible...you can also try to use your Lockback value as count and the shift value of the bar as start ...
The same is also possible with ArrayMaximum for the Max Value.

happy weekend,

NeoTrader

-
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

Re: How can I capture an indicators max/min values ?

Post by lucklogic »

Code: Select all

double MyMax, MyMin;
int LookBack = 100;
double WprArray[100];

for ( i=0; i<=LookBack; i++) {
   WprArray[i] = Call to your WPR Indicator shift = i;
   MyMax = MathMax(MyMax, WprArray[i]);
   MyMin = MathMin(MyMin, WprArray[i]);
}
In order to work I just need to declare the dimensions of the array eg [100] rather than as a blank []

Thanks again :D :ugeek:
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: How can I capture an indicators max/min values ?

Post by NeoTrader »

hi lucklogic,
lucklogic wrote:In order to work I just need to declare the dimensions of the array eg [100] rather than as a blank []
It would be a cleaner solution to use ArrayResize(WprArray, LookBack)... this way the array will resize automatically to the value of your LookBack...in case you are going to change this value in your testing...or make it available es external Parameter ;)

Maybe you also need to set the Array as a timeSeries via ArraySetAsSeries(WprArray, true);


happy weekend,

NeoTrader

-
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: How can I capture an indicators max/min values ?

Post by gaheitman »

NeoTrader wrote:hi lucklogic,
lucklogic wrote:In order to work I just need to declare the dimensions of the array eg [100] rather than as a blank []
It would be a cleaner solution to use ArrayResize(WprArray, LookBack)... this way the array will resize automatically to the value of your LookBack...in case you are going to change this value in your testing...or make it available es external Parameter ;)

Maybe you also need to set the Array as a timeSeries via ArraySetAsSeries(WprArray, true);


happy weekend,

NeoTrader

-
It's not clear (to me, at least) why we are using an array in the first place. The code posted does not actually reference the array in a useful manner, it is only looking at the value we just put in it. We could just use a simple double to hold the result of the call to GetWPR(i).

In order to determine the best path forward, we need to know in what context you need this information. Are you using it in an EA, an indicator or a script? I would code them all differently.

George
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

Re: How can I capture an indicators max/min values ?

Post by lucklogic »

gaheitman wrote:
NeoTrader wrote:hi lucklogic,
lucklogic wrote:In order to work I just need to declare the dimensions of the array eg [100] rather than as a blank []
It would be a cleaner solution to use ArrayResize(WprArray, LookBack)... this way the array will resize automatically to the value of your LookBack...in case you are going to change this value in your testing...or make it available es external Parameter ;)

Maybe you also need to set the Array as a timeSeries via ArraySetAsSeries(WprArray, true);


happy weekend,

NeoTrader

-
It's not clear (to me, at least) why we are using an array in the first place. The code posted does not actually reference the array in a useful manner, it is only looking at the value we just put in it. We could just use a simple double to hold the result of the call to GetWPR(i).

In order to determine the best path forward, we need to know in what context you need this information. Are you using it in an EA, an indicator or a script? I would code them all differently.

George


Yes I see that you are (of course) correct. Both methods work, array or double and I'm happy that I can now capture the max/min.

I want to use the info in an EA
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: How can I capture an indicators max/min values ?

Post by gaheitman »

lucklogic wrote:
gaheitman wrote:
NeoTrader wrote:hi lucklogic,

It would be a cleaner solution to use ArrayResize(WprArray, LookBack)... this way the array will resize automatically to the value of your LookBack...in case you are going to change this value in your testing...or make it available es external Parameter ;)

Maybe you also need to set the Array as a timeSeries via ArraySetAsSeries(WprArray, true);


happy weekend,

NeoTrader

-
It's not clear (to me, at least) why we are using an array in the first place. The code posted does not actually reference the array in a useful manner, it is only looking at the value we just put in it. We could just use a simple double to hold the result of the call to GetWPR(i).

In order to determine the best path forward, we need to know in what context you need this information. Are you using it in an EA, an indicator or a script? I would code them all differently.

George


Yes I see that you are (of course) correct. Both methods work, array or double and I'm happy that I can now capture the max/min.

I want to use the info in an EA
I don't know how CPU intensive the WPR calculation is but if you keep track of it in an array, you might want to use it as a circular buffer so you only update the new value (look at the CentralBankInterventionModule() code in some of the EAs Steve has done).

George
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

Re: How can I capture an indicators max/min values ?

Post by lucklogic »

I don't know how CPU intensive the WPR calculation is but if you keep track of it in an array, you might want to use it as a circular buffer so you only update the new value (look at the CentralBankInterventionModule() code in some of the EAs Steve has done).

George

Code: Select all

 void StoreQuote()
{

   // fill the current tick value into the table
   TickTable[tc] = Bid;

   if (is_filled == 0) // table not full yet
   { 
      fill_check_counter += 1;
      if (fill_check_counter == TableSize) is_filled = 1;
   }//if (is_filled == 0)
   else 
   {
      TickDiff = MathAbs(TickTable[(tc + 1) % TableSize] - TickTable[tc]) * PipMultiplier;
   }//else   
      
      
   // increment the counter
   tc += 1;
   tc = tc % TableSize;// keeps tc within TableSize

}//End void StoreQuote()
  
Thanks for that advise and some of the relevant portion of the module, I have included above, unfortunately its above my pay grade to understand what's happening
Post Reply

Return to “Coders Hangout”