Download MetaTrader 5

iMA Shift parameter problem.

To add comments, please log in or register
Thushara Dissanayake
11178
Thushara Dissanayake  

hi,

Indicator moving average lines working well. I tested  with "-7" Shift parameter. yes it is working well. But the shift parameter not working well with object draw part. I am using SetIndexBuffer for draw lines. But i am using other method to draw object arrows.

You can see it working well with "Shift=0"


With Shift="-7", You can see the last arrow object draw as a sell signal. But actually red line not at sell trend. it still at buy trend with last crossover. that is the problem. And this wrong sell signal show only if MA lines at BUY trend. Think, if red line at sell trend then that will not draw wrong arrow. look next image.

you can see it working well. last arrow is correct with sell tend. But when it crossover as buy trend that will show again wrong sell sign.


i am using two ways to draw this signals. One for lines and other for arrows. Lines are working well. But arrow drawing method is the problem. here my code.


#property indicator_buffers 2


double FastMA_[], SlowMA_[];

int OnInit()
  {
   SetIndexShift(0,MAShiftFast); 
   SetIndexShift(1,MAShiftSlow);
   
   SetIndexDrawBegin(0,MAShiftFast+Fast_MA);
   SetIndexDrawBegin(1,MAShiftSlow+Slow_MA);
   
   SetIndexBuffer(0,FastMA_); 
   SetIndexBuffer(1,SlowMA_);
       
   SetIndexStyle (0,DRAW_LINE,FastMAStyle,FastMAWidth,FastMAColor);
   SetIndexStyle (1,DRAW_LINE,SlowMAStyle,SlowMAWidth,SlowMAColor);

   return(INIT_SUCCEEDED);
  }

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[])
  {
   
   double FastMA_0,SlowMA_0;
   int i, Counted_bars;                 

   Counted_bars=IndicatorCounted(); 
   i=Bars-Counted_bars-1;           
   if (i>History-1)                 
      i=History-1;                 

   while(i>=0)                      
     {
    
         FastMA_0=iMA(NULL,0,Fast_MA,0,ENUM_MA_METHOD(MAFast),ENUM_APPLIED_PRICE(MAAppllyFast),i);
         FastMA_[i]=FastMA_0; //for lines
              

         SlowMA_0=iMA(NULL,0,Slow_MA,0,ENUM_MA_METHOD(MASlow),ENUM_APPLIED_PRICE(MAAppllySlow),i);
         SlowMA_[i]=SlowMA_0; //for lines
          
         //for arrow object draw
         double Slow_MACurr_1=iMA(Symbol(),0,Slow_MA,MAShiftSlow,ENUM_MA_METHOD(MASlow),ENUM_APPLIED_PRICE(MAAppllySlow),i);
         double Slow_MAPrev_1=iMA(Symbol(),0,Slow_MA,MAShiftSlow,ENUM_MA_METHOD(MASlow),ENUM_APPLIED_PRICE(MAAppllySlow),i+1);
  
   
         double Fast_MACurr_1=iMA(Symbol(),0,Fast_MA,MAShiftFast,ENUM_MA_METHOD(MAFast),ENUM_APPLIED_PRICE(MAAppllyFast),i);
         double Fast_MAPrev_1=iMA(Symbol(),0,Fast_MA,MAShiftFast,ENUM_MA_METHOD(MAFast),ENUM_APPLIED_PRICE(MAAppllyFast),i+1);
      
  

            if(Slow_MAPrev_1>Fast_MAPrev_1 && Fast_MACurr_1>Slow_MACurr_1){
               create_(0,"x_\n"+IntegerToString(i),0,Time[i],High[i]+SymPoint*ArrowDistance,ArrowCode,BuyColor,STYLSOLID);
            }
            if(Slow_MAPrev_1<Fast_MAPrev_1 && Fast_MACurr_1<Slow_MACurr_1){
               create_(0,"x_\n"+IntegerToString(i),0,Time[i],High[i]+SymPoint*ArrowDistance,ArrowCode,SellColor,STYLSOLID);
            }
         
      
      i--;                          
     }

   return(rates_total);
  }


What is the wrong with my arrow draw part? It only working as bad with "-Shift" values.

my inputs....


Finally i want to know is my code wrong or need to fix anything for this. If you got it please kindly comment, how to do that.

Thank you.

Thushara Dissanayake
11178
Thushara Dissanayake  
In this case i used
MAShiftFast //and
MAShiftSlow
whroeder1
17951
whroeder1  
Why don't you create to more buffers of arrow type?
Thushara Dissanayake
11178
Thushara Dissanayake  
whroeder1:
Why don't you create to more buffers of arrow type?
Can you explain more? Are you mean use buffers for arrow draw?
Naguisa Unada
253
Naguisa Unada  

Even if you use "SetIndexShift" in the program, the display is only shifted on the screen. Data in the buffer is not moved.

Thushara Dissanayake
11178
Thushara Dissanayake  
Naguisa Unada:

Even if you use "SetIndexShift" in the program, the display is only shifted on the screen. Data in the buffer is not moved.

So how to do it correctly?

Thushara Dissanayake
11178
Thushara Dissanayake  
Actually i used few methods. But still not fixed!
To add comments, please log in or register