Assigning Bool Input to Chart Buttons Instead Input Values

 

Hi Everybody 

 Suppose i Want to Create 3 Buttons in Chart with Bool Value and i Want Change my indicator parameters with these buttons instead input values

so far i could create all needed things for that but there is a problem that is :

i don't know how to calling OnCalculate() method after i press  "Calculate" button  in other words i need to refresh all calculates in OnCalculate() function after new Button pressed (new indicator input)

please somebody help me at this 

thank you to all .

 
Alireza Rezaee:

Hi Everybody 

 Suppose i Want to Create 3 Buttons in Chart with Bool Value and i Want Change my indicator parameters with these buttons instead input values

so far i could create all needed things for that but there is a problem that is :

i don't know how to calling OnCalculate() method after i press  "Calculate" button  in other words i need to refresh all calculates in OnCalculate() function after new Button pressed (new indicator input)

please somebody help me at this 

thank you to all .

hello,


use :  extern  bool    var1=false;

int var2;

int var3;

you don't have to call OnCalculate(). it run in infinite loop after OnInit() call.

OnInit run just ONE time before OnCalculate() (please lookat the doc for use OnInit(), OnCalculate(), etc....

A condition will check your ask into OnCalculate()

if(var1==true){var2=100] else var2=50; // condition will be checked into the infinite loop OnCalculate() upto you decide to close you program (EA, indicator)

if(var1==false){var3=80] else var3=3;

Comment("\n\n var1= "+IntegerToString(var1)+"    var2="+IntegerToString(var2)+"  var3="+IntegerToString(var3));

please open the MetaEditor and create an indicator and you will get all you need. put what you need into the right function and your program will run as you want

check your variables with Comment() (on the chart)  and Print() (experts window to the bottom of the chart)  functions to check if you get what you need.

Laurent

 
boobyditbeber:

hello,


use :  extern  int, double,.....bool    var1=false;

you don't have to call OnCalculate(). it run in infinite loop after OnInit() call.

OnInit run just ONE time before OnCalculate() (please lookat the doc for use OnInit(), OnCalculate(), etc....

A condition will check your ask into OnCalculate()

if(var1==true){var2=100] else var2=50; // condition will be checked into the infinite loop OnCalculate() upto you decide to close you program (EA, indicator)


Laurent

thanks 

suppose i want change indicator parameters with buttons and not Indicator inputs dialog 

and there is no new tick in market , indicator should recalculate all Bars from first to last with new parameters (change with buttons)

i could not use #input value because  it has constant value and can not be changed during indicator use 

this is different from OnCalculate() infinity loop , this is "Recalculate" with new parameters like when you change indicator input parameters with double Click on it

 
Alireza Rezaee:

thanks 

suppose i want change indicator parameters with buttons and not Indicator inputs dialog 

and there is no new tick in market , indicator should recalculate all Bars from first to last with new parameters (change with buttons)

i could not use #input value because  it has constant value and can not be changed during indicator use 

this is different from OnCalculate() infinity loop , this is "Recalculate" with new parameters like when you change indicator input parameters with double Click on it

https://www.mql5.com/en/forum/277437

My approach uses a global variable and returning 0 from OnCalculate(), which causes a refresh.

Ernst's approach calls OnInit(). I haven't tried his approach, but it looks simpler. He also shows how to fire OnCalculate() with a fake tick in case the market is closed.

Using objects to change the extern variable
Using objects to change the extern variable
  • 2018.09.03
  • www.mql5.com
Hi friends, I usually need to change my indicator extern variable's value in order to change my indicator setting and redraw the indicator with the...
 
Alireza Rezaee:

thanks 

suppose i want change indicator parameters with buttons and not Indicator inputs dialog 

and there is no new tick in market , indicator should recalculate all Bars from first to last with new parameters (change with buttons)

i could not use #input value because  it has constant value and can not be changed during indicator use 

this is different from OnCalculate() infinity loop , this is "Recalculate" with new parameters like when you change indicator input parameters with double Click on it

if you don't have tick you should use OnTimer to get like an  infinite loop 

every seconde or minute or hours or .... timer will launch your function to check which button you click on.

with the help of chart event (you have to verify if it works alone whitout tick entries too. i don't know about that, doc will give you informations


Laurent

 

OnCalculate will be excecuted one time even there is no tick, but just one time, please check it with a simple calcul into the OnCalculate function


Laurent

 

a link that can be usefull :   https://www.mql5.com/en/forum/158187

https://www.youtube.com/watch?v=U6a7MZ2Rpa0

https://www.youtube.com/watch?v=tjlYcXPodfQ


etc....


there are 2 kinds of inputs

input and extern

input can not be modified

extern can be

there are global and one is safe against change the other one is free of change



Laurent :))

Button on Chart to trigger Script
Button on Chart to trigger Script
  • 2016.02.01
  • www.mql5.com
Hi everyone, I am playing around with buttons on the chart and I thought it would be good to have a button that moves the stoploss to breakeven...
 
boobyditbeber:

there are 2 kinds of inputs input and extern input can not be modified extern can be

Laurent :))

"there are 2 kinds of inputs input and extern input can not be modified extern can be"

i had never think  about this . i guess that is the way

thanks  :)

 
Anthony Garot:

https://www.mql5.com/en/forum/277437

My approach uses a global variable and returning 0 from OnCalculate(), which causes a refresh.

Ernst's approach calls OnInit(). I haven't tried his approach, but it looks simpler. He also shows how to fire OnCalculate() with a fake tick in case the market is closed.

"returning 0 from OnCalculate(), which causes a refresh."

"He also shows how to fire OnCalculate() with a fake tick in case the market is closed."

these are thing that i want to do  

ill trying these ways too 

tnx ;)

 
Alireza Rezaee:

"returning 0 from OnCalculate(), which causes a refresh."

"He also shows how to fire OnCalculate() with a fake tick in case the market is closed."

these are thing that i want to do  

ill trying these ways too 

tnx ;)

Hello,

Nice if you got help. 

have a nice day of programing


laurent

Reason: