Build an Array serie of "Period"

 

Hi guys,

i want to know how build an array serie (i think) of period?

HighPriceM30= iHigh(Symbol(),PERIOD_M30,1);
LowPriceM30= iLow(Symbol(),PERIOD_M30,1);

HighPriceH1= iHigh(Symbol(),PERIOD_H1,1);
LowPriceH1= iLow(Symbol(),PERIOD_H1,1);

The aim is simplify the code. Maybe it is not an array what i need. The code which i think is like that:

HighPrice= iHigh(Symbol(),Period_selected,1);
LowPirce= iLow(Symbol(),Period_Selected,1);

Thanks by advance for your answers.

 
Kane59:

Hi guys,

i want to know how build an array serie (i think) of period?

The aim is simplify the code. Maybe it is not an array what i need. The code which i think is like that:

Thanks by advance for your answers.

Not sure what you are trying to achieve,  you haven't said . . .  why can't you use the 2nd code example you gave ?
 
RaptorUK:
Not sure what you are trying to achieve,  you haven't said . . .  why can't you use the 2nd code example you gave ?


Hi,

i want to simplify my code and attach a TP to the period selected: M30= TP 2pips, H1= TP 5 pips, ... like:

int period_selected = M30, H1, H4, D1;
double Takeprofit= 2,5,10,15;

HighPrice= iHigh(Symbol(),Period_selected,1);
LowPirce= iLow(Symbol(),Period_Selected,1);
 
Kane59:

Hi,

i want to simplify my code and attach a TP to the period selected: M30= TP 2pips, H1= TP 5 pips, ... like:

OK,  so in init()  use a switch statement to set the TP dependant on the timeframe selected . . . 

exterm int TimeFrame = 60;



init()
   {
   
   switch(TimeFrame)
      {
      case PERIOD_M30: {TP = 2;  break;} 
      case PERIOD_H1:  {TP = 5;  break;} 
      case PERIOD_H4:  {TP = 10; break;} 
      case PERIOD_D1:  {TP = 20; break;} 
      }
   }
   
 

I will give my code:

   double         HighPrice,LowPrice,openCandle,closeCandle; 
   int            Periode_selected = 30,60,240;
   
   HighPrice= iHigh(Symbol(),PERIOD_M30,1);
   LowPrice= iLow(Symbol(),PERIOD_M30,1);
   closeCandle= iClose(Symbol(),PERIOD_M30,1);
   openCandle= iOpen(Symbol(),PERIOD_M30,1);



   if (openCandle<closeCandle)
   {
      OrderSend(Symbol(),OP_SELLSTOP,0.1,LowPrice,0,0,(TP of selected TimeFrame),NULL,0,iTime(Symbol(), PERIOD_D1, 0 ) + (5*2*86395));
   }
   if (openCandle>closeCandle)
   {  
      OrderSend(Symbol(),OP_BUYSTOP,0.1,HighPrice,0,0,(TP of selected TimeFrame),NULL,0,iTime(Symbol(), PERIOD_D1, 0 ) + (5*2*86395));
   }
Is it correct? And where place your swith code?
 
Kane59:

I will give my code:

Is it correct? And where place your swith code?


This is not correct,  it will not compile  . . .

int Periode_selected = 30,60,240;

 . . .  how will the Periode be set ?  by the user in an extern ?  hard coded ?

 

My code is not to be placed,  it is an example of what you could use . . .  do you understand it ?  is it correct ?

RaptorUK:

OK,  so in init()  use a switch statement  . . . .

Why aren't you checking the return value from your OrderSend() ?  don't you want to know if it fails ?  don't you want to know the error code if it fails ?  don't you want to know the values of key variables used with your OrderSend() when it fails so you can determine why it failed ?

 

This will help:   What are Function return values ? How do I use them ?

 
RaptorUK:


This is not correct,  it will not compile  . . .

 . . .  how will the Periode be set ?  by the user in an extern ?  hard coded ?

 

My code is not to be placed,  it is an example of what you could use . . .  do you understand it ?  is it correct ?

Why aren't you checking the return value from your OrderSend() ?  don't you want to know if it fails ?  don't you want to know the error code if it fails ?  don't you want to know the values of key variables used with your OrderSend() when it fails so you can determine why it failed ?

 

This will help:   What are Function return values ? How do I use them ?

 

I will add code to have errors codes. Periodes can be set by users by extern. For all subjects, i'm sorry i begin in MQL4, i don't see all code ican to use or how to use.
 
Kane59:
I will add code to have errors codes. Periodes can be set by users by extern. For all subjects, i'm sorry i begin in MQL4, i don't see all code ican to use or how to use.

No need to apologise . . . .  we are all still learning  :-)
Reason: