Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1492

 
Alexey Viktorov:

Tarasik, piss on you... Idiot. Look at the code we got after your hints... It's called "teaching you how not to do it", and it's your own fault if you don't get it.

And now we're getting personal and discussing what a bad man he is.

Alexey Viktorov:

It's rude to lie so blatantly. You delete your post and blame your illiteracy on someone else. Liar.

so who's the Liar there?)
 
Taras Slobodyanik:

Here we go, and then we get all personal and talk about what a bad man he is.

So who's the Liar?)

Read my posts on the previous page about that.

 
Alexey Viktorov:

Yeah, I didn't delete it, I just didn't immediately find that message.

But! Still recanting who you are

radish)

 
Taras Slobodyanik:

radish)

Does this answer your question?

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, help and discussion of algorithms and codes

Alexey Viktorov, 2021.06.02 17:41

Yes, I did not delete it, I just did not immediately find the message


But! Still retracting your words who are you?

:-)))

 
SanAlex:

the easiest and simplest way is to get the names of Horizontal or Trend lines from the Indicator.

- right-click on the chart and find the OBJECT LIST item(copy and paste into Expert Advisor)

Thanks for the help! Had another look at your Expert Advisor and used the code:

double price_line_up=ObjectGetDouble(0, "Top",OBJPROP_PRICE);

double price_line_down=ObjectGetDouble(0, "Bottom",OBJPROP_PRICE);

typing the line names from the indicator. I am getting the values but I have not checked them all yet. I think it should work.

 

Hi all. Guys, I need your help.

I have a stochastic indicator with allert, it gives a signal on crossing of moving lines. Please tell me how to make it give a signal by crossing moving only when it is above or below the overbought and oversold zone.

Please advise

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_level1 80
#property indicator_level2 20
#property indicator_maximum 100
#property indicator_minimum 0

//---- input parameters
/*************************************************************************
PERIOD_M1   1
PERIOD_M5   5
PERIOD_M15  15
PERIOD_M30  30 
PERIOD_H1   60
PERIOD_H4   240
PERIOD_D1   1440
PERIOD_W1   10080
PERIOD_MN1  43200
You must use the numeric value of the timeframe that you want to use
when you set the TimeFrame' value with the indicator inputs.
---------------------------------------
MODE_SMA    0 Simple moving average, 
MODE_EMA    1 Exponential moving average, 
MODE_SMMA   2 Smoothed moving average, 
MODE_LWMA   3 Linear weighted moving average. 
You must use the numeric value of the MA Method that you want to use
when you set the 'ma_method' value with the indicator inputs.

**************************************************************************/
extern int TimeFrame=240;
extern int KPeriod=5;
extern int DPeriod=3;
extern int Slowing=3;
extern int MAMethod=0;
extern int PriceField=0;// PriceField:  0=Hi/Low   1=Close/Close

extern string note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN";
extern string __MA_Method = "SMA0 EMA1 SMMA2 LWMA3";
extern string __PriceField = "0=Hi/Low   1=Close/Close";
//extern string __Price = "0O,1C 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";


double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

datetime last_t=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexLabel(0,  "MTF_Stochastic("+KPeriod+","+DPeriod+","+Slowing+")TF"+TimeFrame+"");
   SetIndexLabel(1,"MTF_Stochastic("+KPeriod+","+DPeriod+","+Slowing+")TF"+TimeFrame+"");
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,233);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,234);

//---- name for DataWindow and indicator subwindow label   
   switch(TimeFrame)
   {
      case 1 : string TimeFrameStr="Period_M1"; break;
      case 5 : TimeFrameStr="Period_M5"; break;
      case 15 : TimeFrameStr="Period_M15"; break;
      case 30 : TimeFrameStr="Period_M30"; break;
      case 60 : TimeFrameStr="Period_H1"; break;
      case 240 : TimeFrameStr="Period_H4"; break;
      case 1440 : TimeFrameStr="Period_D1"; break;
      case 10080 : TimeFrameStr="Period_W1"; break;
      case 43200 : TimeFrameStr="Period_MN1"; break;
      default : TimeFrameStr="Current Timeframe";
   } 
   IndicatorShortName("MTF_Stochastic("+KPeriod+","+DPeriod+","+Slowing+") "+TimeFrameStr);  
   start();
   return(0);
  }
//----
   
 
//+------------------------------------------------------------------+
//| MTF Stochastic                                                   |
//+------------------------------------------------------------------+
 int deinit()
  {
   for (int i=Bars;i>=0;i--){
      ObjectDelete("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0));
   }
   return(0);
  }

bool up_a=false;
bool dn_a=false;
int start()
  {
   datetime TimeArray[];
   ArrayResize(TimeArray,Bars);
   int    i,limit,y=0,counted_bars=IndicatorCounted();
    
// Plot defined timeframe on to current timeframe   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   
 //  limit=Bars-counted_bars+TimeFrame/Period(); //igorad
limit=Bars-1;
limit=MathMax(limit,TimeFrame/Period());
//limit=MathMin(limit,BarsToCount);
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++; 
   
 /***********************************************************   
   Add your main indicator loop below.  You can reference an existing
      indicator with its iName  or iCustom.
   Rule 1:  Add extern inputs above for all neccesary values   
   Rule 2:  Use 'TimeFrame' for the indicator timeframe
   Rule 3:  Use 'y' for the indicator's shift value
 **********************************************************/  
   ExtMapBuffer3[i]=EMPTY_VALUE;  
   ExtMapBuffer4[i]=EMPTY_VALUE;
   ExtMapBuffer1[i]=EMPTY_VALUE;  
   ExtMapBuffer2[i]=EMPTY_VALUE;

   ExtMapBuffer1[i]=iStochastic(NULL,TimeFrame,KPeriod,DPeriod,Slowing,MAMethod,PriceField,0,y);
   ExtMapBuffer2[i]=iStochastic(NULL,TimeFrame,KPeriod,DPeriod,Slowing,MAMethod,PriceField,1,y);
   ObjectDelete("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0));   

   if (NormalizeDouble(ExtMapBuffer1[i],Digits)>NormalizeDouble(ExtMapBuffer2[i],Digits) && NormalizeDouble(ExtMapBuffer1[i+1],Digits)<=NormalizeDouble(ExtMapBuffer2[i+1],Digits)  && NormalizeDouble(ExtMapBuffer1[i+1],Digits)!=NormalizeDouble(ExtMapBuffer1[i],Digits) ){
      ExtMapBuffer3[i]=ExtMapBuffer1[i];
      ObjectDelete("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0));
      ObjectCreate("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),22,0,Time[i],Low[i]-5*Point);
      ObjectSet("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),6,Blue);
      ObjectSet("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),14,233);      
   }
   if (NormalizeDouble(ExtMapBuffer1[i],Digits)<NormalizeDouble(ExtMapBuffer2[i],Digits) && NormalizeDouble(ExtMapBuffer1[i+1],Digits)>=NormalizeDouble(ExtMapBuffer2[i+1],Digits)  && NormalizeDouble(ExtMapBuffer1[i+1],Digits)!=NormalizeDouble(ExtMapBuffer1[i],Digits)){
      ExtMapBuffer4[i]=ExtMapBuffer1[i];
      ObjectDelete("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0));
      ObjectCreate("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),22,0,Time[i],High[i]+5*Point);
      ObjectSet("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),6,Red);
      ObjectSet("st"+Symbol()+Period()+DoubleToStr(KPeriod+DPeriod+Slowing,0)+DoubleToStr(i,0),14,234);      
   }
   }  
     
//
   //----  Refresh buffers ++++++++++++++ 
   if (TimeFrame < Period()) TimeFrame = Period();
   if (TimeFrame>Period()) {
     int PerINT=TimeFrame/Period()+1;
     datetime TimeArr[]; ArrayResize(TimeArr,PerINT);
     ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period()); 
     for(i=0;i<PerINT+1;i++) {if (TimeArr[i]>=TimeArray[0]) {
 /********************************************************     
    Refresh buffers:         buffer[i] = buffer[0];
 ************************************************************/  

   ExtMapBuffer1[i]=ExtMapBuffer1[0];
   ExtMapBuffer2[i]=ExtMapBuffer2[0];

   } } }
//+++++++++++++++++++++++++++++++++++++++++++++++++++++   Raff 

   if (ExtMapBuffer3[0]!=EMPTY_VALUE && !up_a){
      up_a=true;
      dn_a=false;    
      Alert("MTF Stochastic Long cross Signal on "+Symbol());
   }
   if (ExtMapBuffer4[0]!=EMPTY_VALUE && !dn_a){
      dn_a=true;
      up_a=false;    
      Alert("MTF Stochastic Short cross Signal on "+Symbol());
   }

   return(0);
  }
 
jarikn:

Hi all. Guys, I need your help.

I have a stochastic indicator with allert, it gives a signal on crossing of moving lines. Please tell me how to make it give a signal by crossing moving only when it is above or below the overbought and oversold zone.

Please advise.

***

Pleaseinsert the codecorrectly: when editing a post, click on Code and insert your code in the pop-up window.
MQL5.community - Памятка пользователя
MQL5.community - Памятка пользователя
  • www.mql5.com
Вы недавно зарегистрировались и у вас возникли вопросы: Как вставить картинку в сообщение на форуме, как красиво оформить исходный код MQL5, где находятся ваши Личные сообщения? В этой статье мы подготовили для вас несколько практических советов, которые помогут быстрее освоиться на сайте MQL5.community и позволят в полной мере воспользоваться доступными функциональными возможностями.
 
  • //| mymacd v2 12/11/05
    /////////////////////////////////////////////////////////////////////////////////////////////
    #property link "jpygbp@yahoo.com"
    #property indicator_buffers 5
    #property indicator_separate_window
    #property indicator_color1 HotPink    //macd
    #property indicator_color2 Lime     //signal
    #property indicator_color3 Gray  //histogram
    #property indicator_color4 Blue  //macd[1]
    #property indicator_color5 Black     //zero line
    //---- buffers
    double Buffer1[]; //macd
    double Buffer2[]; //signal
    double Buffer3[]; //histogram
    double Buffer4[]; //macd[1]
    double Buffer5[]; //zero line
    //
    extern int FastEMA = 9;
    extern int SlowEMA = 64;
    extern int SignalSMA = 112;
    //extern bool plotMACD = true;
    //extern bool plotSignalLine = true;
    //extern bool plotHistogram = true;
    //extern bool plotMACDOneBarAgo = true;
    //extern bool plotZeroLine = true;
    extern bool plotArrows = false;
    extern double HistThreshold = 0;
    //
    ///////////////////////////////////////////////////////////////////////////////////////////////
    
    int limit = 0;
    int fontsize=10;
    int i = 0;
    bool InLTrade = false;
    bool InSTrade = false;
    /////////////////////////////////////////////////////////////////////////////////////////////
    int init()
    {
       ObjectsDeleteAll();
       //---- indicators
       SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);//macd
       SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);//signal
       SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);//hist
       SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2);//macd[1]
       SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);//zero
       //
       SetIndexBuffer(0,Buffer1);
       SetIndexBuffer(1,Buffer2);
       SetIndexBuffer(2,Buffer3); 
       SetIndexBuffer(3,Buffer4); 
       SetIndexBuffer(4,Buffer5); 
       //
       SetIndexDrawBegin(1,SignalSMA);
       //
       IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
       //
       IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
       //
       SetIndexLabel(0,"MACD");
       SetIndexLabel(1,"Signal");
       SetIndexLabel(2,"Histogram");
       SetIndexLabel(3,"MACD[1]");
       SetIndexLabel(4,"Zero");
       //
       return(0);
    }
    /////////////////////////////////////////////////////////////////////////////////////////////
    string NewArrow(datetime T1, double P1, color collor) 
    {
       string N=StringConcatenate("A",collor,"-",TimeToStr(T1));
       int AC=SYMBOL_STOPSIGN;
       if(collor==Blue)
          AC=SYMBOL_ARROWUP;
       if(collor==Red) 
          AC=SYMBOL_ARROWDOWN;
       //
       ObjectCreate(N, OBJ_ARROW, 0, T1, P1);
       ObjectSet(N, OBJPROP_ARROWCODE, AC);
       ObjectSet(N, OBJPROP_COLOR, collor);
       ObjectSet(N, OBJPROP_WIDTH, 1);
       ObjectsRedraw();
       return(N);
    }
    /////////////////////////////////////////////////////////////////////////////////////////////
    int deinit()
    {
       ObjectsRedraw();
       return(0);
    }
    /////////////////////////////////////////////////////////////////////////////////////////////
    int start()
    {
       int counted_bars=IndicatorCounted();
       if(counted_bars<0) return(-1);//---- check for possible errors
       if(counted_bars>0) counted_bars--;//---- last counted bar will be recounted
       limit=Bars-counted_bars;
       //
       for(i=0; i<limit; i++)//---- macd counted in the 1-st buffer histogram
          Buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
       //
       for(i=0; i<limit; i++)//---- signal line counted in the 2-nd buffer line
          Buffer2[i]=iMAOnArray(Buffer1,Bars,SignalSMA,0,MODE_SMA,i);
       //
       for(i=0; i<limit; i++)//---- histogram is the difference between macd and signal line
       {
          Buffer3[i]=Buffer1[i]-Buffer2[i];
          Buffer5[i]=0;
       }
       //
       for(i=1; i<limit; i++)//---- macd[1]
          Buffer4[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-1)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-1);
       //
       if (plotArrows)
       {
          ObjectsDeleteAll();
          InLTrade = false;
          InSTrade = false;
          for(int i=Bars;i>=0;i--)
          {
             if ((Buffer3[i-1]  > 0) && (Buffer3[i] < 0) && Buffer3[i-1] > HistThreshold)//Long Begin
             {
               string upArrow1=NewArrow(Time[i-1], High[i-1]+0.0005, Blue);
                InLTrade = true; 
             }
             if ((Buffer3[i-1]  < 0) && (Buffer3[i] > 0) && Buffer3[i-1] < -HistThreshold)//Short Begin
             {
                string dnArrow1=NewArrow(Time[i-1], Low[i-1]-0.0003, Red);
                InSTrade = true; 
                InLTrade = false;  
             }
             if ((InSTrade  == true) && (Buffer3[i-1] > Buffer3[i]))//Short End
             {
                string upArrow2=NewArrow(Time[i-1], Low[i-1]-0.0003, Aqua);
                InSTrade = false; 
             }
             if ((InLTrade == true) && (Buffer3[i-1] < Buffer3[i]))//Long End
             {
                string dnArrow2=NewArrow(Time[i-1], High[i-1]+0.0005, Aqua);
                InLTrade = false;   
             }
          }
       }
       //
       //
       return(0);
    }
    /////////////////////////////////////////////////////////////////////////////////////////////

    I need help, there is an indicator -Macd, but when you add it to the chart and when you switch timeframes, all levels and graphical objects disappear, how can you fix it.
Files:
-Macd.ex4  6 kb
-Macd.mq4  5 kb
 
Please advise how to list indicator parameters in iCustom.
Files:
q7iqav.PNG  47 kb
 
Please advise mql5, I want to collect statistics about the average size of e.g. a 12-hour candle, for example, today is Friday, and I want to take the data from Thursday, Wednesday, Tuesday and Monday for the calculations.
I take time[] I convert TimeToString, then SplitString and TD. Is there a faster and less cumbersome way to refer to the same time candle a day or more back? Of course, I could run the number of candlesticks of the current timeframe in 24 hours, but I'm afraid that if there are some gaps in quotes, they will be shifted.
Reason: