From int start (which returns value) to be void OnTick (which don't returns values)

To add comments, please log in or register
Abdelrahman Ahmed
32
Abdelrahman Ahmed  

I have an old code MQL4 indicator, I want to use it to create EA but in new MQL4 language.

How to change this part of the code from int start() (which returns value) to be void OnTick (which don't returns values) ?


int start()
{
if(Bars<=10) return(0);
ExtCountedBars=IndicatorCounted();
//---- check for possible errors
if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
if (ExtCountedBars>0) ExtCountedBars--;
int pos=Bars-ExtCountedBars-1;
while(pos>=0)
{
ExtMapBuffer1[pos]=iMA(Symbol(),0,ma_1,0,method,price,pos);
ExtMapBuffer2[pos]=iMA(Symbol(),0,ma_2,0,method,price,pos);
MACD_Map[pos]=ExtMapBuffer1[pos]-ExtMapBuffer2[pos];
pos--;
}
// signal lines
pos=Bars-ExtCountedBars-1;

while(pos>=0)
{
SignalMap[pos]= iMAOnArray(MACD_Map,0,signal,0,s_method,pos);
SignalLine[pos]= NormalizeDouble(ExtMapBuffer2[pos]+SignalMap[pos],Digits);

SignalMap2[pos]= iMAOnArray(MACD_Map,0,signal2,0,s_method2,pos);
SignalLine2[pos]= NormalizeDouble(SignalMap2[pos]+ExtMapBuffer2[pos],Digits);
pos--;
}

return(0);
}
William Roeder
20064
William Roeder  
Abdelrahman Ahmed: How to change this part of the code from int start() (which returns value) to be void OnTick (which don't returns values) ?

You don't! OnTick is for EAs. Your code is an indicator.

You should stop using the old event handlers and IndicatorCounted() and start using the new ones.
          Event Handling Functions - Functions - Language Basics - MQL4 Reference
          How to do your lookbacks correctly.
Abdelrahman Ahmed
32
Abdelrahman Ahmed  
William Roeder:

You don't! OnTick is for EAs. Your code is an indicator.

thank you for clarifying, I understand that OnTick is for EA, Mainly I want to create EA from this indicator which coded by the old event handlers! so how can i use this indicator to build my EA ?

this indicator draw a custom 4 array moving averages , I want to create EA conditions related to this indicator to open orders !

i know how to code the conditions to open orders ! but i can't take any data from that code , that's why the EA is not working !
William Roeder
20064
William Roeder  
Abdelrahman Ahmed: ! but i can't take any data from that code ,
Just get the value(s) of the indicator(s) into the EA (using iCustom) and do what you want with it.
You should encapsulate your iCustom calls to make your code self-documenting.
          Detailed explanation of iCustom - MQL4 programming forum
Abdelrahman Ahmed
32
Abdelrahman Ahmed  
William Roeder:
Just get the value(s) of the indicator(s) into the EA (using iCustom) and do what you want with it.
You should encapsulate your iCustom calls to make your code self-documenting.
          Detailed explanation of iCustom - MQL4 programming forum

thank you :) I'll found out how to use iCustom :)

To add comments, please log in or register