Help needed: - page 2

 
FrenchyTrader:

It would be very ugly I know, but this is the way I can do it:

// GET Candle closed price:
double Candle_1 = iClose(Symbol(),PERIOD_H1,1);

you missed candle No. 0

// GET iMA closed price:
double MA_1 = iMA(Symbol(),60,21,0,MODE_SMMA,PRICE_CLOSE,1);

the same thing here

I guess there is more dynamic way... but how?

Thank you for helping

 
qjol:

you missed candle No. 0


Candle 0 hasn't closed yet.

Maybe it's my eyes, but when you highlight text with the colour red, it makes it almost impossible to read.

 

Thank you so much GumRai


    int counter=0;              //count number of candles that satify condition
   for(int x=1;x<=12;x++)
     {
      int Period_MA = 15;
      // GET Candle closed price:
      double Candle=iClose(Symbol(),Period_MA,x);

      // GET iMA closed price:
      double MA=iMA(Symbol(),Period_MA,7,0,MODE_SMA,PRICE_CLOSE,x);
            
      // for (int y=x+1;y<=x+5;y++)
      // I see for each "x", it needs to loop/calculate if "y" (5 last candles in row are above MAx+1,... MAx+5) 
      // this is the hard part... If I read it I will understand, but too noob to code.
      
      // copy paste it's my friend : )
      double Candle_1=iClose(Symbol(),Period_MA,x+1);
      double Candle_2=iClose(Symbol(),Period_MA,x+2);
      double Candle_3=iClose(Symbol(),Period_MA,x+3);
      double Candle_4=iClose(Symbol(),Period_MA,x+4);
      double Candle_5=iClose(Symbol(),Period_MA,x+5);
      
      double MA_1=iMA(Symbol(),Period_MA,7,0,MODE_SMA,PRICE_CLOSE,x+1);
      double MA_2=iMA(Symbol(),Period_MA,7,0,MODE_SMA,PRICE_CLOSE,x+2);
      double MA_3=iMA(Symbol(),Period_MA,7,0,MODE_SMA,PRICE_CLOSE,x+3);
      double MA_4=iMA(Symbol(),Period_MA,7,0,MODE_SMA,PRICE_CLOSE,x+4);
      double MA_5=iMA(Symbol(),Period_MA,7,0,MODE_SMA,PRICE_CLOSE,x+5);
      
      // CHECK Condition
      if(Candle<MA && Candle_1<MA_1 && Candle_2<MA_2 && Candle_3<MA_3 && Candle_4<MA_4 && Candle_5<MA_5)
         counter++;
         
         if(counter > 0){ int Condition = 1; // true
                          }
     }
   Print("There were ",counter," series of 5 candles that closed above the MA"," Condition= ",Condition);
 

I know the error:


      // CHECK Condition
      if(Candle>MA && Candle_1>MA_1 && Candle_2>MA_2 && Candle_3>MA_3 && Candle_4>MA_4 && Candle_5>MA_5)
         counter++;
 
GumRai:


Maybe it's my eyes, but when you highlight text with the colour red, it makes it almost impossible to read.


fixed, (Special for you ;-) )
 
qjol:

fixed, (Special for you ;-) )

Thank you, maybe it doesn't bother anyone else, but it actually makes my eyes ache trying to read black writing on a red background (and vice-versa)
 
it depends on the age
 
FrenchyTrader:

Thank you so much GumRai


int Period_MA = 15;

This is confusing, you are not using this as an MA period, you are using it for the timeframe.

Using enumerations is a good habit to form

int t_frame=PERIOD_M15;

Always try to think about how to logically simplify your code.

I have not tested this

   int t_frame=PERIOD_M15;
   int counter=0;              //count number of candles that satify condition
   int series_counter=0;
   for(int x=1;x<=40;x++)
     {
      // GET Candle closed price:
      double Candle=iClose(Symbol(),t_frame,x);

      // GET iMA closed price:
      double MA=iMA(Symbol(),t_frame,7,0,MODE_SMA,PRICE_CLOSE,x);
      // CHECK Condition
      if(Candle>MA)
         counter++;
      else
         counter=0;
      if(counter==5)
         {
         series_counter++;
         counter--;
         }
            
     }
   Print("There were ",series_counter," series of 5 candles that closed above the MA");
  }
 
FrenchyTrader:

Hi all,

Please help and advise how to do this:

What you want the indicator to do ? Arrows when it happens ? Draw a line ? Create an object of some sort ? An Alert ?

3 parameters:

Total_Candles = 40 This is your moving average period 40 - is this SMA, EMA, other ?

Above_Candles = 5

1 moving average as reference.


Condition 1:

If At least 5 candles in a row closes above Moving average over the last 40 candles, then Condition_1 is valid.

So condition 1 - the close of 5 consecutive candles to be above the MA value of the corresponding candle, then do what ?

Question:

What is the proper function to use to check Condition_1?

A little example would be appreciated : )


Thank you


A bit more detail if you want more detailed advice ?

Are you building an indicator or an EA ?

 

And now in order to avoid copy paste... How can we dynamically test Condition_1 for various Timeframes (from PERIOD_M15 to PERIOD_D1) ?


Example:

How to store data for:

PERIOD_M15_Condition_1 = 1;

...
PERIOD_D1_Condition_1 = 0;