Download MetaTrader 5
To add comments, please log in or register
Publish your task in Freelance service and developers will execute your order.
Brendan
650
Brendan 2016.08.25 09:13 

hi, I'm fairly new to coding but I cant seem to work out what I need to change in this section of code to make the third candle in the trade set up to close lower then it opened for sell trade, and higher then it opened for buy trade. Thanks for your help.

bool inside_bar = false;
  if(rates[3].high > rates[2].open && rates[3].low < rates[2].open && rates[3].high > rates[2].close && rates[3].low < rates[2].close) inside_bar = true;
 
  if(inside_bar && rates[1].close < 0.5*(rates[1].high + rates[1].low) &&
    ( (rates[1].high > rates[2].high && rates[1].low > rates[2].low) || (rates[1].high > rates[2].high && rates[1].close < rates[2].low) ) ) {
     value = SELL;
     pend_price = rates[1].high - PendingPercent*0.01*(rates[1].high- rates[1].low);
  }
  else
  if(inside_bar && rates[1].close > 0.5*(rates[1].high + rates[1].low) &&
    ( (rates[1].low < rates[2].low && rates[1].high < rates[2].high) || (rates[1].low < rates[2].low && rates[1].close > rates[2].high) ) ) {
     value = BUY;
     pend_price = rates[1].low + PendingPercent*0.01*(rates[1].high- rates[1].low); 
Ernst Van Der Merwe
4479
Ernst Van Der Merwe 2016.08.25 12:13  

The high/low of the second bar should also be lower/higher than the third for an inside bar. Other than that it seems ok.

      CopyRates(NULL,0,1,3,rates);
      ArraySetAsSeries(rates,true);
      
      bool inside_bar = (rates[2].high > rates[1].high && 
                         rates[2].low < rates[1].low/* && 
                         rates[2].high > rates[1].close && 
                         rates[2].low < rates[1].close*/);
 
      if(inside_bar && 
         rates[0].close < (rates[0].high + rates[0].low)*0.5 &&
       ((rates[0].high > rates[1].high && 
         rates[0].low > rates[1].low) || 
        (rates[0].high > rates[1].high && 
         rates[0].close < rates[1].low))) 
        {
         value = SELL;
         pend_price = rates[0].high - PendingPercent*0.01*(rates[0].high- rates[0].low);
        }
      else if(inside_bar && 
         rates[0].close > (rates[0].high + rates[0].low)*0.5 &&
       ((rates[0].low < rates[1].low && 
         rates[0].high < rates[1].high) || 
        (rates[0].low < rates[1].low && 
         rates[0].close > rates[1].high)))
        {
         value = BUY;
         pend_price = rates[0].low + PendingPercent*0.01*(rates[0].high- rates[0].low); 
        }    
/
To add comments, please log in or register