How to code? - page 294

 

OrderSend(Symbol..... query

int ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);

my question is this:

can the symbol() part be changed so it says eurusd so when i run the buy script it just buys eurusd...from any chart i run it?

something like:

int ticket=OrderSend(eurusd,OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);

thanks

 

...

Yes. it can

Just be careful with the casing. The call should look like this :

int ticket=OrderSend("EURUSD",OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);
al_shore:
int ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);

my question is this:

can the symbol() part be changed so it says eurusd so when i run the buy script it just buys eurusd...from any chart i run it?

something like:

int ticket=OrderSend(eurusd,OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);

thanks
 

EA doesnt Work

Dear Friends,

I am new in Forex , Although It didnt give error when compiling , I didnt make it work , please someone help me on what is wrong with it ?

thanks in advance

Files:
test_ea.mq4  128 kb
 

...

You can not just copy a code from an indicator to an EA and expect it to work (especially indicators from Nikolay Kostisin who is not known for simple code)

For start, better use the indicators through iCustom() call and keep the trading logic in the EA, that way you are going to get a much easier to write EA

kemal44:
Dear Friends,

I am new in Forex , Although It didnt give error when compiling , I didnt make it work , please someone help me on what is wrong with it ?

thanks in advance
 

How to Code Volatility Quality EA

Greeting to all !

I'm new to metatrader EA. How do I code the VQ indicator into an EA to trade in M15 timeframe but buy sell trigger base on Volatility Quality indictor selected timeframe?

Many Thanks

Files:
vq7.mq4  8 kb
 

You will also need to change Ask to MarketInfo("EURUSD", MODE_ASK).

Otherwise the trade will not succeed. The Ask will be for the symbol of the chart.

Also be aware that some brokers add other characters before or after the symbol name

like "EURUSDm".

Robert

al_shore:
int ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);

my question is this:

can the symbol() part be changed so it says eurusd so when i run the buy script it just buys eurusd...from any chart i run it?

something like:

int ticket=OrderSend(eurusd,OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);

thanks
 

...

ymkoh

Check this thread : https://www.mql5.com/en/forum/general

There are quite a few versions of EA using volatility quality there

ymkoh:
Greeting to all !

I'm new to metatrader EA. How do I code the VQ indicator into an EA to trade in M15 timeframe but buy sell trigger base on Volatility Quality indictor selected timeframe?

Many Thanks
 
mladen:
ymkoh

Check this thread : https://www.mql5.com/en/forum/general

There are quite a few versions of EA using volatility quality there

Thank for the info!

I've tried most of them but none can work.

examples:- EA Trading TF H1 VQ input 240.

It only works on Trading TF H1 VQ input 0 default.

Attached screenshot show example trading TF H1 buysell signal trigger by VQ indicator H4 timeframe. (No EA attached)

vq7.mq4

 

this kind of indicator about Hurst Exponent

Hi, anybody can help me?I want this kind of indicator about Hurst Exponent. the cod is successly programmed by the compiler, but no image,can you fix it? Thank you!

The values of the Hurst Exponent range between 0 and 1.

* A Hurst Exponent value H close to 0.5 indicates a random walk (a Brownian time series). In a random walk there is no correlation between any element and a future element and there is a 50% probability that future return values will go either up or down. Series of this type are hard to predict.

* A Hurst Exponent value H between 0 and 0.5 exists for time series with "anti-persistent behaviour". This means that an increase will tend to be followed by a decrease (or a decrease will be followed by an increase). This behaviour is sometimes called "mean reversion" which means future values will have a tendency to return to a longer term mean value. The strength of this mean reversion increases as?H?approaches 0.

* A Hurst Exponent value H between 0.5 and 1 indicates "persistent behavior", that is the time series is trending. If there is an increase from time step [t-1] to [t] there will probably be an increase from [t] to [t+1]. The same is true of decreases, where a decrease will tend to follow a decrease. The larger the?Hvalue is, the stronger the trend. Series of this type are easier to predict than series falling in the other two categories.

Calculation is as follows

Step_A、X= MathLog(Close/Close)

{ the value of H from a single R/S

Step1、E = (1/n)*[X(0)+X(1)+X(2)+...+X(n-1) ]

Step2、A(0) = X(0) - E

A(1) = X(1) - E

A(2) = X(2) - E

...

A(n-1) = X(n-1) – E

Step3、SUM(0) = A(0)

SUM(1) = A(0)+ A(1)

SUM(2) = A(0)+A(1) + A(2)

...

SUM(n-1) = A(0)+A(1) + A(2) + ...+ A(n-1)

Step4、R= Maximum(SUM,n) - Minimum(SUM,n)

Step5、H = log(R/S)/log(n/2) // Let?s be the standard deviation of the set of { X(0),X(1), X(2), ... X(n-1)}

}

Step_B、calculate H from the set of { X(i),X(i+1), X(i+2), ... X(i+n-1)}

Step_C、calculate H_SMA, Let it smooth ,if H_SMA=0.5 then alert

cod is as follows

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

//| #HURST.mq4 |

//| chenairbin. |

//| MetaTrader 4 Trading Platform / MetaQuotes Software Corp. |

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

#property copyright "chenairbin."

#property link "http://www.metaquotes.net"

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_maximum 1

#property indicator_buffers 7

#property indicator_color7 Yellow

extern int n=21,S_EMA=8;

extern double Natural=0.5;

double X[],E[],S[],A[],SUM[],H[],C[];

int init()

{

IndicatorBuffers(7);

SetIndexBuffer(0,X);

SetIndexBuffer(1,E);

SetIndexBuffer(2,S);

SetIndexBuffer(3,A);

SetIndexBuffer(4,SUM);

SetIndexBuffer(5,H);

SetIndexStyle(6,DRAW_LINE);

SetIndexBuffer(6,C);

return(0);

}

int start()

{

int i;

int limit;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

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

{

X= MathLog(Close/Close);

}

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

{

E=iMAOnArray(X,0,n,0,MODE_EMA,i);

S=iStdDevOnArray(X,0,n,0,MODE_EMA,i);

}

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

{

A=X-E;

}

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

{

for (int j=0;j<n;j--)

{

for (i=limit-1;0<=i<=j;i--)

{

double B=0,SUM[];

B=B+A;

SUM[j]=B;

}

}

H=MathLog((SUM[ArrayMaximum(SUM,n,0)]-SUM[ArrayMinimum(SUM,n,0)])/S)/MathLog(n/2);

}

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

{

C=iMAOnArray(H,0,S_EMA,0,MODE_EMA,i);

}

return(0);

}

//-----------------------------------------------------------

 

This part :

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

{

for (int j=0;j<n;j--)

{

for (i=limit-1;0<=i<=j;i--) // you are alrady using "i" variable in in the outer loop

{

double B=0,SUM[]; // Sum is an un-initialized array and shoulde be created out of this loop.

B=B+A;

SUM[j]=B;

}

}

H=MathLog((SUM[ArrayMaximum(SUM,n,0)]-SUM[ArrayMinimum(SUM,n,0)])/S)/MathLog(n/2);

}

Commented where the error is. Without description I can not say what are you trying to achieve wiith that code, so I can not alter it.

chenairbin:
Hi, anybody can help me?I want this kind of indicator about Hurst Exponent. the cod is successly programmed by the compiler, but no image,can you fix it? Thank you!

The values of the Hurst Exponent range between 0 and 1.

* A Hurst Exponent value H close to 0.5 indicates a random walk (a Brownian time series). In a random walk there is no correlation between any element and a future element and there is a 50% probability that future return values will go either up or down. Series of this type are hard to predict.

* A Hurst Exponent value H between 0 and 0.5 exists for time series with "anti-persistent behaviour". This means that an increase will tend to be followed by a decrease (or a decrease will be followed by an increase). This behaviour is sometimes called "mean reversion" which means future values will have a tendency to return to a longer term mean value. The strength of this mean reversion increases as?H?approaches 0.

* A Hurst Exponent value H between 0.5 and 1 indicates "persistent behavior", that is the time series is trending. If there is an increase from time step [t-1] to [t] there will probably be an increase from [t] to [t+1]. The same is true of decreases, where a decrease will tend to follow a decrease. The larger the?Hvalue is, the stronger the trend. Series of this type are easier to predict than series falling in the other two categories.

Calculation is as follows

Step_A、X= MathLog(Close/Close)

{ the value of H from a single R/S

Step1、E = (1/n)*[X(0)+X(1)+X(2)+...+X(n-1) ]

Step2、A(0) = X(0) - E

A(1) = X(1) - E

A(2) = X(2) - E

...

A(n-1) = X(n-1) – E

Step3、SUM(0) = A(0)

SUM(1) = A(0)+ A(1)

SUM(2) = A(0)+A(1) + A(2)

...

SUM(n-1) = A(0)+A(1) + A(2) + ...+ A(n-1)

Step4、R= Maximum(SUM,n) - Minimum(SUM,n)

Step5、H = log(R/S)/log(n/2) // Let?s be the standard deviation of the set of { X(0),X(1), X(2), ... X(n-1)}

}

Step_B、calculate H from the set of { X(i),X(i+1), X(i+2), ... X(i+n-1)}

Step_C、calculate H_SMA, Let it smooth ,if H_SMA=0.5 then alert

cod is as follows

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

//| #HURST.mq4 |

//| chenairbin. |

//| MetaTrader 4 Trading Platform / MetaQuotes Software Corp. |

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

#property copyright "chenairbin."

#property link "http://www.metaquotes.net"

#property indicator_separate_window

#property indicator_minimum 0

#property indicator_maximum 1

#property indicator_buffers 7

#property indicator_color7 Yellow

extern int n=21,S_EMA=8;

extern double Natural=0.5;

double X[],E[],S[],A[],SUM[],H[],C[];

int init()

{

IndicatorBuffers(7);

SetIndexBuffer(0,X);

SetIndexBuffer(1,E);

SetIndexBuffer(2,S);

SetIndexBuffer(3,A);

SetIndexBuffer(4,SUM);

SetIndexBuffer(5,H);

SetIndexStyle(6,DRAW_LINE);

SetIndexBuffer(6,C);

return(0);

}

int start()

{

int i;

int limit;

int counted_bars=IndicatorCounted();

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

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

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

{

X= MathLog(Close/Close);

}

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

{

E=iMAOnArray(X,0,n,0,MODE_EMA,i);

S=iStdDevOnArray(X,0,n,0,MODE_EMA,i);

}

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

{

A=X-E;

}

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

{

for (int j=0;j<n;j--)

{

for (i=limit-1;0<=i<=j;i--)

{

double B=0,SUM[];

B=B+A;

SUM[j]=B;

}

}

H=MathLog((SUM[ArrayMaximum(SUM,n,0)]-SUM[ArrayMinimum(SUM,n,0)])/S)/MathLog(n/2);

}

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

{

C=iMAOnArray(H,0,S_EMA,0,MODE_EMA,i);

}

return(0);

}

//-----------------------------------------------------------