[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 258

 
Yuri, can you suggest something on my question just above?
 
dzhini:

Can you tell me how to specify the condition for the Tester to determine the bar number of the lower timeframe within the text.

For example: The tester starts with H1, then it determines the start time of the n-th candle in the textframe, and the next step is to determine the number of the candle, which started at the same time, but by the timeframe below. iBarShift always writes 0. The block responsible for the bar calculation is below:

This is not the way to do it. In the tester, you have to run the owl on the minimum TF used in this owl at the opening prices. It is better to run the owl on the open on minutes. And it is better to prescribe the TF, explicitly!
 
dzhini:
Yuri, can you suggest something about my question just above?


Checking script

//+------------------------------------------------------------------+
//|                                             VininI_CheckTime.mq4 |
//|                                            Copyright 2012, Vinin |
//|                                                    vinin@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, Vinin"
#property link      "vinin@mail.ru"



//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int TimeFrame[]={PERIOD_MN1, PERIOD_W1, PERIOD_D1, PERIOD_H4, PERIOD_H1,PERIOD_M30, PERIOD_M15, PERIOD_M5, PERIOD_M1};
   int i, pos;
   for (i=0;i<ArraySize(TimeFrame);i++) {
      if (Period()<TimeFrame[i]) continue;
      pos=i;
      break;
   }
   for (i=pos+1;i<ArraySize(TimeFrame);i++) {
      int tmp=iBarShift(NULL, TimeFrame[i], Time[0], true);
      if (iTime(NULL, TimeFrame[i], tmp)<Time[0])tmp--;
      Print("TimeFrame: ",  TimeFrame[i], " TimeOpen: ", TimeToStr(iTime(NULL, TimeFrame[i], tmp), TIME_MINUTES), " Bar: ", tmp);
      
   
   
   }
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Result

2012.07.17 20:42:45 VininI_CheckTime EURUSD,Daily: TimeFrame: 1 TimeOpen: 00:00 Bar: 1057

2012.07.17 20:42:45 VininI_CheckTime EURUSD,Daily: TimeFrame: 5 TimeOpen: 00:00 Bar: 212

2012.07.17 20:42:45 VininI_CheckTime EURUSD,Daily: TimeFrame: 15 TimeOpen: 00:00 Bar: 70

2012.07.17 20:42:45 VininI_CheckTime EURUSD,Daily: TimeFrame: 30 TimeOpen: 00:00 Bar: 35

2012.07.17 20:42:45 VininI_CheckTime EURUSD,Daily: TimeFrame: 60 TimeOpen: 00:00 Bar: 17

2012.07.17 20:42:45 VininI_CheckTime EURUSD,Daily: TimeFrame: 240 TimeOpen: 00:00 Bar: 4


 

Can you give me a hint?

I want to make a multi-timeframe MA, which changes its colour when the trend changes. I have done the average price display from other timeframes, but I do not know how to solve the problem with the colour change.

//+------------------------------------------------------------------+
//|                                                      MA-MTFC.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
//+------------------------------------------------------------------+
extern int MA_TF=1440;
extern int MA_Period=89;
extern int MA_Shift=0;
extern int MA_Method=2;
extern int MA_AP=0;
//+------------------------------------------------------------------+
double Buffer_Yellow[];
double Buffer_Lime[];
double Buffer_Red[];

string Symb;
double MA;

int init()
  {
   Symb=Symbol();
   //---
   if (MA_TF != 1)
    if (MA_TF != 5)
     if (MA_TF != 15)
      if (MA_TF != 30)
       if (MA_TF != 60)
        if (MA_TF != 240)
         if (MA_TF != 1440)
          if (MA_TF != 10080)
           if (MA_TF != 43200)
            if (MA_TF != 0)
             return;
   //---
   SetIndexBuffer(0,Buffer_Yellow);
   SetIndexBuffer(1,Buffer_Lime);
   SetIndexBuffer(2,Buffer_Red);
   //---
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   //---
   return(0);
  }

int deinit()
  {

   return(0);
  }

int start()
  {
   double MA;
   int counted_bars=IndicatorCounted();
   int limit=Bars-counted_bars-1;
   if (limit>1) 
      limit=Bars-1;
      
   for(int i=limit-1;i>=0;i--)
    {
      int pos=iBarShift(NULL, MA_TF, Time[i]);
      MA=iMA(Symb,MA_TF,MA_Period,MA_Shift,MA_Method,MA_AP,pos);
      
      Buffer_Yellow[i]=MA;
      Buffer_Lime[i]=MA;
      Buffer_Red[i]=MA;
      
      if(Buffer_Yellow[i]>Buffer_Yellow[i+1])
       {
         Buffer_Red[i]=EMPTY_VALUE;
       }
      else if(Buffer_Yellow[i]<Buffer_Yellow[i+1])
       {
         Buffer_Lime[i]=EMPTY_VALUE;
       }
      else
       {
        Buffer_Red[i]=EMPTY_VALUE;
        Buffer_Lime[i]=EMPTY_VALUE; 
       }
      
    }

   return(0);
  }
 
Roman.:
This is not the way to do it. In the tester, you have to run the owl on the minimum TF used in this owl at the opening prices. It is better to run the owl on the open on minutes. And it is better to prescribe the TF, explicitly!
Roman, I am trying to make the indicator to be displayed in the Strategy Tester. The indicator uses lower timeframes for the analysis.
 
FAQ:
It would be better if you could show the full code, and paste it using the "SRC" button.

OK, I'll try to add code to this post.

I actually know what I want to achieve in the end - I've been trading for a long time, but I only started programming after I realised exactly what I want to program.

My goal now is to get a green arrow on every bar close above all three slips and a red arrow on every closed bar that closed below all three and only for bars closed after attaching to chart. I am not interested in the current bar.

I want these arrows to be on the chart while the indicator is attached to it and then removed.

I am drawing the sliders now only for clarity and then I will remove them from the EA.

Now we have some sliders and arrows, but they appear and disappear now and appear over wrong bars. That is what I do not understand.

I think I may have confused something with j or j+1 in lines 106-111 and what element to pin them to.


Thanks if you can give me a hint.


For some reason the SRC button does not work. I will try to insert the file as a normal mq4

Files:
t11.mq4  5 kb
 
Vinin:


Checking script

Decided to tweak your code and make a check to suit my purposes (ran it on H1).

   for (i=0;i<10;i++) {
      int tmp=iBarShift(NULL, PERIOD_M15, Time[i], true);
      if (iTime(NULL, PERIOD_M15, tmp)<Time[i])tmp--;
      Alert(" TimeOpen: ", TimeToStr(iTime(NULL, PERIOD_M15, tmp), TIME_MINUTES), " Bar: ", tmp);  
   }

And here it is

 
dzhini:

Decided to tweak your code and make a check to suit my purposes (ran it on H1).

And this is what I got


You check in the tester by opening prices. So Roman has already written how to do it.

 
i.e. we run the tester on a low-end TF, and modify all other logic in the indicator to fit a higher-end TF?
 
ilunga:

Closing price of the previous bar Close[1]

Thank you very much! So, the EA trades by ticks, but can I change it to trade on intervals (candlesticks)? I am so confused about it.
Reason: