MQL4 Learning - page 107

 

I tested all EA from there but only this is working fine "e-CloseByTime" But it dont bye.

 

Need help with code for adding market order during trend

Could someone help me with adding code to my EA. I would like it to add market orders during the trend at regular intervals. Any help would be greatly appreciated. Marty

 

MARTINGALE + LAGUERRE + TrendRSI_v3 in expert

I have a EA based on Laguerre and Moving Averages indicators, among others.

But now i want introduce the indicator ( TrendRSI_v3 ) in expert.

please someone help me in the conditions of the buy and sell this indicator

i did it this way but not working

double TrendRsi_Up = iCustom(NULL,0,"TrendRSI_v3",RSIPeriod,EMAPeriod,ATRPeriod,K,1,0);

double TrendRsi_Dn = iCustom(NULL,0,"TrendRSI_v3",RSIPeriod,EMAPeriod,ATRPeriod,K,2,0);

//----------------------------conditions of the sell----------//

if(OrdersTotalMagicbuy(Magicsell)<1)

{

if( TrendRsi_Up < 1){

if(martingale == false){

orderclosebuy(ticketbuy);

}

SellValue = 1;

}

}

//----------------------------conditions of the buy----------//

if(OrdersTotalMagicsell(Magicbuy)<1)

{

if(TrendRsi_Dn > 2){

if(martingale == false){

orderclosesell(ticketsell);

}

BuyValue = 1;

}

}

//-------------------indicator TrendRSI_v3--------------------------//

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_color1 Silver

#property indicator_color2 LightBlue

#property indicator_color3 Tomato

//---- input parameters

extern int RSIPeriod=14;

extern int EMAPeriod= 5;

extern int ATRPeriod=14;

extern double K=4.236;//2.618

//---- buffers

double RSIindex[];

double UpTrend[];

double DnTrend[];

double RSIBuffer[];

double smin[];

double smax[];

double trend[];

int MAPeriod=1;

int Price=0;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

string short_name;

//---- 2 additional buffers are used for counting.

IndicatorBuffers(7);

//---- indicator line

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,RSIindex);

SetIndexStyle(1,DRAW_ARROW);

SetIndexBuffer(1,UpTrend);

SetIndexStyle(2,DRAW_ARROW);

SetIndexBuffer(2,DnTrend);

SetIndexArrow(1,159);

SetIndexArrow(2,159);

SetIndexBuffer(3,RSIBuffer);

SetIndexBuffer(4,smin);

SetIndexBuffer(5,smax);

SetIndexBuffer(6,trend);

//---- name for DataWindow and indicator subwindow label

short_name="TrendRSI("+RSIPeriod+","+EMAPeriod+","+ATRPeriod+","+DoubleToStr(K,3)+")";

IndicatorShortName(short_name);

SetIndexLabel(0,short_name);

SetIndexLabel(1,"UpTrend");

SetIndexLabel(2,"DownTrend");

//----

SetIndexDrawBegin(0,RSIPeriod+EMAPeriod+ATRPeriod);

SetIndexDrawBegin(1,RSIPeriod+EMAPeriod+ATRPeriod);

SetIndexDrawBegin(2,RSIPeriod+EMAPeriod+ATRPeriod);

//----

return(0);

}

//+------------------------------------------------------------------+

//| TrendRSI_v3 |

//+------------------------------------------------------------------+

int start()

{

int i,limit,counted_bars=IndicatorCounted();

double rel;

//----

if ( counted_bars < 0 ) return(-1);

if ( counted_bars ==0 ) limit=Bars-1;

if ( counted_bars < 1 )

for( i=1;i<RSIPeriod+EMAPeriod+ATRPeriod;i++)

{

RSIindex=0.0;

UpTrend=0.0;

DnTrend=0.0;

}

if(counted_bars>0) limit=Bars-counted_bars;

limit--;

for( i=limit; i>=0; i--)

{

double sumn=0.0,sump=0.0;

for (int k=RSIPeriod-1;k>=0;k--)

{

rel=iMA(NULL,0,MAPeriod,0,MODE_SMA,Price,i+k)-iMA(NULL,0,MAPeriod,0,MODE_SMA,Price,i+k+1);

if(rel>0) sump+=rel; else sumn-=rel;

}

double pos=sump/RSIPeriod;

double neg=sumn/RSIPeriod;

if(neg==0.0) RSIBuffer=100.0;

else

RSIBuffer=100.0-100.0/(1.0+pos/neg);

RSIindex=RSIindex+2.0/(1.0+EMAPeriod)*(RSIBuffer-RSIindex);

double AvgRange=0;

for ( k=ATRPeriod-1;k>=0;k--)

AvgRange+=MathAbs(RSIindex-RSIindex);

double Range = AvgRange/ATRPeriod;

smax=RSIindex+K*Range;

smin=RSIindex-K*Range;

trend=trend;

if (RSIindex>smax) trend=1;

if (RSIindex<smin) trend=-1;

if(trend>0)

{

if (smin<smin) smin=smin;

UpTrend=smin;

DnTrend=EMPTY_VALUE;

}

else

{

if(smax>smax) smax=smax;

UpTrend=EMPTY_VALUE;

DnTrend=smax;

}

}

//----

return(0);

}

//+------------------------------------------------------------------+

 

kenoor

Meta Language question: How do I reference custom or purchased indicators in my code?

 

Equity as Indicator

Hello,

I want to programm the Equity as an Indicator. I tried it in this way, but it doesn't work

int init()

{

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,EquityBuffer);

SetIndexLabel(0,"EquityBuffer");

SetIndexDrawBegin(0,0);

return(0);

}

int start()

{

int limit;

int counted_bars=IndicatorCounted();

//---- check for possible errors

if(counted_bars<0) return(-1);

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int k=0; k<limit; k++)

{

EquityBuffer[k] = AccountEquity();

}

//----

return(0);

}Can anybody tell me why?!

 

You need to use iCustom function to pass parameters to the custom indicators and get the values of whichever mode you prefer.

kenoor:
Meta Language question: How do I reference custom or purchased indicators in my code?
 

"\n" comment line

Hi coders,

In the "comment" text in an EA, is there any maximum "\n" comment lines ?

Compiling I have a ")"- wrong parameters count error.

What does this mean ?

Thanks a lot

Tomcat

 

Maximum "\n" Comment Lines

Tomcat98:
Hi coders,

In the "comment" text in an EA, is there any maximum "\n" comment lines ?

Compiling I have a ")"- wrong parameters count error.

What does this mean ?

Thanks a lot

Tomcat

Hi Tomcat,

Quick answer - yes... I don't know the number of comment lines but I have hit the maximum many times. Had to double and triple up my values on the same lines to display them all...

Example:

"\n Value1=",Value1," Value2=",Value2," Value3=",Value3,

Compiling errors - In most cases the first error is the one you have to solve. All the rest may not be errors.

Without seeing the list of errors and which error is first on the list, that "wrong parameters count" error could be from the domino effect of your "\n" line error.

Fix the first error, recompile, and solve the next. In most cases solving the first error fixes all the rest.

Otherwise if the same error comes up again, "wrong parameters count" usually means that the values don't match or the right parenthesis ")" is missing in one of the lines.

Hope this helps,

Robert

 

Maximum "\n" Comment Lines

Hi Cosmiclifeform,

Yes it helps;

I thank you for your answer.

I have isolated each of my comment lines with //

All my comment lines have their own good syntax.

Maximum lines appears to be 11. One more comment line build the folowing error "wrong parameters count" while again all lines compiled separately build "zero error".

"double and triple up my values on the same lines to display them all..." could be a clue...

Working on that...

I thank you very much Robert

Tomcat

 

beginner for coding

Dear all guru,

void calculateRanges()

{

g_bar1Range = MathAbs( High[ 1 ] - Low[ 1 ] );

g_bar2Range = MathAbs( High[ 2 ] - Low[ 2 ] );

g_bar1Body = MathAbs( Open[ 1 ] - Close[ 1 ] );

if( MathAbs( g_bar1Body ) < EPSILON )

Can I ask this code calculate the last candle range (g_bar1range) and 2 candle stick before the current candlestick (g_bar2range)? Am i correct?

Thank you in advance.

Reason: