To make Toggle Drawing - Amibroker

#1
I have a pproblem with Amibroker

I want to show EMA50 line in my chart.

I make a parameter toggle, so i can choose, to show this EMA50 line or not from parameter window.

But, the program can not run as I want.

after the chart show, then I show the amibroker parameter window, and try to change the ShowP50 to "yes" and "no". But it seems that the EMA50 can not appear and disappear as i want.

I still learn AFL.

so can someone help me to fix my code below ?

Thanks.


my code is :
========

ShowPeriode50 = ParamToggle("ShowP50","No|Yes",1);


Plot(C,"",colorBlack,styleCandle);


if (ShowP50 = 1)
{ Plot(EMA(C,50),"EMA 50",colorViolet,styleLine);
};



==========
 

asnavale

Well-Known Member
#2
I have a pproblem with Amibroker

I want to show EMA50 line in my chart.

I make a parameter toggle, so i can choose, to show this EMA50 line or not from parameter window.

But, the program can not run as I want.

after the chart show, then I show the amibroker parameter window, and try to change the ShowP50 to "yes" and "no". But it seems that the EMA50 can not appear and disappear as i want.

I still learn AFL.

so can someone help me to fix my code below ?

Thanks.


my code is :
========

ShowPeriode50 = ParamToggle("ShowP50","No|Yes",1);


Plot(C,"",colorBlack,styleCandle);


if (ShowP50 = 1)
{ Plot(EMA(C,50),"EMA 50",colorViolet,styleLine);
};



==========

Hi,

The Errors in your code are highlighted in Red below:

/******************************************/

ShowPeriode50 = ParamToggle("ShowP50","No|Yes",1);


Plot(C,"",colorBlack,styleCandle);


if (ShowP50 = 1)
{ Plot(EMA(C,50),"EMA 50",colorViolet,styleLine);
};

/**********************************************/

There are two errors:

Error 1:
You are using the variable name ShowPeriode50 to toggle the value between "YES" and "NO" but when testing its value you are using the variable name ShowP50. Therefore the code will not work.

Error 2:
In the test condition you are using the assignment (ShowP50 = 1). This means Make the value of ShowP50 equal to 1. It does not test whether the Value of ShowP50 is equal to 1. It simply makes the value of ShowP50 as 1 and there is no failure in making the value equal to 1. Therefore (ShowP50 = 1) is always a success and therefore always true. Hence your EMA50 line is always plotted.

To test whether a variable is equal to some specific value you should use "==" instead of a single "=". For example when you want to see whether X is equal to 10 you should write "if(X == 10)" and not "if(X = 10)".

Since you mentioned that you are learning I have given a long explanation of the errors.

I have corrected your code and it works.

The correct code is:


ShowP50 = ParamToggle("ShowP50","No|Yes",1);

Plot(C,"",colorBlack,styleCandle);

if (ShowP50) Plot(EMA(C,50),"EMA 50",colorViolet,styleLine);



-Anant
 
#3
Dear Asnavale,


Thanks for your explanation.

Yes, it works now.

Now i understand my mistake.


:)


Do You know, is there any ebook (pdf) which teaching about programing with AFL ?


Best Regards.
 

Similar threads