# Create a loop for rights ```mq4 int OnCalculate(...) { // // wait to pass bars until we have rights ... if (rates_total <= InpPeriod) { // // return not calculated ... return 0; } // // find loop count for bars manipulation ... int count = (prev_calculated == 0) ? rates_total - InpPeriod - 1 : rates_total - prev_calculated + 1; // // this is the main loop of calculations, for each bar index ... for (int i = count - 1; i >= 0; i--) { } // // return current calculated ... return rates_totlat; } ```