Indicator help needed

Back to topics list To post a new topic, please log in or register
avatar
11
hilfx 2016.07.05 19:38
 
extern datetime candledate=D'05.07.2016 16:00';//DD.MM.YYYY. HH:MM                                                                   

//---- buffer
double buff_buy_entry[];
double pips;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   pips=Point; //.00001 or .001
   if(Digits==3 || Digits==5)
      pips*=10; // pips=0,0001 or pips=0,01
//+------------------------------------------------------------------+
//---- BUY Buffers
   SetIndexBuffer(0,buff_buy_entry);
   SetIndexStyle(0,DRAW_LINE,STYLE_DASHDOTDOT,1,clrGreen);
   SetIndexLabel(0,"BUY ENTRY Level");
   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[])

  {
   int limit;
   if(!prev_calculated)limit=rates_total-2;
   else limit=rates_total-prev_calculated;
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+   
   int mycandle=0;   
   double candleclose=0.0;
//+------------------------------------------------------------------+   
   mycandle=iBarShift(NULL,PERIOD_M5,candledate,true);
//+------------------------------------------------------------------+        
   for(int i=0;i<=mycandle;i++)
     {
     candleclose=iClose(NULL,0,mycandle);
      if(iLow(NULL,0,i)<candleclose-20*pips)
         buff_buy_entry[i]=candleclose-20*pips;
      else
         buff_buy_entry[i]=candleclose;
     };

return(rates_total);
}

Hi,

I have a simply indicator which should do the following:

1. Look at an specific date for the candle
2. check the close of that candle
3. if the current low is 20 pips below the close of that candle, draw a line,
   otherwise draw the line at the level of the candle's close.

Here's my problem:

Check AUDUSD M5 for the date 05.07.2016 16:00
first, the line is at the candle's close level, then the line moves to 20 pips below the level.

But later on the price moves back and also the line moves back. But I don't want the line moves back. In other words: I want the line is moving only one time - if the price goes 20 pips away. Then the line should stay at this level, it doesn't matter where the price is going after the 1st movement.

Big THANKS for your help.

Dan 

Attached files:
  fade_line.mq4  (2.57 KB)
avatar
13008
WHRoeder 2016.07.06 15:27 #
 
hilfx: if the price goes 20 pips away. Then the line should stay at this level, it doesn't matter where the price is going after the 1st movement.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. mycandle=iBarShift(NULL,PERIOD_M5,candledate,true);
         candleclose=iClose(NULL,0,mycandle);
    You are mixing apples and oranges
  3. iClose(NULL,0,mycandle);
    iLow(NULL,0,i)
    Why use a function call when you can use the Predefined Variables - MQL4 Reference
  4. Count down and don't move it back.
    candleclose=iClose(NULL,0,mycandle);
    for(int i=mycandle; i >= 0; --i){
          if(Low[i] < candleclose-20*pips)
             candleclose -= 20*pips;
    //         buff_buy_entry[i]=candleclose-20*pips;
    //      else
             buff_buy_entry[i]=candleclose;
         };

avatar
11
hilfx 2016.07.07 07:22 #
 
#property indicator_chart_window
#property indicator_buffers 1
#property strict
//----
extern datetime candledate=D'07.07.2016 07:30';//YYYY.MM.DD. HH:MM                                                                   

//---- buffer
double buff_buy_entry[];
double pips;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   pips=Point; //.00001 or .001
   if(Digits==3 || Digits==5)
      pips*=10; // pips=0,0001 or pips=0,01
//+------------------------------------------------------------------+
//---- BUY Buffers
   SetIndexBuffer(0,buff_buy_entry);
   SetIndexStyle(0,DRAW_LINE,STYLE_DASHDOTDOT,1,clrGreen);
   SetIndexLabel(0,"BUY ENTRY Level");
   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[])

  {
   int limit;
   if(!prev_calculated)limit=rates_total-2;
   else limit=rates_total-prev_calculated;
//+------------------------------------------------------------------+   
   int mycandle=iBarShift(NULL,0,candledate,true);
   double candleclose=Close[mycandle];
//+------------------------------------------------------------------+        
   Comment("i der Kerze: ",IntegerToString(mycandle,0)
           ,"\ncandledate: ",TimeToString(candledate,TIME_DATE|TIME_MINUTES)
           ,"\nClose: ",DoubleToString(candleclose,_Digits)
           ,"\nTrigger: ",DoubleToString(candleclose-15*pips,_Digits)
           );
//+------------------------------------------------------------------+
   for(int i=mycandle;i>=0;i--)
     {
      if(Low[i]<=candleclose-15*pips)
         candleclose-=15*pips;
         buff_buy_entry[i]=candleclose;
      
     }
   return(rates_total);
  }
Thanks WHRoeder for your advices! But the line still moves for a second time. The first move is right, but after the Price moves another 15 pips down, the line moves also. That's not what it should. I wanna to move it only one time. Thanks for help! Dan.
Back to topics list  

To add comments, please log in or register