still getting this bugged

 

I want to get this to work what I wanted to do is,

first off I want it to calculate how many bars whent the opposite side on previous ones, it should be incrementing the past bars and checking the way they took to increment me a number (multiplier) to add to my ea. the rest of the ea goes like a charm but this part I just don't get how it should be working. I tought maybe it's an obvious error to more experimented programmers still tough I have the problem. It gives me randomly weird multipliers trough comments not according to the actual chart I have in front of me.

//+------------------------------------------------------------------+
//|                                          TimeFrameCalculator.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
bool done;
int previousbar;
int barcount;
double openprice2;
double closeprice2;
double openprice1;
double closeprice1;
int nexttype1;
int nexttype2;
int multiplier;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   barcount = 1;
   done = false;
             while (done != true)
               {
               // Adding 1 to the bar I have fixed
                  previousbar = barcount+1;
                  openprice1 = iOpen(Symbol(),Period(),barcount);
                  closeprice1 = iClose(Symbol(),Period(),barcount);
                  // close - open gives me the direction the fixed bar took
                  if ((closeprice1 - openprice1) > 0) nexttype1 = OP_BUY;
                  if ((closeprice1 - openprice1) < 0) nexttype1 = OP_SELL;                  
                  openprice1 = iOpen(Symbol(),Period(),previousbar);
                  closeprice1 = iClose(Symbol(),Period(),previousbar);
                  // same operation for the bar before
                  if ((closeprice2 - openprice2) > 0) nexttype2 = OP_BUY;
                  if ((closeprice2 - openprice2) < 0) nexttype2 = OP_SELL;
                  // comparing the bar directions using the nexttype to figure it out
                  // if this is not the same I loop back to the top while incrementing the barcount
                  if (nexttype1 != nexttype2) barcount++;
                  // if this is the same I'm fixed and I can break the loop
                  if (nexttype1 == nexttype2)
                     {
                        multiplier = barcount;
                        done = true;
                     }
               }   
      Comment("TimeFrame: " ,Period(),"\nNombre de Changements:" ,barcount,"\nMultiplicateur:" ,multiplier);
  }
 
                 
                  openprice1 = iOpen(Symbol(),Period(),previousbar);
                  closeprice1 = iClose(Symbol(),Period(),previousbar);
                  // same operation for the bar before
                  if ((closeprice2 - openprice2) > 0) nexttype2 = OP_BUY;
                  if ((closeprice2 - openprice2) < 0) nexttype2 = OP_SELL;

 
GumRai:




obvious wasen't it! thanks for your time GumRai
 
liquidd:


obvious wasen't it! thanks for your time GumRai


I suspect that you do the same as I do

copy and paste some lines of code because you will only need to change a little bit. Then you forget to do the changes and no matter how hard you look, you just can't see it.

I have done it soooo many times!

Reason: