Download MetaTrader 5

Help with drawing arrows on cross of moving average and a line produced by an array

To add comments, please log in or register
technoteze
33
technoteze 2016.02.11 01:28 

I was hoping someone would be willing to help me with a problem I'm having. As the title suggests, I'm trying to draw arrows when a moving average crosses a line that is drawn by an array. I'm working with the Center of Gravity indicator, trying to understand it actually. I thought it would be nice to be able to draw a signal moving average that would signal buy and sell as price moves between the channels. 


I am by no means a skilled programmer but have been learning MQL and am slowly getting to grips to how it works. This has really stumped me though and can't understand why I can't get it to work. I have used similar code before to draw arrows at a cross of two moving averages and it works perfectly. The only difference here is the fact I'm crossing a line that is drawn through an array. In previous attempts I can get arrows drawn but they draw on every candle so I thought it had to do with the loop I was using. In this latest attempt I can't even get the arrows to show up!

This is the source code in question. If needs be I can post the full source if that would be easier. Any help would be very much appreciated.


HighChannel2[n]= CenterChannel[n]+(ChannelNarrow2*StandardDeviation);
LowChannel2[n] = CenterChannel[n] -(ChannelNarrow2*StandardDeviation);


   int counted_bars=IndicatorCounted();
   int limit= Bars-counted_bars;
   for(int q=0;q<limit;q++)
     {
      double SignalLineCurrent=iMA(NULL,PERIOD_CURRENT,1,0,MODE_LWMA,PRICE_CLOSE,q);
      double SignalLinePrevious=iMA(NULL,PERIOD_CURRENT,1,0,MODE_LWMA,PRICE_CLOSE,q+1);

      if(ShowSignal)
        {
         MA3[q]=SignalLineCurrent;
        }

      if(ShowArrows)
        {
         if(SignalLineCurrent>LowChannel2[n] && SignalLinePrevious<LowChannel2[n+1])
           {
            upArrow[q]=Low[q];
           }

         else if(SignalLineCurrent<HighChannel2[n] && SignalLinePrevious>HighChannel2[n+1])
           {
            downArrow[q]=High[q];
           }

        }

     }
Vasyl Nosal
18648
Vasyl Nosal 2016.02.11 12:42  

Change all "n" to "q" after for(int q=0;q<limit;q++)

 

 LowChannel2[n]

technoteze
33
technoteze 2016.02.11 12:56  
Vasyl Nosal:

Change all "n" to "q" after for(int q=0;q<limit;q++)

 

 LowChannel2[n]

Out of everything I tried I did not try that... Thank you very much! It works perfectly now.
To add comments, please log in or register