Indicador Simples de Alvo - Stop

 

Olá pessoal,

Estou estudando um indicador simples para compartilhar aqui na comunidade de marcação de Alvo-Stop usando Envelopes.

No momento tenho iniciado o código abaixo:

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   2
//+------------------------------------------------------------------+
#property indicator_label1  "Gain"
#property indicator_type1   DRAW_ARROW 
#property indicator_style1  STYLE_SOLID
#property indicator_color1  clrBlue
#property indicator_width1  1

#property indicator_label2  "Stop"
#property indicator_type2   DRAW_ARROW 
#property indicator_style2  STYLE_SOLID
#property indicator_color2  clrRed
#property indicator_width2  1
//+------------------------------------------------------------------+

double         TP_Buffer[];
double         SL_Buffer[];

input ushort   InpStopLoss       = 0;        // Distância em ticks
input ushort   InpTakeProfit     = 0;        // Distância em ticks

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() 
  {
   SetIndexBuffer(0,TP_Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,SL_Buffer,INDICATOR_DATA);
   
   ArrayInitialize (TP_Buffer, EMPTY_VALUE);
   ArrayInitialize (SL_Buffer, EMPTY_VALUE);
  
   return(INIT_SUCCEEDED);

  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
  
 //+------------------------------------------------------------------+

  if(prev_calculated==0) 
     {       
        for(int i=0; i<rates_total;i++) 
        {
         TP_Buffer[i] = close[i]+20*0.01;
         SL_Buffer[i] =   low[i]-10*0.01;
        }
                       
     }
     
     else
     {
         TP_Buffer[rates_total-1] = close[rates_total-1];
        }
     
   return(rates_total);
  }

//+------------------------------------------------------------------+

No momento está marcando em todas as barras:


Busco ainda:

1) Marcação apenas na primeira barra que romper uma banda de evelope ou de banda de bollinger;

2) Definir alvo em ticks para ser usado em qualquer ativo;


Agradeço se alguem puder ajudar no código.


Abs.