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

 
double Signal_Stochastic[];

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

 
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

 
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"
 
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.

 
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

 
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
 
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
 

No Luck yet. :(

couldn't find any satisfactory example.

 
Arav007:

No Luck yet. :(

couldn't find any satisfactory example.


I have already given you an example 4 posts back
Reason: