OnInit() - Check historical Bias?

 

When I drop an updated EA onto the given chart, it has no way of determining a bias from the historical price action. Instead, it will have to then wait for a bias to form off of the new price action. 

I am wanting to get the bias on initialization so that there is no lag or missing of setups when I make small updates to me EA (as I am missing trades because of this).

 This gauges the bias (moving averages first):

//+------------------------------------------------------------------+
//| Function checks for MA bias cross up or down on multiple TF's    |
//+------------------------------------------------------------------+
void CheckForMaTrade()
   {
   double CurrentSmallFish1   =  iMA(NULL,low,3,0,1,0,MA_Bias_Shift),  Hour4_3   =  iMA(NULL,middle,3,0,1,0,MA_Bias_Shift),  Daily_3   =  iMA(NULL,high,3,0,1,0,MA_Bias_Shift); 
   double CurrentSmallFish2   =  iMA(NULL,low,5,0,1,0,MA_Bias_Shift),  Hour4_5   =  iMA(NULL,middle,5,0,1,0,MA_Bias_Shift),  Daily_5   =  iMA(NULL,high,5,0,1,0,MA_Bias_Shift);
   double CurrentSmallFish3   =  iMA(NULL,low,8,0,1,0,MA_Bias_Shift),  Hour4_8   =  iMA(NULL,middle,8,0,1,0,MA_Bias_Shift),  Daily_8   =  iMA(NULL,high,8,0,1,0,MA_Bias_Shift);
   double CurrentSmallFish4   =  iMA(NULL,low,10,0,1,0,MA_Bias_Shift), Hour4_10  =  iMA(NULL,middle,10,0,1,0,MA_Bias_Shift), Daily_10  =  iMA(NULL,high,10,0,1,0,MA_Bias_Shift);
   double CurrentSmallFish5   =  iMA(NULL,low,12,0,1,0,MA_Bias_Shift), Hour4_12  =  iMA(NULL,middle,12,0,1,0,MA_Bias_Shift), Daily_12  =  iMA(NULL,high,12,0,1,0,MA_Bias_Shift);
   double CurrentSmallFish6   =  iMA(NULL,low,15,0,1,0,MA_Bias_Shift), Hour4_15  =  iMA(NULL,middle,15,0,1,0,MA_Bias_Shift), Daily_15  =  iMA(NULL,high,15,0,1,0,MA_Bias_Shift);
   double CurrentBigFish1     =  iMA(NULL,low,30,0,1,0,MA_Bias_Shift), Hour4_30  =  iMA(NULL,middle,30,0,1,0,MA_Bias_Shift), Daily_30  =  iMA(NULL,high,30,0,1,0,MA_Bias_Shift);
   double CurrentBigFish2     =  iMA(NULL,low,35,0,1,0,MA_Bias_Shift), Hour4_35  =  iMA(NULL,middle,35,0,1,0,MA_Bias_Shift), Daily_35  =  iMA(NULL,high,35,0,1,0,MA_Bias_Shift);
   double CurrentBigFish3     =  iMA(NULL,low,40,0,1,0,MA_Bias_Shift), Hour4_40  =  iMA(NULL,middle,40,0,1,0,MA_Bias_Shift), Daily_40  =  iMA(NULL,high,40,0,1,0,MA_Bias_Shift);
   double CurrentBigFish4     =  iMA(NULL,low,45,0,1,0,MA_Bias_Shift), Hour4_45  =  iMA(NULL,middle,45,0,1,0,MA_Bias_Shift), Daily_45  =  iMA(NULL,high,45,0,1,0,MA_Bias_Shift);
   double CurrentBigFish5     =  iMA(NULL,low,50,0,1,0,MA_Bias_Shift), Hour4_50  =  iMA(NULL,middle,50,0,1,0,MA_Bias_Shift), Daily_50  =  iMA(NULL,high,50,0,1,0,MA_Bias_Shift);
   double CurrentBigFish6     =  iMA(NULL,low,60,0,1,0,MA_Bias_Shift), Hour4_60  =  iMA(NULL,middle,60,0,1,0,MA_Bias_Shift), Daily_60  =  iMA(NULL,high,60,0,1,0,MA_Bias_Shift);
   double ema21               =  iMA(NULL,low,Trigger_Period,0,1,0,MA_Bias_Shift);


   
  // Check for Moving Averages Fanned up ON THE DAILY TIME FRAME, creating an UP bias.   
    if(D1_Bias=="None") 
      if(Daily_3>Daily_5)
         if(Daily_5>Daily_8)
            if(Daily_8>Daily_10)
               if(Daily_10>Daily_12)
                  if(Daily_12>Daily_15)
                     if(Daily_15>Daily_30)
                        if(Daily_30>Daily_35)
                           if(Daily_35>Daily_40)
                              if(Daily_40>Daily_45)
                                 if(Daily_45>Daily_50)
                                    if(Daily_50>Daily_60)
                                       {
                                       D1_Bar = iTime(NULL, high, 1);
                                       D1_Bias="Daily is Up";
                                       Comment("D1 Bias is: "+D1_Bias+" since: "+TimeToStr(D1_Bar,TIME_DATE|TIME_MINUTES),
                                          "\nH4 Bias is: "+H4_Bias,
                                          "\nH1 Bias is: ",H1_Bias);
                                       }
  
  // Check for Moving Averages Fanned up ON THE 4 HOUR TIME FRAME, creating an UP bias.  
    if(D1_Bias=="Daily is Up" && H4_Bias=="None" ) 
      if(Hour4_3>Hour4_5)
         if(Hour4_5>Hour4_8)
            if(Hour4_8>Hour4_10)
               if(Hour4_10>Hour4_12)
                  if(Hour4_12>Hour4_15)
                     if(Hour4_15>Hour4_30)
                        if(Hour4_30>Hour4_35)
                           if(Hour4_35>Hour4_40)
                              if(Hour4_40>Hour4_45)
                                 if(Hour4_45>Hour4_50)
                                    if(Hour4_50>Hour4_60)
                                       {
                                       H4_Bar = iTime(NULL, middle, 1);
                                       H4_Bias="4 Hour is Up";
                                       Comment("D1 Bias is: "+D1_Bias+" since: "+TimeToStr(D1_Bar,TIME_DATE|TIME_MINUTES),
                                          "\nH4 Bias is: "+H4_Bias+" since: "+TimeToStr(H4_Bar,TIME_DATE|TIME_MINUTES),
                                          "\nH1 Bias is: ",H1_Bias);
                                       }
   
   // Check for Moving Averages Fanned up on H1, creating an UP bias.
   if(D1_Bias=="Daily is Up" && H4_Bias=="4 Hour is Up" && H1_Bias=="None")
      if(CurrentSmallFish1>CurrentSmallFish2)
         if(CurrentSmallFish2>CurrentSmallFish3)
            if(CurrentSmallFish3>CurrentSmallFish4)
               if(CurrentSmallFish4>CurrentSmallFish5)
                  if(CurrentSmallFish5>CurrentSmallFish6)
                     if(CurrentSmallFish6>CurrentBigFish1)
                        if(CurrentBigFish1>CurrentBigFish2)
                           if(CurrentBigFish2>CurrentBigFish3)
                              if(CurrentBigFish3>CurrentBigFish4)
                                 if(CurrentBigFish4>CurrentBigFish5)
                                    if(CurrentBigFish5>CurrentBigFish6)
                                    {
                                    triggerBarTime = iTime(NULL, low, 1);
                                    H1_Bias="H1 is Up";
                                    Comment("D1 Bias is: "+D1_Bias+" since: "+TimeToStr(D1_Bar,TIME_DATE|TIME_MINUTES),
                                            "\nH4 Bias is: "+H4_Bias+" since: "+TimeToStr(H4_Bar,TIME_DATE|TIME_MINUTES),
                                            "\nH1 Bias is: "+H1_Bias+" since: "+TimeToStr(triggerBarTime,TIME_DATE|TIME_MINUTES));

...

 (If this is really difficult to read because it does not fit onto your screen without scrolling, then let me know and I will shift it over to the left for easier reading)

As you can see, this will only look at the previous bars close and find out if they're "up" or "down". 

What I am wanting is as soon as the EA is dropped onto the chart, I want to find the historical bias - as long as the "low" (which is 60 minute) is ABOVE the 60 ema (on the H1 TF) - of the specific date and time of the bar where all the MA's on the H1 TF (or "low")  were fanned up?

 

Have a look at some indicators.

They start their "painting" at ~ Bars-1.

You can do this in your EA as well - I think this is what you are looking for(?) like:

bool IsIni = false;
void OnTick() {
   if ( !IsIni ) {
      int start = Bars - MaxIndiPeriods-1;
      for (i=start;i>=0;i--) {
          ...
      }
      IsIni = true;
   }
   ... // EA logic
   
}

By the way bias means for you trend?

 

I think I understand... Yea bias is trend direction. I am a little confused on how it is I search back a specific number of bars until a certain if statement is false?

To make it clear and relative to above's code that I have pasted these are the steps:

  1. Is Bar[1] > 60ema (on "low" tf) if it equals "True", then search back to the specific bar datetime where-by all the MA's were fanned up.
  2. In order for number 1 to be checked, Bar[1] (ON H4 TF) HAS to be > 60ema (on "middle" tf which is H4).
  3. In order for number 1 to be checked, 2 and 3 have to be true. This one is, Bar[1] (on D1 TF) HAS to be > 60 ema (on "high" tf which is D1). 

 

hmm - it hard for me to understand you.

Close[0] is the most recent close, Close[1] the close of the last completely closed bar and Close[Bars-1] the first (oldest) bar close.

 

Maybe this screen will help? http://screencast.com/t/kJbq1tRXN

 The top red line is the 60ema. As long as price remains closed beneath that level, then the candle I have highlighted == True and that is the bar I want to look back to and start from (as opposed to working with just the candle [1] I drop the EA on). 

 

1) If my cursor is above a candle a little wondow pops up with time op,hi,lo,cl (sometimes) at least the marketwatch shows all the data of that candle.

2) you cannot place an EA on a single bar, you attach it to a chart valid for all bars!

 
I think you're taking what I am saying literally. I am well aware of how the fundamentals of an EA work. Despite my numerous threads on here asking for guidance, I am not that simple lol ;)

I am wanting my EA to "look-back" instead of working with the current bar in the equation of gaining the MA bias... 
 

As I said in my first post start calc from the beginning of the chart that is from Bars-1 down to 0.

 
Ok thanks. Ill have a play with it later :) 
 
gooly: As I said in my first post start calc from the beginning of the chart that is from Bars-1 down to 0.
Something like
datetime LastAnalyzed = 0;
void Analyze(){
   for(int iBar = iBarShift(NULL,0, LastAnalyzed); iBar >= 0; --iBar{
      isUp = Bar[1] > iMA(... iBar);
      :
   }
   LastAnalyzed = Time[0];
}
 

Thanks WHRoeder. Makes perfect sense what you're saying there.

 I had an additional thought: Is it possible so that on OnInit() I can specify a specific Bar (extern) to work from? Basically, if I see the chart, it may just be easier that when the EA is dropped onto the chart I can specify to the EA the bar in which the MA's were first fanned down. After-all, for what I need it for does not need to be mathematically precise. Just needs to be roughly (too long winded to explain).

Is this possible? 

Reason: