Using iMAOnArray() function correctly.

Post Reply
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Using iMAOnArray() function correctly.

Post by Arav »

Hello All,
Hope you are doing fine.

I am having problem with defining 'iMAOnArray()' function.
I am planning a strategy with 'Stochastic Crossover' with Moving Average in the 'Precious Indicator's Data'. [See the attached Image, Yellow one is the MA]
The idea is when the MA will cross the 'Signal Line' of Stochastic, it'll produce Buy/Sell accordingly.

I have tried to get idea about 'iMAOnArray' and arranged things like this:

Code: Select all

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

double Signal_Stochastic[];


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

    ArraySetAsSeries(Signal_Stochastic, true);
   for( i=0; i<Bars; i++)
Signal_Stochastic[i] = iStochastic(NULL,0,20,10,20,MODE_SMA,0,MODE_SIGNAL,i);

   double MA_Signal_Sto = iMAOnArray(Signal_Stochastic, 0,20,0,MODE_SMA,0);
   

sLog_Start = sLog_Start + sNL + "    Signal Sto's Value=" +  Signal_Stochastic[0];
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);
}

But matter of great regret is that I am not getting any value other than '0' for Signal Line and MA.

Signal Sto's Value=0.000000000
MA_Signal_Sto's Value=0.00000

So I am doing it wrong. So please correct me or refer me to the example where such MA crossover with Stochastic is discussed elaborately.

Thanks
You do not have the required permissions to view the files attached to this post.
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Using iMAOnArray() finction correctly.

Post by milanese »

Arav » Sat Mar 01, 2014 1:17 pm wrote:Hello All,
Hope you are doing fine.

I am having problem with defining 'iMAOnArray()' function.
I am planning a strategy with 'Stochastic Crossover' with Moving Average in the 'Precious Indicator's Data'. .......
But matter of great regret is that I am not getting any value other than '0' for Signal Line and MA.

Signal Sto's Value=0.000000000
MA_Signal_Sto's Value=0.00000

So I am doing it wrong. So please correct me or refer me to the example where such MA crossover with Stochastic is discussed elaborately.

Thanks
Your code can't work..

you should try something like

Code: Select all

double Signal_Stochastic[];
 bool Buy_Signal=false;
 bool Sell_Signal=false;
 
       int OnInit(void)
  {
       if(ArraySize(Signal_Stochastic) < Bars)
     {
       ArraySetAsSeries(Signal_Stochastic, false);
      //----
       ArrayResize(Signal_Stochastic, Bars);
       //----
       ArraySetAsSeries(Signal_Stochastic, true);
      
     } 
     return(0);
     }
       
       void OnTick()
  {
       
        Buy_Signal=false;
        Sell_Signal=false;
        int i=0;
        
         
         
        
         
            
           for( i=0; i<Bars; i++)
        Signal_Stochastic[i] = iStochastic(NULL,0,20,10,20,MODE_SMA,0,MODE_SIGNAL,i);
         
           double MA_Signal_Sto = iMAOnArray(Signal_Stochastic, 0,20,0,MODE_SMA,0);
           
         
        
         
        if (Signal_Stochastic[0]>MA_Signal_Sto)
        {
        Buy_Signal=true;
        }
        if (Signal_Stochastic[0]<MA_Signal_Sto)
        {
        Sell_Signal=true;
        }
       
        }
Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Using iMAOnArray() finction correctly.

Post by Arav »

Your code can't work..
Hello Thanks a lot that you took time for giving solution. I'll try it for sure.
Just another request, is it possible to show why my code wouldn't work?

I am learning now. So it is necessary for me to know why it failed. Otherwise if I just copy a template then things will work but my skills wont develop.
Thanks once again.

Regards
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Using iMAOnArray() finction correctly.

Post by milanese »

Arav » Sat Mar 01, 2014 8:01 pm wrote:
Your code can't work..
Hello Thanks a lot that you took time for giving solution. I'll try it for sure.
Just another request, is it possible to show why my code wouldn't work?

I am learning now. So it is necessary for me to know why it failed. Otherwise if I just copy a template then things will work but my skills wont develop.
Thanks once again.

Regards
Hi,

using Signal_Stochastic<MA_Signal_Sto will not work as Signal_Stochastic is an array, this is an invalid array access, so you must use Signal_Stochastic[0] or what ever bar you want to have checked.
And you need to set a size for your array, so ArrayResize(Signal_Stochastic, Bars); is needed ..

Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Using iMAOnArray() finction correctly.

Post by Arav »


using Signal_Stochastic<MA_Signal_Sto will not work as Signal_Stochastic is an array, this is an invalid array access, so you must use Signal_Stochastic[0] or what ever bar you want to have checked.
And you need to set a size for your array, so ArrayResize(Signal_Stochastic, Bars); is needed ..

Cheers :)

Tommaso
Thanks a lot for the reply.
You know what I have seen many 'Programmers' who just don't tell the exact point rather extends the conversation by giving Hints to the solution indirectly. But they don't understand that 'Programming' is not 'Mathematics' like you know the 'Laws', you know the ways of 'Calculations', now you have to figure out the solutions by brain storming.
Programming is the summation of a bunch of 'Pre-Defined' compatible languages which need to be followed strictly. If anything needs to be defined, it needs to Exactly like what is 'Pre-Defined'. You can't be innovative in doing that in a different way like 'Mathematics'. [Though one can implement a Logic in different ways like using for/while/if]

So as a Newbie it is really tough to figure out the mistake(s). Especially when you are trying to learn by yourself with the help of some basic books and other experienced coders.
They can just tell where the Problem is or what was wrong and give the solution or Hint directly thus Newbie can understand "okay, the way of defining this is like that and I have done this wrong".
But I hardly found anyone does like this.
I have even got a one page 'Lecture' on how to improve myself as a 'Coder' but didn't get anything about my 'Mistake' and it's reason which could be told withing 'Few' lines!

That's why I am Grateful to you that at least you weren't like 'Others'.
Post Reply

Return to “Coders Hangout”