Download MetaTrader 5

Coder Opinion and Question about VLine

To add comments, please log in or register
Interested in MetaTrader 5 features? Learn more about them!
fxtrader_ 2016.05.07 22:01 


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;

      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))
   string RedLineTime = "Time"+TimeToStr(last_Red_Line_time,TIME_DATE|TIME_MINUTES);



            ObjectSet   ("Red_Line",OBJPROP_COLOR,clrRed);
            ObjectSet   ("Red_Line",OBJPROP_WIDTH,2);
            ObjectSet   ("Red_Line",OBJPROP_STYLE,0);
            ObjectSet   ("Red_Line", OBJPROP_BACK,1);


Keith Watford
Keith Watford 2016.05.08 00:22  

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

fxtrader_ 2016.05.08 05:04  
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
To add comments, please log in or register