1
votes

I'm trying to develop an Expert Advisor, so far I can understand and write this which will place orders when a new bar opens.

int BarsCount = 0;

int start()
{   if ( Bars >  BarsCount )
    {    OrderSend( Symbol(), OP_BUY, 0.01, Ask, 2, NULL, NULL );                            
         BarsCount = Bars;
    }
    return( 0 );
}

how to get the highest value of standard deviation for last 2 hours to a variable?

E.g.: lets say the EA runs in a 30 mins chart and the bar1 has the standard deviation value 0.003, and bar2 has 0.001, bar3 has 0.004 and bar4 has 0.001. So, the highest value for past 4 hours is bar3 which has the value of 0.004, so how to get that value to a variable?

I'm trying to make the EA place orders when this formula is true:

 ( ( current_value_of_standard_deviation
   / highest_value_of_standard_deviation_for_last_2_hours
     )
   * 100
   ) > 10
1

1 Answers

0
votes

Use built-in tools:

input  int    MA_period = 27;
       int    BarsCount = 0;
       int    nCells2CMP= ( PERIOD_H1 * 2 / PERIOD_CURRENT ) - 1;
       double Sig2H[100];

void OnInit(){
     ...
}

void OnTick(){
     if ( Bars >  BarsCount ){
          if (    BarsCount == 0 ){
                  for ( int i = MA_period; i >  0; i-- ){
                        Sig2H[i] = iStdDev( _Symbol,
                                            PERIOD_CURRENT,
                                            0,
                                            MODE_SMA,
                                            PRICE_CLOSE,
                                            i
                                            );
                  }
          }
          for ( int i = MA_period; i > 1; i-- )  Sig2H[i] = Sig2H[i-1];
          Sig2H[1] = iStdDev( _Symbol,           // symbol 
                              PERIOD_CURRENT,    // timeframe 
                              MA_period,         // MA averaging period 
                              0,                 // MA shift 
                              MODE_SMA,          // MA averaging method 
                              PRICE_CLOSE,       // applied price 
                              1                  // shift 
                              );
     }
     Sig2H[0] = iStdDev( _Symbol,           // symbol 
                         PERIOD_CURRENT,    // timeframe 
                         MA_period,         // MA averaging period 
                         0,                 // MA shift 
                         MODE_SMA,          // MA averaging method 
                         PRICE_CLOSE,       // applied price 
                         0                  // shift 
                         );
     if ( 0.1 < ( Sig2H[0]
                / Sig2H[ArrayMaximum( Sig2H,
                                      nCells2CMP,
                                      1
                                      )
                        ]
                  )
          ){...}
}