MQL4 - automated forex trading   /  

Forum

Trend Signal Indicator Question

Back to topics list  | 1 2 To post a new topic, please log in or register

avatar
261
wackena 2006.08.31 21:39 
I'm using this Trend Signal indicator and it fails to keep the trend up and trend down arrows on the chart current. When indicator is reset manually by either reloading, opeing propeties and clicking OK or changing chart timeframe and back again, it redraws the latest arrow with new data. But it doesn't do this automatically.

Can someone please review code below and advise if this indicator code can be altered to keep chart arrows current.

Thanks in advance,

Wackena


//+------------------------------------------------------------------+
//|                                           SHI_SilverTrendSig.mq4 |
//|          Copyright © 2003, VIAC.RU, OlegVS, GOODMAN, 2005 Shurka |
//|                                                 shforex@narod.ru |
//|                                                                  |
//|                                                                  |
//| Ïèøó ïðîãðàììû íà çàêàç                                          |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Shurka"
#property link      "http://shforex.narod.ru"
 
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
 
 
//---- Âõîäíûå ïàðàìåòðû
extern int     AllBars=0;//Äëÿ ñêîëüêè áàðîâ ñ÷èòàòü. 0 - äëÿ âñåõ.
extern int     Otstup=30;//Îòñòóï.
extern double  Per=9;//Ïåðèîä.
int            SH,NB,i,UD;
double         R,SHMax,SHMin;
double         BufD[];
double         BufU[];
#define  SH_BUY   1
#define  SH_SELL  -1
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè                                            |
//+------------------------------------------------------------------+
int init()
{
   // NB çàïèñûâàåì êîëè÷åñòâî áàðîâ äëÿ êîòîðûõ ñ÷èòàåì èíäèêàòîð
   if (Bars<AllBars+Per || AllBars==0) NB=Bars-Per; else NB=AllBars;
   IndicatorBuffers(2);
   IndicatorShortName("SHI_SilverTrendSig");
   SetIndexStyle(0,DRAW_ARROW,0,1);
   SetIndexStyle(1,DRAW_ARROW,0,1);
   SetIndexArrow(0,233);
   SetIndexArrow(1,234);
   SetIndexBuffer(0,BufU);
   SetIndexBuffer(1,BufD);
   SetIndexDrawBegin(0,Bars-NB);//Èíäèêàòîð áóäåòîòîáðàæàòüñÿ òîëüêî äëÿ NB áàðîâ
   SetIndexDrawBegin(1,Bars-NB);
   ArrayInitialize(BufD,0.0);//Çàáü¸ì îáà áóôåðà íîëèêàìè. Èíà÷å áóäåò ìóñîð ïðè ñìåíå òàéìôðåéìà.
   ArrayInitialize(BufU,0.0);
   return(0);
}
//+------------------------------------------------------------------+
//| Ôóíêöèÿ äåèíèöèàëèçàöèè                                          |
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
}
//+------------------------------------------------------------------+
//| Ñîáñíà èíäèêàòîð                                                 |
//+------------------------------------------------------------------+
int start()
{
   int CB=IndicatorCounted();
   /* Òóò âîò òà ñàìàÿ îïòèìèçàöèîííàÿ ôèøêà.  ÿçûê ââåäåíà ôóíêöèÿ, êîòîðàÿ âîçâðàùàåò êîëè÷åñòâî
   ïîñ÷èòàííûõ áàðîâ, ïðè÷¸ì î÷åíü õèòðî. Ïðè ïåðâîì âûçîâå èíäèêàòîðà ýòî 0, âñ¸ ïîíÿòíî, åù¸ íè÷åãî
   íå ñ÷èòàëîñü, à çàòåì âûäà¸ò êîëè÷åñòâî îáñ÷èòàííûõ áàðîâ ìèíóñ îäèí. Ò.å. åñëè âñåãî áàðîâ 100,
   òî ôóíêöèÿ âåðí¸ò 99. ß ââ¸ë òàêîé êîä, âûøå ó ìåíÿ îïðåäåëÿëàñü NB - êîë-âî áàðîâ ïîäëåæàùèõ
   îáñ÷¸òó.  ïðèíöèïå ýòîò ïàðàìåòð ìîæíî è âûêèíóòü, îäíàêî äëÿ òåõ êòî â òàíêå (I80286) ìîæíî
   è îñòàâèòü. Òàê âîò, çäåñü, ïðè ïåðâîì âûçîâå NB îñòà¸òñÿ ïðåæíåé, à ïðè ïîñëåäóþùèõ óìåíüøàåòñÿ
   äî ïîñëåäíåãî áàðà, ò.å. 1 èëè 2, íó èëè ñêîëüêî òàì îñòàëîñü ïîñ÷èòàòü*/
   if(CB<0) return(-1); else if(NB>Bars-CB) NB=Bars-CB;
   for (SH=1;SH<NB;SH++)//Ïðî÷¸ñûâàåì ãðàôèê îò 1 äî NB
   {
      for (R=0,i=SH;i<SH+10;i++) {R+=(10+SH-i)*(High[i]-Low[i]);}      R/=55;
 
      SHMax = High[Highest(NULL,0,MODE_HIGH,Per,SH)];
      SHMin = Low[Lowest(NULL,0,MODE_LOW,Per,SH)];
      if (Close[SH]<SHMin+(SHMax-SHMin)*Otstup/100 && UD!=SH_BUY) { BufU[SH]=Low[SH]-R*0.5; UD=SH_BUY; }
      if (Close[SH]>SHMax-(SHMax-SHMin)*Otstup/100 && UD!=SH_SELL) { BufD[SH]=High[SH]+R*0.5; UD=SH_SELL; }
   }
   return(0);
}


article

Expert Advisors Based on Popular Trading Systems and Alchemy of Trading Robot Optimization (Cont.)

In this article, the author gives an example Expert Advisor meeting the requirements stated in the Rules of the Automated Trading Championship 2008


avatar
Moderator
4803
stringo 2006.09.01 12:22 
Try to copy one line from init function to start function
int start()
{
   if (Bars<AllBars+Per || AllBars==0) NB=Bars-Per; else NB=AllBars;
   int CB=IndicatorCounted();
...


avatar
261
wackena 2006.09.01 13:34 
stringo wrote:
Try to copy one line from init function to start function
int start()
{
   if (Bars<AllBars+Per || AllBars==0) NB=Bars-Per; else NB=AllBars;
   int CB=IndicatorCounted();
...


Stringo, thank you. I tested the recommended change as a cut amd paste and all arrows on chart disappeared. I'm now testing as you stated a copy and paste.

avatar
261
wackena 2006.09.02 12:28 
wackena wrote:
stringo wrote:
Try to copy one line from init function to start function
int start()
{
   if (Bars<AllBars+Per || AllBars==0) NB=Bars-Per; else NB=AllBars;
   int CB=IndicatorCounted();
...


Stringo, thank you. I tested the recommended change as a cut amd paste and all arrows on chart disappeared. I'm now testing as you stated a copy and paste.
Stringo, I tested your recommendation and it did not work. Still have to manually reset indicator to get indicator to update position of arrows. Any other suggestions will be appreciated.

avatar
97
Zonker 2006.09.03 14:06 

Have you tried

start()

..

for(SH=0;SH<NB; etc..


avatar
261
wackena 2006.09.04 14:14 
Zonker wrote:

Have you tried

start()

..

for(SH=0;SH<NB; etc..

 

Zonker, I tried this. Sorry, it did not work. Still have to manually reset indicator to get current data to redraw arrows.

Any other ideas, please advise.

Thanks very much,

Wackena

avatar
Moderator
4803
stringo 2006.09.04 14:33 
wackena, I cannot reproduce your problem

avatar
43
zolero 2006.09.04 15:15 
wackena wrote:
I'm using this Trend Signal indicator and it fails to keep the trend up and trend down arrows on the chart current. When indicator is reset manually by either reloading, opeing propeties and clicking OK or changing chart timeframe and back again, it redraws the latest arrow with new data. But it doesn't do this automatically.

Can someone please review code below and advise if this indicator code can be altered to keep chart arrows current.

Thanks in advance,

Wackena

If I understood your problem correcly you want that the indicator would update all arrows to have the actual situation. If so you should use BarsPerWindow() function. so it calculates all visible dataset. so change the line
if(CB<0) return(-1); else if(NB>Bars-CB) NB=Bars-CB;

because it makes the code calculate just one bar -- after first calculatiod CB=1 and this means that if the new Bar is created it calculates only new data. what you need is something like
if(CB<0) return(-1); else if(CB==0) NB=Bars; else NB=BarsPerWindow();
ObjectsDeleteAll(EMPTY, OBJ_ARROW);
for(int n=0;nNB;n++)
{
BufU[n]=0.00;
BufD[n]=0.00;
}

now the code calculates at first time all Bars and after that all visible bars and deletes all old arrows before that. It looks that your problem is constantly new arrows (groups) if the signal is coming...

this should do what you asked for...

avatar
261
wackena 2006.09.04 15:23 
stringo wrote:
wackena, I cannot reproduce your problem
Stringo, I use the indicator on H4 chart. But that is too long for you to wait to see the problem. Attached indicator to M1 chart and wait a few minutes. Place curser over one of the arrows until text ID box appears. Right-click on the arrow and select indicator's properties, and then click OK. you will see the newest arrow redrawn in new position. The indicator's data is current, but it is unable to keep chart current. 

Can a reset be coded into indicator or in the EA attached to same chart?

Any advice is greatly appreciated.

Wackena

avatar
261
wackena 2006.09.04 16:35 
zolero wrote:
wackena wrote:
I'm using this Trend Signal indicator and it fails to keep the trend up and trend down arrows on the chart current. When indicator is reset manually by either reloading, opeing propeties and clicking OK or changing chart timeframe and back again, it redraws the latest arrow with new data. But it doesn't do this automatically.

Can someone please review code below and advise if this indicator code can be altered to keep chart arrows current.

Thanks in advance,

Wackena

If I understood your problem correcly you want that the indicator would update all arrows to have the actual situation. If so you should use BarsPerWindow() function. so it calculates all visible dataset. so change the line
if(CB<0) return(-1); else if(NB>Bars-CB) NB=Bars-CB;

because it makes the code calculate just one bar  -- after first calculatiod CB=1 and this means that if the new Bar is created it calculates only new data. what you need is something like
if(CB<0) return(-1); else if(CB==0) NB=Bars; else NB=BarsPerWindow();

now the code calculates at first time all Bars and after that all visible bars.

to be sure you see only new arrows use ObjectsDeleteAll(EMPTY, OBJ_ARROW); by deinit(). ..

this should do what you asked for...
zolero, I tried your suggestion. New arrow is now drawn, but preceding arrow does not delete itself. So, after a few minutes on M1 chart, there can be multiple same colour arrows next to each other. I put put the suggested delete code as follows;

int deinit()
{
    ObjectsDeleteAll(EMPTY, OBJ_ARROW); 
    return(0);
}


When I reset indicator, the multiple arrows delete and newest arrown remains drawn. 

Wackena

avatar
43
zolero 2006.09.04 16:53 
wackena wrote:


When I reset indicator, the multiple arrows delete and newest arrown remains drawn.

Wackena

if(CB<0) return(-1); else if(CB==0) NB=Bars; else NB=BarsPerWindow();
ObjectsDeleteAll(EMPTY, OBJ_ARROW);
for(int n=0;nNB;n++)
{
BufU[n]=0.00;
BufD[n]=0.00;
}
this deletes multiple arrows
Back to topics list   | 1 2  

To add comments, please log in or register