Download MetaTrader 5

How to use iMAOnArray() with Stochastic? - page 3

To add comments, please log in or register
Keith Watford
Moderator
9640
Keith Watford 2014.02.28 21:59  
double Signal_Stochastic[];

You declare your array, but you don't size it

Arav007
412
Arav007 2014.03.01 13:01  
GumRai:

You declare your array, but you don't size it


It might not the problem as I have seen many code with such declaration.

Yet if you feel it's wrong, please show the right one. Thanks

whroeder1
14750
whroeder1 2014.03.01 13:24  
Arav007:


It might not the problem as I have seen many code with such declaration.

Yet if you feel it's wrong, please show the right one. Thanks

There is nothing wrong "with such declaration". The problem, is you didn't size it later. Either explicitly, or automatically as a indicator buffer. Look again at your " I have seen many code"
Arav007
412
Arav007 2014.03.01 14:50  
WHRoeder:
There is nothing wrong "with such declaration". The problem, is you didn't size it later. Either explicitly, or automatically as a indicator buffer. Look again at your " I have seen many code"


Ok, what I have understood so far by the Array things:

int start()
{
sLog_Start = "START - start() function----------------------------------";

double Signal_Stochastic[];//....................................................................................L-1


sLog_Start = sLog_Start + sNL + "    Start - Set and Get MA values";

    ArraySetAsSeries(Signal_Stochastic, true);//................................................................L-2
   for( i=0; i<Bars; i++)
Signal_Stochastic[i] = iStochastic(NULL,0,75,5,5,MODE_SMA,0,MODE_SIGNAL,i);//...................................L-3

   double MA_Signal_Sto = iMAOnArray(Signal_Stochastic, 0,20,0,MODE_SMA,0);//...................................L-4
   

sLog_Start = sLog_Start + sNL + "    Signal Sto's Value=" +  Signal_Stochastic[0];..............................L-5
sLog_Start = sLog_Start + sNL + "    MA_Signal_Sto's Value=" +  MA_Signal_Sto;

if (Signal_Stochastic>MA_Signal_Sto)
{
Buy;
}
if (Signal_Stochastic<MA_Signal_Sto)
{
Sell;
}
return (0);
}

At Line 1(L-1): I have declared an array called 'Signal_Stochastic' with indefinite array size.

At L-2: Used AraySetAsSeries() function for Right to Left counting.

At L-3: Defined the Signal_Stochastic Array with a size of 'i' where 'i' keeps increasing from '0' to last bar available. The value of Signal Line of the Stochastic is getting calculated at every bar starting from the current bar to backward.

At L-4: Define Here this MA is getting fed from the Signal Line of Stochastic. But calculating Value of MA only for current bar.

At L-5: Tried to see the value of Signal Line for current bar.

But I know I have faults in understanding the code.

Keith Watford
Moderator
9640
Keith Watford 2014.03.01 15:01  
Arav007:


It might not the problem as I have seen many code with such declaration.

Yet if you feel it's wrong, please show the right one. Thanks


Try this script and notice that #propertystrict has been commented out. This is because an array out of range error is a critical error if #propertystrict is enabled

//+------------------------------------------------------------------+
//|                                                  Array check.mq4 |
//|                                                           GumRai |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "GumRai"
#property link      ""
#property version   "1.00"
//#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   double Signal_Stochastic[];
   int array_size = 5;
   
   for(int index=0; index < array_size; index++)
     {
     Signal_Stochastic[index]=index;
     Alert("index = ",index," Signal_Stochastic[",index,"] = ",Signal_Stochastic[index]);
     }
  }
//+------------------------------------------------------------------+

All the alerts will show zero

Add this single line of code to Resize the array

ArrayResize(Signal_Stochastic,array_size);


//+------------------------------------------------------------------+
//|                                                  Array check.mq4 |
//|                                                           GumRai |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "GumRai"
#property link      ""
#property version   "1.00"
//#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   double Signal_Stochastic[];
   int array_size = 5;
   ArrayResize(Signal_Stochastic,array_size);
   
   for(int index=0; index < array_size; index++)
     {
     Signal_Stochastic[index]=index;
     Alert("index = ",index," Signal_Stochastic[",index,"] = ",Signal_Stochastic[index]);
     }
  }
//+------------------------------------------------------------------+

And you will see that the Alerts are as expected

If you un-comment #property strict, you will see the alerts as doubles

Keith Watford
Moderator
9640
Keith Watford 2014.03.01 15:07  
Arav007:


Ok, what I have understood so far by the Array things:

At Line 1(L-1): I have declared an array called 'Signal_Stochastic' with indefinite array size.

At L-2: Used AraySetAsSeries() function for Dynamic object of the Array.

At L-3: Defined the Signal_Stochastic Array with a size of 'i' where 'i' keeps increasing from '0' to last bar available. The value of Signal Line of the Stochastic is getting calculated at every bar starting from the current bar to backward.

At L-4: Define Here this MA is getting fed from the Signal Line of Stochastic. But calculating Value of MA only for current bar.

At L-5: Tried to see the value of Signal Line for current bar.

But I know I have faults in understanding the code.

asff


But nowhere have you sized the array
Arav007
412
Arav007 2014.03.01 15:18  
GumRai:

But nowhere have you sized the array

Actually I 'm trying to Figure out this 'Array Sizing' thing. If there is any reference with example please give tat link. Thanks
Arav007
412
Arav007 2014.03.01 19:15  

No Luck yet. :(

couldn't find any satisfactory example.

Keith Watford
Moderator
9640
Keith Watford 2014.03.01 21:49  
Arav007:

No Luck yet. :(

couldn't find any satisfactory example.


I have already given you an example 4 posts back
123
To add comments, please log in or register