i not mess with indicators like u need but search site lsma and this maybe give help 'Linear Regression Indicator'
i not mess with indicators like u need but search site lsma and this maybe give help 'Linear Regression Indicator'
Yes that is the indicator. but, my question is where do I insert it into the code. The normal way to do something like that is to change the
Mode_SMA to Mode_EMA or what ever.
But, since the language editor does not have that listed than it does not support that code in that fashion. I beleive it has to be add as a custom indicator and that is to advanced for my little pee brain and my lack of coding skils. But, thanks anyway.
no way - not peewee ;)
icustom easy once use.
do any old basic terminal call if u have the source too
i show u - i copy from help and give example and give code u take and compile and do it 4sure
double iCustom( | string symbol, int timeframe, string name, ..., int mode, int shift) |
do this for below code - the zero lag macd indicator
double result = iCustom(symbolpairnameOR NULLOR Symbol(),yourperiodvalueORzeroOR Period(),"ZeroLag_MACD",12,24,9,0,yourShiftvalue);
ok - see the 3 externs in source? they in custom call too. start with first,second,....
ok - see zero in custom call b4 yourShiftvalue? that is indexbuffer number 0..7 and is buffer that indicator puts values into and u see on chart.
see how use zero cuz MACDBuffer[] is told to system as indexbuffer 0 by SetIndexBuffer(0,
there u r - not bean brain at all - u can do ;)
result is the double value held in MACDBuffer[yourShiftvalue] which indicator of course has loaded up all buffer - terminal/custom just give u that one as u have askd it do.
u put below code into editor and saveas ZeroLag_MACD in the indicator dir like help says.
compile it... maybe it compile ok ;)
now u compile ur code with above kinda custom call - fill in blanks ok and use result like maybe print it out with shift value to? then u can run the indicator on chart - look at macd line compare values - be happy - then u try other mode value and maybe shifts too
maybe u thy this - and i know this that once get hang of it, is good and u can now use custom on all sorta stuff
one thing in help:
Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.
so u have NO parameters which mean indicator have NO externs - wat u do? do this
double result = iCustom(symbolpairnameOR NULLOR Symbol(),yourperiodvalueORzeroOR Period(),"ZeroLag_MACD",0,yourShiftvalue);
see after "..." all 12,24,9 gone? see - some indicators need NO inputs
but above only example - not work below code ok?
another example u want vaue from SignalBuffer[yourShiftValue] so put one as mode value as this buffer indexbuffer 1
double result = iCustom(symbolpairnameOR NULLOR Symbol(),yourperiodvalueORzeroOR Period(),"ZeroLag_MACD",12,24,9,1,yourShiftvalue);
//ZeroLag MACDx.mq4 | #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Blue #property indicator_color2 Red //---- input parameters extern int FastEMA = 12; extern int SlowEMA = 24; extern int SignalEMA = 9; //---- buffers double MACDBuffer[]; double SignalBuffer[]; double FastEMABuffer[]; double SlowEMABuffer[]; double SignalEMABuffer[]; double ZEROline[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(6); SetIndexBuffer(0, MACDBuffer); SetIndexBuffer(1, SignalBuffer); SetIndexBuffer(3, FastEMABuffer); SetIndexBuffer(4, SlowEMABuffer); SetIndexBuffer(5, SignalEMABuffer); //SetIndexStyle(0, DRAW_HISTOGRAM); SetIndexStyle(0, DRAW_LINE,EMPTY); SetIndexStyle(1, DRAW_LINE,EMPTY); SetIndexDrawBegin(0, SlowEMA); SetIndexDrawBegin(1, SlowEMA); IndicatorShortName("ZeroLag MACD(" + FastEMA + "," + SlowEMA + "," + SignalEMA + ")"); SetIndexLabel(0, "MACD"); SetIndexLabel(1, "Signal"); //draw zero line. means user not need to add via indicator properties>levels SetIndexStyle(2, DRAW_LINE); SetIndexBuffer(2, ZEROline); SetIndexDrawBegin(2, SlowEMA); SetLevelStyle(DRAW_LINE, 1, Gainsboro); SetLevelValue(2,0.0); IndicatorDigits(8); //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; limit = Bars - counted_bars; double EMA, ZeroLagEMAp, ZeroLagEMAq; for(int i = 0; i < limit; i++) { FastEMABuffer[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i); SlowEMABuffer[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i); } for(i = 0; i < limit; i++) { EMA = iMAOnArray(FastEMABuffer, Bars, FastEMA, 0, MODE_EMA, i); ZeroLagEMAp = FastEMABuffer[i] + FastEMABuffer[i] - EMA; EMA = iMAOnArray(SlowEMABuffer, Bars, SlowEMA, 0, MODE_EMA, i); ZeroLagEMAq = SlowEMABuffer[i] + SlowEMABuffer[i] - EMA; MACDBuffer[i] = ZeroLagEMAp - ZeroLagEMAq; } for(i = 0; i < limit; i++) SignalEMABuffer[i] = iMAOnArray(MACDBuffer, Bars, SignalEMA, 0, MODE_EMA, i); for(i = 0; i < limit; i++) { EMA = iMAOnArray(SignalEMABuffer, Bars, SignalEMA, 0, MODE_EMA, i); SignalBuffer[i] = SignalEMABuffer[i] + SignalEMABuffer[i] - EMA; } return(0); } //+------------------------------------------------------------------+
"How can I add or change the trend to the LSMA?"
You can't do what you are looking to do.
You can write custom code to apply a least squares moving average in the calculation of other indicators, but not just "slip it in" to the existing functions you mentioned.
Ok, how does one do something like that for the 100 pip EA? Can you direct me to the documentation that would assist me in understanding how to do such a thing. Or would you assist me in doing that coding writing task?
if(timeframe==0) {timeframe=Period();}
double diClose0=iClose(Symbol(),timeframe,0);
double diMA1=iMA(Symbol(),timeframe,7,0,MODE_SMA,PRICE_OPEN,0);
double diClose2=iClose(Symbol(),timeframe,0);
double diMA3=iMA(Symbol(),timeframe,6,0,MODE_SMA,PRICE_OPEN,0);
if(AccountFreeMargin()<(1000*LotsOptimized())){
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0); }
if(!ExistPositions()) {
if((diClose0<diMA1)) {
OpenBuy();
return(0); }
if ((diClose2>diMA3)) {
OpenSell();
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am new to this code writing stuff. But the EMA Cross.mq4. only use the EMA as is its trend. How can I add or change the trend to the LSMA? This trend indicator seems to be more reliable than the EMA or the others that are offer in the MQ4 language. Where does one find the code for this LSMA and where do you place it in the code. I would like to add the LSMA to this EA also. The 100 pips. Any ideas? Here is some of the code for the 100 pips. I beleive that this is where the EA find the trend.
if(timeframe==0) {timeframe=Period();}
double diClose0=iClose(Symbol(),timeframe,0);
double diMA1=iMA(Symbol(),timeframe,7,0,MODE_SMA,PRICE_OPEN,0);
double diClose2=iClose(Symbol(),timeframe,0);
double diMA3=iMA(Symbol(),timeframe,6,0,MODE_SMA,PRICE_OPEN,0);
As you can see the 100 pips uses the SMA. How do we change that to the LSMA the language does not support that indicator or does it? Iam lost.
Moving Average calculation method used with iAlligator(), iEnvelopes(), iEnvelopesOnArray, iForce(), iGator(), iMA(), iMAOnArray(), iStdDev(), iStdDevOnArray(), iStochastic() indicators.
It can be any of the following values: