[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 647

 
Mathers:

right.
 
Good afternoon forum members. Found an interesting code for constructing a trend line. And decided to play with it a little - that would draw the trend line not in points, but in percentage, but for some reason - after my completion turret stops drawing history - only the last three bars (or rather if you run the turret, the trend line it draws since start normal, but once you click to update turret - property>ОК history resets. What did I do wrong?
I drew the code below. May someone tell me what's the problem - the snippet I put in bold?
The problem is that the indicator draws the history backward immediately and does not reset it after changing the parameters.
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LimeGreen

double AUD;

extern int PerAvr=5,Delta=1;
double Idx[];
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(0,Idx);

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
for(int i=limit; i>=0; i--)
{
AUD=(iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i)-iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+De lta)*100/iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+De lta);

//if (Curency =="AUDUSD")
Idx[i] = AUD;



}

//----

//----
return(0);
}
//+------------------------------------------------------------------+
 
Lonely_man:
Good afternoon, forum members. I found an interesting code for building a trend line. I decided to play with it a little bit.

For some reason I was reminded of an anecdote: in a family of a programmer, a son approaches his father and asks why the sun rises in the east and sets in the west.

Daddy, without taking his eyes off his computer, does it really rise in the east? -Yes. -And it sets in the west? - Yeah. So, what, every day? - Yes. Well, don't touch anything if it's working.

 
Roger:

For some reason I was reminded of an anecdote: in a family of a programmer, a son approaches his father and asks why the sun rises in the east and sets in the west.

Daddy, without taking his eyes off his computer, does it really rise in the east? -Yes. -And it sets in the west? - Yeah. So, what, every day? - Yeah. Well, you don't have to touch anything if it's working.

:))
 
Lonely_man:
Hello forum users, I have found an interesting code for drawing the trend line.

You know what's funny - you've changed the code according to your principles and want a brigade of scholars to find faults

and you just try to output the information that you want to get in the commentary? it's possible that everything works but you get the data that is not displayed at the current price but somewhere at the bottom of the chart - i think it's the separatetwinds

SZS good luck

 
IgorM:

You know what's funny - you've changed the code according to your principles and want a brigade of scholars to find faults

and you just try to output the information that you want to get in the commentary? it's possible that everything works but you get the data that is not displayed at the current price but somewhere at the bottom of the chart - i think it's the separatetwinds

SZS good luck

I know about the separator - I know, it's in a separate window, it's not about it. I can't see what will happen with this code - apparently this method of calculation will not work for percentages((.

Immediately, for some reason I recall a joke - a programmer's son comes to his father and asks why the sun rises in the east and sets in the west?

Daddy, without taking his eyes off his computer, does it really rise in the east? -Yes. -And it sets in the west? - Yeah. So, what, every day? - Yeah. Well, you don't have to touch anything if it's working.

))) I'm just not sure what I want to do. Hint: I need it for cross currency trading - their pips to the dollar change of GBP or JPY do not give complete information, which of them fell in price against the other, but their percentage change against the dollar shows everything clearly - as an additional tool is very useful thing.
 
Mathers:
Thank you. I guess the only difference is that the EA is launched every time a new tick comes in, while the script has to be launched in infinite loop to keep it running?


Not necessarily. It all depends on the purpose of the script. If the purpose of the script is for a one-off run (which is the vast majority), there's no need to make up endless loops. The need of calculating the amount of money to be involved in the market when opening a position with a preset lot can serve as an example of such a one-time script. Since the point price at minimum lot is different for different instruments, it is easier to open the required instrument, apply the script to it, enter the intended lot into the parameters window and see how much money will be blocked if the trade is opened.

This is just an example. The purpose of the scripts may be different.

 
Lonely_man:

I'm aware of the separateness - I know, it's in a separate window, it's not about it. I don't see how this code will work - apparently this method of percentage calculation won't work((.

Immediately, for some reason I recalled an anecdote: a son in a family of a programmer comes to his father and asks why the sun rises in the east and sets in the west?

Daddy, without taking his eyes off his computer, does it really rise in the east? -Yes. -And it sets in the west? - Yeah. So, what, every day? - Yeah. Well, you don't have to touch anything if it's working.

))) The hint: I need it for cross currency trading - pips to the dollar for GBP or JPY do not give complete information which of them fell in price against the other, but their percentage change against USD shows everything clearly - as an additional indicator it's a very useful thing.

It's a pretty simple indicator. I don't see how percentages are any better than pips, but whatever.

You've made some mistakes, though :)

1.

AUD=(iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE, i)-iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+Delta)*100/iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+Delta));

To correctly calculate the percentage you must add parentheses.

AUD=((iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE, i)-iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+Delta))*100/iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+Delta));

2.


The problem is that the indicator draws the history backward immediately and does not reset it after changing the parameters.

The most interesting thing is that it woke up the sporting interest and sat for half an hour on your indicator.

Why wasn't the history calculated?
The answer is that you added a division operation.

100/iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+Delta)

The fact that the iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE ,i+Delta) function returns 0 at the very beginning of the history has not been taken into account. And you were "kicked out" with error 4013 (ERR_ZERO_DIVIDE) when trying to divide by 0, check the log.

We may add one more check into FOR loop.

if(iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+Delta) == 0)continue;

And everything will be all right. Below is my variant.

#property copyright "Copyright © 2010, Анатолий Сергеев"
#property link      "mql.sergeev@yandex.ru"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LimeGreen

double AUD;

extern int PerAvr=5,Delta=1;
double Idx[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+
int init(){
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(0,Idx);
//----
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start(){ 
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;   
   for(int i=limit; i>=0; i--){
      double a = iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE, i);
      double b = iMA("AUDUSD",0,PerAvr,0,MODE_LWMA,PRICE_CLOSE,i+Delta);      
      if(b == 0)continue;      
      AUD=((a-b)*100/b);
      Idx[i] = AUD;
   }
}
//+------------------------------------------------------------------+


 

#property indicator_color1 White

Is it possible to change this parameter programmatically in the start() module,

i.e. is it possible to change the colour set for the buffer as the program progresses?



 
valenok2003:

#property indicator_color1 White

Is it possible to change this parameter programmatically in the start() module,

i.e. is it possible to change the colour set for the buffer as the program progresses?




I don't think so. And why should it be?