Coder Opinion and Question about VLine

 

Hi,

With the help of Mr. GumRai Code I try to modify the code to get VLine when iMA Crossed.

First I would like to know about professional coder opinion. Is this the right way for writing code?
Second I have question about the VLine.  How to stop the line to not drawing in subwindow?


int start()
  {

   double Red_Line_Period = 0;
   datetime EndTime = TimeCurrent();
   int last_Red_Line_Cross_index=1;
   static datetime last_Red_Line_time=0;

   while(true)
     {
      if(iMA(Symbol(),Red_Line_Period,5,0,MODE_SMA,PRICE_CLOSE,last_Red_Line_Cross_index+1) > iMA(Symbol(),Red_Line_Period,21,0,MODE_SMA,PRICE_CLOSE,last_Red_Line_Cross_index+1)
      && iMA(Symbol(),Red_Line_Period,5,0,MODE_SMA,PRICE_CLOSE,last_Red_Line_Cross_index-2) < iMA(Symbol(),Red_Line_Period,21,0,MODE_SMA,PRICE_CLOSE,last_Red_Line_Cross_index-2))
        {
          last_Red_Line_time=iTime(Symbol(),Red_Line_Period,last_Red_Line_Cross_index);
   string RedLineTime = "Time"+TimeToStr(last_Red_Line_time,TIME_DATE|TIME_MINUTES);

         break;
        }
      last_Red_Line_Cross_index++;
     }

//XCXCXCXCXCXCXCXCXCXXCXCXCXCXCX|  ADD RED LINE |XCXCXCXCXCXCXCXCXCXXCXCXCXCXCXCXCXCXCXCXCXCXCXCXXCXCXCXCXCXCX|

      if(Show_Red_Line)
          {
            ObjectCreate(0,"Red_Line",OBJ_VLINE,0,last_Red_Line_time,last_Red_Line_Cross_index,EndTime,last_Red_Line_Cross_index);
            ObjectSet   ("Red_Line",OBJPROP_COLOR,clrRed);
            ObjectSet   ("Red_Line",OBJPROP_WIDTH,2);
            ObjectSet   ("Red_Line",OBJPROP_STYLE,0);
            ObjectSet   ("Red_Line", OBJPROP_BACK,1);
          }
      ObjectsRedraw();


   return(0);
  }



 

First of all I have to say that is not my code. If it ever was, it has been changed so much that it is no longer representative of any code that I would write.

   int last_Red_Line_Cross_index=1;
        
iMA(Symbol(),Red_Line_Period,5,0,MODE_SMA,PRICE_CLOSE,last_Red_Line_Cross_index-2) ////

Never usecalculations that can give negative index values. index[-1] does not exist

You are looking for a cross by comparing [index+1] to [index-2]. That doesn't make sense as you should be comparing consecutive bars

If you don't want the line to show in subwindows, use a trend line instead

 
First of all please apologise me for my language .

and As usual you are very helpful Mr.GumRai. and please do not misunderstand me. I mean by that the idea behind the code how to find the moving average across, You wrote a code to find the last red candle. and from that I change the code. it seems to be worked and it plot the line exactly where the moving average across.

I know as every body knows here you are one of the professional coder's.

Thanks again