Need Help Painting Objects created from indicator (:

To add comments, please log in or register
Honeggeral
101
Honeggeral  

Hello!

Im pretty new to coding actually learning about it this year at my university. Ive created an indicator that produces signals based on overbought levels of stochastic and bollinger and detects if there are divergence points at those levels. it works fairly well and i use it mainly to aid in scalping. Planning on adding hidden divergence to it too. Its a fairly simple code, but i need help getting it to paint on all previous bars instead of only new ones that are produced. Also when i switch profiles any previous arrows drawn disappear. Any help would be greatly appreciated (: thanks!  

//PROGRAM FOR SCALPING NOTIFICATIOS
//INDICATORS: STOCHASTIC (14,3,3), BOLLINGS BANDS, AND PRICE ACTION TO IDENTIFY DIVERGENCE POINTS WHEN IN OVERBOUGHT AND OVERSOLD CONDITION.
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 SeaGreen
#property indicator_color2 Red
datetime PreviousBarTime1;
datetime PreviousBarTime2;
double CrossUp[];
double CrossDown[];
input string SENDEMAIL = "TRUE";
input string SENDNOTIF = "TRUE";
input string SENDALERT = "FALSE";

int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }

void start ()
  {
  int counted_bars=IndicatorCounted();
  int limit, i, counter;
  if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++){
   counter=i;
      double Range=0;
      double AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10; 
  
   if(NewBarBuy()){
      if(High[1] >= BOLL(1,1) && STOCH (0,1) > 70){  //TRADING REVERSAL OFF MAIN BOLLING POINT
         if(STOCH_CURRENT("POSITIVE")){
               if(STOCH_POINTS_PAST("POSITIVE")){
                  CrossDown[i] = High[2] + Range*0.5;
                  
                     if(SENDEMAIL == "TRUE"){
                           SendMail("POSSIBLE SELL", "POSSIBLE SELL SCALP FOR " + Symbol());}
                      if(SENDNOTIF == "TRUE"){
                           Print("POSSIBLE SELL SCALP FOR " + Symbol());}
                      if(SENDALERT == "TRUE"){
                            Alert("POSSIBLE SELL SCALP FOR " + Symbol());}}}}}
      
    if(NewBarSell()){
      if(Low[1] <= BOLL(2,1) && STOCH (0,1) < 30){  //TRADING REVERSAL OFF MAIN BOLLING POINT
         if(STOCH_CURRENT("NEGATIVE")){
               if(STOCH_POINTS_PAST("NEGATIVE")){
               CrossUp[i] = Low[2] - Range*0.5;
                     if(SENDEMAIL == "TRUE"){
                           SendMail("POSSIBLE BUY", "POSSIBLE BUY SCALP FOR " + Symbol());}
                      if(SENDNOTIF == "TRUE"){
                           Print("POSSIBLE BUY SCALP FOR " + Symbol());}
                      if(SENDALERT == "TRUE"){
                            Alert("POSSIBLE BUY SCALP FOR " + Symbol());}}}}}}
   
  }

double STOCH (int buffer, int shift){
   double value;
    value = iStochastic(Symbol(), 0, 14, 3, 3, 0, 0, buffer, shift); //BUFFER: 0=MAIN 1=SIGNAL
   return (value);}
   
double BOLL (int buffer, int shift){
   double value;
   value = iBands(Symbol(), 0, 20, 2, 0, 0, buffer, shift); //BUFFER: 0=MAIN 1=UPPER 2=LOWER
   return (value);}

bool STOCH_CURRENT (string sign){
    if (sign == "NEGATIVE"){
         if(STOCH (0, 1) > STOCH (0, 2) && STOCH (0,2) < STOCH(0,3)){
            return (true);}}
    if (sign == "POSITIVE"){
         if(STOCH (0, 1) < STOCH (0, 2) && STOCH (0,2) > STOCH(0,3)){
            return (true);}}}
   
   
bool STOCH_POINTS_PAST (string sign){
   if (sign == "NEGATIVE"){
   for(int i = 4; i<60; i++){
         if(STOCH (0, i) > STOCH (0, i+1) && STOCH (0,i+1) < STOCH(0,i+2)){
               if(Low[i+1] > Low[2]&& STOCH (0,i+1) < STOCH(0,2)){
                  return (true);}}}}
    if (sign == "POSITIVE"){
   for(i = 4; i<60; i++){
         if(STOCH (0, i) < STOCH (0, i+1) && STOCH (0,i+1) > STOCH(0,i+2)){
               if(High[i+1] < High[2] && STOCH (0,i+1) > STOCH(0,2)){
                  return (true);}}}}}
    
                  
                  
double test (void){
   for(int i = 4; i<60; i++){
         if(STOCH (0, i) < STOCH (0, i+1) && STOCH (0,i+1) > STOCH(0,i+2)){
               if(High[i+1] > Low[2]){
                  return (STOCH(0,i+1));}}}}
      
   
   
bool NewBarBuy()
{
   if(PreviousBarTime1<Time[0])
   {
      PreviousBarTime1=Time[0];
      return(true);
   }
   return(false);
}

bool NewBarSell()
{
   if(PreviousBarTime2<Time[0])
   {
      PreviousBarTime2=Time[0];
      return(true);
   }
   return(false);
}
To add comments, please log in or register