Download MetaTrader 5

HELP WITH CODE - page 2

To add comments, please log in or register
whroeder1
14780
whroeder1  
xavilin:i finally came with this, hope now works.
   ArrayResize(KAMA,MK_Period+5);
   ArrayResize(MK,5);
   Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;           // Index of the first uncounted
   while(i>=0)                      // Loop for uncounted bars
     {KAMA[i] = ...
      MK[i] = iM ...
 
Your chart may have thousands of Bars, but you are assigning those thousands to KAMA[] that has only MK_Period+5 elements and MK[] that has only five..
xavilin
48
xavilin  
WHRoeder:
xavilin:i finally came with this, hope now works.
Your chart may have thousands of Bars, but you are assigning those thousands to KAMA[] that has only MK_Period+5 elements and MK[] that has only five..

yes, as i only want enough KAMA[] data to calculate momentum over it, and i only need 3 MK[] data to decide whether to buy, sell or nothing. if this is what i want to achieve, did i do the correct thing? or will i be saving the oldest data and need to set array as series to have it work under FIFO and have always the latest 5 (or MK_Period+5)? thanks
xavilin
48
xavilin  
WHRoeder:
xavilin:i finally came with this, hope now works.
Your chart may have thousands of Bars, but you are assigning those thousands to KAMA[] that has only MK_Period+5 elements and MK[] that has only five..

Do you think this is correct or should i opt for a "for" loop?


   while(i>=0 && i<=MK_Period+5)                      // Loop for uncounted bars
     {KAMA[i] = iCustom(NULL,0,"kaufman-adaptive-moving-average",K_Period,K_Fast,K_Slow,5,i);   //array containing KAMA data      
      i--; }                        // Calculating index of the next bar;}
   while(i>=0 && i<=5)
     {MK[i] = iMomentumOnArray(KAMA,50,MK_Period,i);       //array containing MomentumKAMA data
      i--; }    
whroeder1
14780
whroeder1  
xavilin: Do you think this is correct or should i opt for a "for" loop?
  1. A while loop and a for loop are interchangeable
  2. After the first loop i will be -1. What do you think the second loop will do?
xavilin
48
xavilin  
WHRoeder:
xavilin: Do you think this is correct or should i opt for a "for" loop?
  1. A while loop and a for loop are interchangeable
  2. After the first loop i will be -1. What do you think the second loop will do?

so restarting i would be the answer? thanks! it costed a bit, but finally came to the correct thing, didn't i? thousands of thanks, your bare phrases made me think and search a lot.
12
To add comments, please log in or register