Download MetaTrader 5
To add comments, please log in or register
Track Market top sellers!
jose
71
jose 2016.05.12 09:58 

Hi all, 

i have one doubt. I want to see some signals when bar close, but fr backtest, i want see signals in history. I use simple code, but when i try to generalize to previous bars of history, the calculations appears each tick and not when bar end. I use:

 

static datetime newBar; 


int start()
  {
    
    
    int counted= IndicatorCounted();

    if (counted<0)
        return(-1);
   
    if (counted>0)
        counted --;
    
    int limit = Bars-counted;

    for(int i = 0; i < limit; i++) 
       {     

         if(iTime(NULL,0,i) != newBar)   
           {
                      
             Alert("  we have alert . . . ."); //Alert for prove the end of bar
            
            // CODE FOR SIGNALS -------------------------------------------------------
               ------------------------------------------------------------------------
               ------------------------------------------------------------------------
               ------------------------------------------------------------------------
               ----------------------------------------------------------------------//
               
             newBar = iTime(NULL, 0, i);  
           }
       } 
   
    return(0);
  }

 The question is i have alerts each tick and not when bar end.

What is the mystake or the correct logic?

Thank you very much. 

jose
71
jose 2016.05.12 12:11  
Messi86:

Hi all, 

i have one doubt. I want to see some signals when bar close, but fr backtest, i want see signals in history. I use simple code, but when i try to generalize to previous bars of history, the calculations appears each tick and not when bar end. I use:

 

 The question is i have alerts each tick and not when bar end.

What is the mystake or the correct logic?

Thank you very much. 

 

Maybe is not posible,. Some help please??

Yhank you very much 

Fernando Carreiro
1523
Fernando Carreiro 2016.05.12 12:57  
Messi86:

Maybe is not posible,. Some help please??

Yhank you very much 

Yes it is possible!

  1. Instead of "iTime()" use "Time[]" because you are using the current chart data.
  2. Instead of monitoring the "i" index (previous bars), just monitor the value of Time[0] (current Bar) and detect when it changes. Don't use Time[i], otherwise you will get thousands of alerts.
  3. To back-test the logic of your indicator, use the Strategy Tester (in Indicator and Visual mode) to test it as if it were in real-time, but against history data
Keith Watford
Moderator
7990
Keith Watford 2016.05.12 13:02  

The problem is that you say that you " want to see signals in history", then you show code that issues alerts for every bar in history. Why would you want that? You just get thousands of alerts.

If you want signals in history, use a buffer to show arrows

Only do alerts and reset newbar when you get a signal and i==0 if signals are calculated on current bars or i==1 if only calculated on closed bars

jose
71
jose 2016.05.12 13:59  
FMIC:

Yes it is possible!

  1. Instead of "iTime()" use "Time[]" because you are using the current chart data.
  2. Instead of monitoring the "i" index (previous bars), just monitor the value of Time[0] (current Bar) and detect when it changes. Don't use Time[i], otherwise you will get thousands of alerts.
  3. To back-test the logic of your indicator, use the Strategy Tester (in Indicator and Visual mode) to test it as if it were in real-time, but against history data



Thank you very much!!

I understood, and i am going to programm for your way!! 

jose
71
jose 2016.05.12 14:00  
GumRai:

The problem is that you say that you " want to see signals in history", then you show code that issues alerts for every bar in history. Why would you want that? You just get thousands of alerts.

If you want signals in history, use a buffer to show arrows

Only do alerts and reset newbar when you get a signal and i==0 if signals are calculated on current bars or i==1 if only calculated on closed bars

Thank you very much for your reply, This option i like too. I prove this way too

Thank you very much!! 

whroeder1
13641
whroeder1 2016.05.12 17:01  
  1. Indicators do not use new bar code. Just alert when i==1 and has a signal.
  2. Handle your lookbacks properly and count down.
/
To add comments, please log in or register