Download MetaTrader 5
To add comments, please log in or register
Order the development and track its status via your mobile phone.
liquidd
170
liquidd 2014.03.06 21:09 

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);
  }
Keith Watford
Moderator
7886
Keith Watford 2014.03.06 22:08  
                 
                  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;

liquidd
170
liquidd 2014.03.07 11:31  
GumRai:




obvious wasen't it! thanks for your time GumRai
Keith Watford
Moderator
7886
Keith Watford 2014.03.07 11:52  
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!

/
To add comments, please log in or register