Download MetaTrader 5

MT4: I had this indicator coded, but..

To add comments, please log in or register
davefx
978
davefx  

Hi,

I had an indicator modded today - JJRSX2 - but it not working as I had hoped. Below is a shot of how it should look:

 

How I need the MT4 JJRSX2 indicator to look 

And here is how it looks at the moment..

How the modded indicator looks at the moment 

As you can see, the shifted line in the top image IS actually SHIFTED. The red line (Buffer1) in the bottom image is not physically shifted.

It is the physical line shifting that I need, whether it is in the past OR the future. I have seen this done with other MT4 indicators.

Can this be achieved with my indicator?

Here is the code:

 

/*
Äëÿ ðàáîòû èíäèêàòîðà  ñëåäóåò  ïîëîæèòü  ôàéëû  

JurXSeries.mqh 
JJMASeries.mqh  
PriceSeries.mqh 

â ïàïêó (äèðåêòîðèþ): MetaTrader\experts\include\

Heiken Ashi#.mq4

â ïàïêó (äèðåêòîðèþ): MetaTrader\indicators\

Ïî ñâîèì  ñâîéñòâàì  ýòîò  èíäèêàòîð àáñîëþòíî àíàëîãè÷åí êëàññè÷åñêèì
îñöèëÿòîðàì  è ê íåìó ïðèìåíèìû àáñîëþòíî òå æå ïðè¸ìû òåõàíàëèçà, ÷òî
è  ê  RSI. Òîëüêî áëàãîäàðÿ èñïîëüçîâàíèþ áîëåå ñîâåðøåííûõ àëãîðèòìîâ
ñãëàæèâàíèÿ îí èìååò ìåíüøåå çàïàçäûâàíèå è áîëåå ãëàêóþ ôîðìó êðèâîé.
//---- 
Relative   Strenght  Index  (RSI)
Èíäåêñ îòíîñèòåëüíîé ñèëû - ýòî ñëåäóþùèé çà öåíîé îñöèëëÿòîð, êîòîðûé
êîëåáëåòñÿ  â  äèàïàçîíå îò 0 äî 100. Îäèí èç ðàñïðîñòðàíåííûõ ìåòîäîâ
àíàëèçà  RSI  ñîñòîèò  â ïîèñêå ðàñõîæäåíèé, ïðè êîòîðûõ öåíà îáðàçóåò
íîâûé ìàêñèìóì, à RSI íå óäàåòñÿ ïðåîäîëåòü óðîâåíü ñâîåãî ïðåäûäóùåãî
ìàêñèìóìà.   Ïîäîáíîå   ðàñõîæäåíèå   ñâèäåòåëüñòâóåò   î  âåðîÿòíîñòè
ðàçâîðîòà  öåí.  Åñëè  çàòåì  RSI  ïîâîðà÷èâàåò âíèç è îïóñêàåòñÿ íèæå
ñâîåé   âïàäèíû,   òî   îí   çàâåðøàåò   òàê  íàçûâàåìûé  'íåóäàâøèéñÿ
ðàçìàõ'(failure    swing).    Ýòîò    íåóäàâøèéñÿ   ðàçìàõ   ñ÷èòàåòñÿ
ïîäòâåðæäåíèåì  ñêîðîãî  ðàçâîðîòà  öåí.  Ñïîñîáû  ïðèìåíåíèÿ  RSI äëÿ
àíàëèçà ãðàôèêîâ:
1.  Âåðøèíû  è  îñíîâàíèÿ  Âåðøèíû  RSIîáû÷íî  ôîðìèðóþòñÿ  âûøå 70, à
îñíîâàíèÿ  - íèæå 30, ïðè÷åì îíè îáû÷íî îïåðåæàþò îáðàçîâàíèÿ âåðøèí è
îñíîâàíèé íà öåíîâîì ãðàôèêå.
2.  Ãðàôè÷åñêèå  ìîäåëè  RSI ÷àñòî îáðàçóåò ãðàôè÷åñêèå ìîäåëè - òàêèå
êàê  'ãîëîâà  è  ïëå÷è'  èëè  òðåóãîëüíèêè, êîòîðûå íà öåíîâîì ãðàôèêå
ìîãóò   è  íå  îáîçíà÷èòüñÿ.
3.  Íåóäàâøèéñÿ  ðàçìàõ  (ïðîðûâ  óðîâíÿ  ïîääåðæêè èëè ñîïðîòèâëåíèÿ)
Èìååò  ìåñòî,  êîãäà RSI ïîäíèìàåòñÿ âûøå ïðåäûäóùåãî ìàêñèìóìà (ïèêà)
èëè îïóñêàåòñÿ íèæå ïðåäûäóùåãî ìèíèìóìà (âïàäèíà).
4.  Óðîâíè ïîääåðæêè è ñîïðîòèâëåíèÿ Íà ãðàôèêå RSI óðîâíè ïîääåðæêè è
ñîïðîòèâëåíèÿ ïðîñòóïàþò äàæå îò÷åòëèâåå, ÷åì íà öåíîâîì ãðàôèêå.
5.  Ðàñõîæäåíèÿ  Êàê  óæå  ñêàçàíî âûøå, ðàñõîæäåíèÿ îáðàçóþòñÿ, êîãäà
öåíà  äîñòèãàåò  íîâîãî  ìàêñèìóìà (ìèíèìóìà), íî îí íå ïîäòâåðæäàåòñÿ
íîâûì   ìàêñèìóìîì   (ìèíèìóìîì)  íà  ãðàôèêå  RSI.  Ïðè  ýòîì  îáû÷íî
ïðîèñõîäèò êîððåêöèÿ öåí â íàïðàâëåíèè äâèæåíèÿ RSI.
*/
//+------------------------------------------------------------------+ 
//|                                                        JJRSX2.mq4 |
//|    MQL4 JJRSX: Copyright © 2006,                Nikolay Kositsin | 
//|                              Khabarovsk,   farria@mail.redcom.ru | 
//+------------------------------------------------------------------+  
#property copyright "Copyright © 2006, Nikolay Kositsin"
#property link "farria@mail.redcom.ru" 
//---- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
#property indicator_separate_window
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ
#property indicator_buffers  2
//---- öâåòà èíäèêàòîðà
#property indicator_color1 Lime
//---- ïàðàìåòðû ãîðèçîíòàëüíûõ óðîâíåé èíäèêàòîðà
#property indicator_level1 0.0
#property indicator_levelcolor White
#property indicator_levelstyle 0
//---- ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ --------------------------------------------------------------------------------------------------+
extern int  Length = 5;  // ãëóáèíà JurX ñãëàæèâàíèÿ èíäèêàòîðà
extern int  Smooth = 3;  // ãëóáèíà JJMA ñãëàæèâàíèÿ ïîëó÷åííîãî èíäèêàòîðà
extern int  Phase = 100; // ïàðàìåòð, èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíûx ïðîöåññîâ ñãëàæèâàíèÿ
extern int Input_Price_Customs = 0;/* Âûáîð öåí, ïî êîòîðûì ïðîèçâîäèòñÿ ðàñ÷¸ò èíäèêàòîðà 

(0-CLOSE, 1-OPEN, 2-HIGH, 3-LOW, 4-MEDIAN, 5-TYPICAL, 6-WEIGHTED, 7-Heiken Ashi Close, 8-SIMPL, 9-TRENDFOLLOW, 10-0.5*TRENDFOLLOW,
11-Heiken Ashi Low, 12-Heiken Ashi High,  13-Heiken Ashi Open, 14-Heiken Ashi Close.) */
extern int Shift= -1;
extern color Color_Second_Buffer=Red;
extern bool Alert_when_Cross=true;
//---- -------------------------------------------------------------------------------------------------------------------------------+
//---- èíäèêàòîðíûå áóôåðû
double Ind_Buffer[];
double Ind_Buffer2[];
bool Alerts=true;
datetime LastBar=0;
//---- öåëûå ïåðåìåííûå 
int    w;  
//+------------------------------------------------------------------+  
//----+ Ââåäåíèå ôóíêöèè JJMASeries 
//----+ Ââåäåíèå ôóíêöèè JJMASeriesResize 
//----+ Ââåäåíèå ôóíêöèè JJMASeriesAlert  
//----+ Ââåäåíèå ôóíêöèè JMA_ErrDescr  
#include <JJMASeries.mqh> 
//+------------------------------------------------------------------+ 
//----+ Ââåäåíèå ôóíêöèè JurXSeries
//----+ Ââåäåíèå ôóíêöèè JurXSeriesResize
//----+ Ââåäåíèå ôóíêöèè JurXSeriesAlert 
//----+ Ââåäåíèå ôóíêöèè JurX_ErrDescr  
#include <JurXSeries.mqh> 
//+------------------------------------------------------------------+  
//----+ Ââåäåíèå ôóíêöèè PriceSeries
//----+ Ââåäåíèå ôóíêöèè PriceSeriesAlert 
#include <PriceSeries.mqh>
//+------------------------------------------------------------------+ 
//| JRSX initialization function                                     |
//+------------------------------------------------------------------+ 
int init()
  {
//---- ñòèëè èçîáðàæåíèÿ èíäèêàòîðà
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE,EMPTY,EMPTY,Color_Second_Buffer);
//---- 1 èíäèêàòîðíûé áóôåð èñïîëüçîâàí äëÿ ñ÷¸òà 
   SetIndexBuffer(0,Ind_Buffer);                                           //Green
   SetIndexBuffer(1,Ind_Buffer2);                                          //Red
//---- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   SetIndexEmptyValue(0,0); 
   SetIndexEmptyValue(1,0);
//---- èìåíà äëÿ îêîí äàííûõ è ëýéáû äëÿ ñóáúîêîí
   SetIndexLabel(0,"JRSX");
    SetIndexLabel(1,"JRSX_Shift");
   IndicatorShortName("JRSX(Length="+Length+", Input_Price_Customs="+Input_Price_Customs+")");
//---- Óñòàíîâêà ôîðìàòà òî÷íîñòè (êîëè÷åñòâî çíàêîâ ïîñëå äåñÿòè÷íîé òî÷êè) äëÿ âèçóàëèçàöèè çíà÷åíèé èíäèêàòîðà  
   IndicatorDigits(2);
//----+ Èçìåíåíèå ðàçìåðîâ áóôåðíûõ ïåðåìåííûõ ôóíêöèè JurXSeries, nJurXnumber=2(Äâà îáðàùåíèÿ ê ôóíêöèè JurXSeries)
   if (JurXSeriesResize(2)!=2)return(-1);
//----+ Èçìåíåíèå ðàçìåðîâ áóôåðíûõ ïåðåìåííûõ ôóíêöèè JJMASeries, nJMAnumber=1(Îäíî îáðàùåíèå ê ôóíêöèè JJMASeries)
   if (JJMASeriesResize(1)!=1)return(-1);
//---- óñòàíîâêà àëåðòîâ íà íåäîïóñòèìûå çíà÷åíèÿ âíåøíèõ ïåðåìåííûõ
   JurXSeriesAlert (0,"Length",Length);
   JJMASeriesAlert (0,"Smooth",Smooth);
   JJMASeriesAlert (1,"Phase",Phase);
   PriceSeriesAlert(Input_Price_Customs);
//---- óñòàíîâêà íîìåðà áàðà, íà÷èíàÿ ñ êîòîðîãî áóäåò îòðèñîâûâàòüñÿ èíäèêàòîð  
   SetIndexDrawBegin(0,2*Length+31);
   SetIndexDrawBegin(1,2*Length+31);
//---- êîðåêöèÿ íåäîïóñòèìîãî çíà÷åíèÿ ïàðàìåòðà Length
   if(Length<1)Length=1; 
//---- èíèöèàëèçàöèÿ êîýôôèöèåíòîâ äëÿ ðàñ÷¸òà èíäèêàòîðà 
   if (Length>5) w=Length-1; else w=5;
//---- çàâåðøåíèå èíèöèàëèçàöèè
return(0);
  }
//+------------------------------------------------------------------+ 
//| JRSX iteration function                                          |
//+------------------------------------------------------------------+ 
int start()
{
//---- Ââåäåíèå ïåðåìåííûõ ñ ïëàâàþùåé òî÷êîé 
double dPrice,dPriceA,UPJRSX,DNJRSX,JRSX,JJRSX; 
//----+ Ââåäåíèå öåëûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîäñ÷èòàííûõ áàðîâ
int bar,limit,reset,MaxBar,MaxBarJ,counted_bars=IndicatorCounted();
//---- ïðîâåðêà íà âîçìîæíûå îøèáêè
if (counted_bars<0)return(-1);
//---- ïîñëåäíèé ïîäñ÷èòàííûé áàð äîëæåí áûòü ïåðåñ÷èòàí
if (counted_bars>0) counted_bars--;
//---- îïðåäåëåíèå íîìåðà ñàìîãî ñòàðîãî áàðà, íà÷èíàÿ ñ êîòîðîãî áóäåò ïðîèçåä¸í ïåðåñ÷¸ò íîâûõ áàðîâ
MaxBar=Bars-2; MaxBarJ=MaxBar-w-1; limit=Bars-counted_bars-1; 

//+--- èíèöèàëèçàöèÿ íóëÿ
        if (limit>=MaxBar)
         {
          limit=MaxBar;
          for(bar=Bars-1;bar>=MaxBar;bar--)Ind_Buffer[bar]=0.0;
         }
         
for(bar=limit;bar>=0;bar--)
  {
   //----+ äâà îáðàùåíèÿ ê ôóíêöèè PriceSeries äëÿ ïîëó÷åíèÿ ðàçíèöû âõîäíûõ öåí dPrice
   dPrice = PriceSeries(Input_Price_Customs, bar)-PriceSeries(Input_Price_Customs, bar+1);
   //----+  
   dPriceA=MathAbs(dPrice);
   //----+ Äâà îáðàùåíèÿ ê ôóíêöèè JurXSeries çà íîìåðàìè 0 è 1. Ïàðàìåòð nJJurXLength íå ìåíÿtòñÿ íà êàæäîì áàðå (nJurXdin=0), ïðîâåðêà íà îòñóòñòâèå îøèáêè â ïðåäûäóùåé îïåðàöèè
   UPJRSX=JurXSeries(0,0,MaxBar,limit,Length,dPrice, bar,reset); if(reset!=0)return(-1);
   DNJRSX=JurXSeries(1,0,MaxBar,limit,Length,dPriceA,bar,reset); if(reset!=0)return(-1); 
   //----+
   if (bar>MaxBar-w)JRSX=0;else if (DNJRSX!=0){JRSX=UPJRSX/DNJRSX;if(JRSX>1)JRSX=1;if(JRSX<-1)JRSX=-1;}else JRSX=0;
   //+----------------------------------------------------------------------------+ 
   //----+ Îäíî îáðàùåíèå ê ôóíêöèè JJMASeries çà íîìåðàì 0. 
   //----+ Ïàðàìåòðû nJMA.Phase è nJMA.Length íå ìåíÿþòñÿ íà êàæäîì áàðå (nJMA.din=0)
   //+----------------------------------------------------------------------------+   
   JJRSX=JJMASeries(0,0,MaxBarJ,limit,Phase,Smooth,JRSX,bar,reset);
   //----+ ïðîâåðêà íà îòñóòñòâèå îøèáêè â ïðåäûäóùåé îïåðàöèè
   if(reset!=0)return(-1);
   //+----------------------------------------------------------------------------+  
   Ind_Buffer[bar]=JJRSX; 
   Ind_Buffer2[bar]=Ind_Buffer[bar+Shift];
   if(NewBar())Alerts=true;
  if(Alerts && (Ind_Buffer[1]<Ind_Buffer2[1] && Ind_Buffer[0]>Ind_Buffer2[0]) || (Ind_Buffer[1]>Ind_Buffer2[1] && Ind_Buffer[0]<Ind_Buffer2[0]))
  {Alert("Lines Cross");Alerts=false;}
} 
//---- çàâåðøåíèå âû÷èñëåíèé çíà÷åíèé èíäèêàòîðà

return(0);
}
//+-------------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| New Bar                                                          |
//+------------------------------------------------------------------+
bool NewBar()
  {
   if(Time[0]!=LastBar)
     {
      LastBar=Time[0];
      return(true);
     }
   else return(false);
  }
//+------------------------------------------------------------------+
//| New Bar                                                          |
//+------------------------------------------------------------------+

 

I hope someone can advise.

DaveFX 

davefx
978
davefx  
onewithzachy:

Hi davefx,

1. I think you already knew that those codes is an MQL4 code which should be asked at MQL4 forum, I don't know why you ask it here again. MQL4 have much visitor than MQL5 anyway, go to alexa.com and compare.

2. When posting chart images, try to post with White color background instead of Black, and make the indicator line more thick.

3. When posting codes try to use, SRC button so the codes will be differentiated in color. That way we can tell which one is MQL function, which one vars, etc.

 

If you want other forumer to help you, would you please re-edit your images and codes. That way will help other forumer will understand your problem easily. Just re-edit, don't create new thread with the same topic, coz that risking your thread/topic being deleted by mod/admin for double posting. I will delete my comment here if you do that.

I won't reply more, coz I think - based on the past - you expect someone else to reply.However I do have questions,

1. The first images is not MT4, what is that ?,

2. Do you have it's source code for that trading platform ?.

3. I have other question, but may embarrassing you, so may be later I PM you - maybe.

Good luck

 

 

Sorry, I spent too much time looking at the keyboard than the screen. :)

I will do as you requested. If off to MQL4 as we speak.. 

In answer to your Qs:

1: It is Marketscope/TradingStation 2.

2: Yes, it is in Lua format.

3: Don't worry. Shoot. 

onewithzachy
2269
onewithzachy  

Hi davefx, 

Off MQL4 ?, well, pretty hectic place there lately. Was very busy days for moderator RaptorUK. I didn't know Trading Station can run lua. Anyway I have a hard time reading your code coz you only post some part of the code, which mean I can't compile correctly, and yet not edit your code and yet reply me, and so my answer here could be wrong. and by the way, you should ask this to person who did the job, it just small code modif and I think s/he miss one. 

Read this carefully will you,  

extern int Shift   = -1;  //-->> find this code first !
extern int Shift_0 = -1;  //<<-- then add...
extern int Shift_1 = -1;  //<<-- ... these two lines 

 

 SetIndexBuffer (0, Ind_Buffer);   //-->> find these ...
 SetIndexBuffer (1, Ind_Buffer2);  //-->> two lines ...
 SetIndexShift  (0, Shift_0);    //<<-- the add ...
 SetIndexShift  (1, Shift_1);    //<<-- these two lines

Then compile it, I hope there's no error.

 

 

davefx
978
davefx  

Hi  onewithzachy

Your a star!

It worked! :)))

Many thanks.

Take care + God bless.

DAve 

To add comments, please log in or register