How to code? - page 321

 
mladen:
dasio

Try something like this :

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 OrangeRed

#property indicator_color2 Silver

#property indicator_width1 2

extern int RsiPeriod = 50;

extern int RsiPrice = PRICE_CLOSE;

double work[];

double avg[];

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

//

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

//

//

//

//

//

int init()

{

SetIndexBuffer(0,work);

SetIndexBuffer(1,avg);

return(0);

}

int start()

{

int i,countedBars = IndicatorCounted();

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

if (countedBars>0) countedBars--;

int limit = MathMin(Bars-countedBars,Bars-1);

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

{

work = iRSI(NULL,0,RsiPeriod,RsiPrice,i);

int y = iBarShift(NULL,PERIOD_D1,Time);

int x = iBarShift(NULL,PERIOD_D1,Time);

if (x!=y)

{

int k = iBarShift(NULL,0,iTime(NULL,PERIOD_D1,y));

double average = work[k];

int c = 1;

for (int j=k-1; j>=i; j--,c++) average += work[j]; average /= c;

for ( j=k ; j>=i; j--) avg[j] = average;

}

}

return(0);

}

Mladen i tried but no success.

Attach there is an example of my indicator. The only differences are in the calculations but the other is the same.

Can you integrate with your formula? so i can also study it.

Thank you

test1.mq4

Files:
test1.mq4  3 kb
 

Hi all. Looking for quick help to write a line of code for a signal.

I am using Step_Indy and an EMA cross for signal. What I want to do is have the EA enter trade only when both give a signal within 10 bars of each other.

So say that the Step gives a signal, I want the EA to look back 10 bars to see if there was a MA cross, if yes enter. (Note I don't want it to just check and see if the MA cross current signal is long, I want it to have been recent like within 10 bars)

TIA for any help, I don't think I have seen this done in the past in any EA's I've looked at.

 

dasio

From the code I can not see what is the intention of the code. Anyway, here is a code in which you can chose if you wish to use the true range as the "basic" value of the indicator (it is the first part of your code) or you wish to use the second part of your code as the "basic" value

dasio:
Mladen i tried but no success.

Attach there is an example of my indicator. The only differences are in the calculations but the other is the same.

Can you integrate with your formula? so i can also study it.

Thank you

test1.mq4
Files:
_test1.mq4  2 kb
 

Signal Problems

Mladen, thank you once again, the alert no more repeating, working fine.....but i want to put a stop sgnal.....and I wrote the following code,the buy and sell signal works but the buy stop and sell stop is not working, see the code below:

//-----Assigning Alarts----

if(Period()==240){

static datetime lastAlerted=0;

double ist_main=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_MAIN,0);

double ist_signal=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_SIGNAL,0);

double RSIP1=iRSI(NULL,240,14,PRICE_CLOSE,0);

double RSIP2=iRSI(NULL,240,70,PRICE_CLOSE,0);

double b4enCCI=iCCI(NULL,240,6,PRICE_TYPICAL,1);

double nowenCCI=iCCI(NULL,240,6,PRICE_TYPICAL,0);

double b4trCCI=iCCI(NULL,240,14,PRICE_TYPICAL,1);

double nowtrCCI=iCCI(NULL,240,14,PRICE_TYPICAL,0);

// Trade alerts

if((adx_h4>=20)&&(di_p_h4>=20)&&(di_p_h4>di_m_h4)&&(ist_main>ist_signal)&&(RSIP1>RSIP2)&&(nowenCCI>0&&nowenCCI>b4enCCI)&&(nowtrCCI>0&&nowtrCCI>b4trCCI)&&(lastAlerted!=Time[0]))

{

lastAlerted=Time[0];

Alert("Buy","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

if((adx_h4>=20)&&(di_m_h4>=20)&&(di_m_h4>di_p_h4)&&(ist_main<ist_signal)&&(RSIP1<RSIP2)&&(nowenCCI<0&&nowenCCI<b4enCCI)&&(nowtrCCI<0&&nowtrCCI<b4trCCI)&&(lastAlerted!=Time[0]))

{

lastAlerted=Time[0];

Alert("Sell","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

// Stop alerts

if((adx_h4>=20)&&(di_p_h4>=20)&&(di_p_h4>di_m_h4)&&(ist_mainRSIP2)&&(nowenCCI>0&&nowenCCI>b4enCCI)&&(nowtrCCI>0&&nowtrCCI>b4trCCI)||(adx_h4>=20)&&(di_p_h4>=20)&&(di_p_h4>di_m_h4)&&(ist_main>ist_signal)&&(RSIP10&&nowenCCI>b4enCCI)&&(nowtrCCI>0&&nowtrCCI>b4trCCI)||(adx_h4>=20)&&(di_p_h4>=20)&&(di_p_h4>di_m_h4)&&(ist_main>ist_signal)&&(RSIP1>RSIP2)&&(nowenCCI<0&&nowenCCI0&&nowtrCCI>b4trCCI)||(adx_h4>=20)&&(di_p_h4>=20)&&(di_p_h4>di_m_h4)&&(ist_main>ist_signal)&&(RSIP1>RSIP2)&&(nowenCCI>0&&nowenCCI>b4enCCI)&&(nowtrCCI<0&&nowtrCCI<b4trCCI)&&(lastAlerted!=Time[0]))

{

lastAlerted=Time[0];

Alert("Stop Buy","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

if((adx_h4>=20)&&(di_m_h4>=20)&&(di_p_h4ist_signal)&&(RSIP1<RSIP2)&&(nowenCCI<0&&nowenCCI<b4enCCI)&&(nowtrCCI<0&&nowtrCCI=20)&&(di_m_h4>=20)&&(di_p_h4<di_m_h4)&&(ist_mainRSIP2)&&(nowenCCI<0&&nowenCCI<b4enCCI)&&(nowtrCCI<0&&nowtrCCI=20)&&(di_m_h4>=20)&&(di_p_h4<di_m_h4)&&(ist_main<ist_signal)&&(RSIP10&&nowenCCI>b4enCCI)&&(nowtrCCI<0&&nowtrCCI=20)&&(di_m_h4>=20)&&(di_p_h4<di_m_h4)&&(ist_main<ist_signal)&&(RSIP1<RSIP2)&&(nowenCCI<0&&nowenCCI0&&nowtrCCI>b4trCCI)&&(lastAlerted!=Time[0]))

{

lastAlerted=Time[0];

Alert(" Stop Sell","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

mladen:
Try like this :
if(Period()==240)

{

static datetime lastAlerted=0;

double ist_main=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_MAIN,0);

double ist_signal=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_SIGNAL,0);

double RSIP1=iRSI(NULL,240,14,PRICE_CLOSE,0);

double RSIP2=iRSI(NULL,240,70,PRICE_CLOSE,0);

double b4enCCI=iCCI(NULL,240,6,PRICE_TYPICAL,1);

double nowenCCI=iCCI(NULL,240,6,PRICE_TYPICAL,0);

double b4trCCI=iCCI(NULL,240,14,PRICE_TYPICAL,1);

double nowtrCCI=iCCI(NULL,240,14,PRICE_TYPICAL,0);

// alerts

if((ist_main>ist_signal)&&(RSIP1>RSIP2)&&(nowenCCI >0&&nowenCCI>b4enCCI)&&(nowtrCCI>0&&nowtrCCI>b4trCCI)&&(lastAlerted!=Time[0]))

{

lastAlerted=Time[0]; Alert("Buy Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

if((ist_main<ist_signal)&&(RSIP1<RSIP2)&&(nowenCCI <0&&nowenCCI<b4enCCI)&&(nowtrCCI<0&&nowtrCCI<b4trCCI)&&(lastAlerted!=Time[0]))

{

lastAlerted=Time[0]; Alert("Sell Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

}
 
mladen:
dasio From the code I can not see what is the intention of the code. Anyway, here is a code in which you can chose if you wish to use the true range as the "basic" value of the indicator (it is the first part of your code) or you wish to use the second part of your code as the "basic" value

Thank you mladen.

I Know calculated in this way there isn't sense. But i'm try to code an analisys that i do every day. ^^

It is only 1/3 of the job.

Thank you

 
mladen:
dasio From the code I can not see what is the intention of the code. Anyway, here is a code in which you can chose if you wish to use the true range as the "basic" value of the indicator (it is the first part of your code) or you wish to use the second part of your code as the "basic" value

Thank you, it is perfect.

It is possible to add the friday fix?

Thank you

Regards

 

Volume

i want to query the volume of each bar but i don't have a clue how to go about it i am new to mql4 programming but trying to learn i have tried this simple program but it may be complete rubbish, please let me know, and any suggestions would be appreiciated. below is the start of the script to query the volume of a bar then print the result, please let me know where I am going wrong!!!! keep trying to compile there is one error which says (end of program ending bracket } expected.

//--- input parameters

extern double TakeProfit = 4;

extern double StopLoss = 20;

extern double Lots = 0.1;

extern double TrailingStop = 30;

extern double volumemore = 600;

extern double volumeless = 150;

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

//| expert initialization function |

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

int start()

{

if (Volume=>volumemore)

{

Print ("volume more");

{

if (Volume=<volumeless)

{

Print ("volume less");

if(Bars<20)

{

Print("bars less than 20");

{

//----

//----

return (0);

}

 

Use Volume where "index" is the number if the bar you want to see the volume for. Just remeber that in metatrader 4 the "Volume" is always tick volume

Tim Latham:
i want to query the volume of each bar but i don't have a clue how to go about it i am new to mql4 programming but trying to learn i have tried this simple program but it may be complete rubbish, please let me know, and any suggestions would be appreiciated. below is the start of the script to query the volume of a bar then print the result, please let me know where I am going wrong!!!! keep trying to compile there is one error which says (end of program ending bracket } expected.

//--- input parameters

extern double TakeProfit = 4;

extern double StopLoss = 20;

extern double Lots = 0.1;

extern double TrailingStop = 30;

extern double volumemore = 600;

extern double volumeless = 150;

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

//| expert initialization function |

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

int start()

{

if (Volume=>volumemore)

{

Print ("volume more");

{

if (Volume=<volumeless)

{

Print ("volume less");

if(Bars<20)

{

Print("bars less than 20");

{

//----

//----

return (0);

}
 
jayjonbeach:
Hi all. Looking for quick help to write a line of code for a signal.

I am using Step_Indy and an EMA cross for signal. What I want to do is have the EA enter trade only when both give a signal within 10 bars of each other.

So say that the Step gives a signal, I want the EA to look back 10 bars to see if there was a MA cross, if yes enter. (Note I don't want it to just check and see if the MA cross current signal is long, I want it to have been recent like within 10 bars)

TIA for any help, I don't think I have seen this done in the past in any EA's I've looked at.

Well I tried a couple things, but so far nothing has worked.

Here is one of the ways I tried this:

extern int lookback = 10;

extern int EMA1 = 21;

extern int EMA2 = 55;

int GetEntrySignal()

{

int trendCurr = iCustom(NULL,StepMaTimeFrame,"StepMA_v7",Length,Kv,StepSize,MA_Mode,Advance,Percentage,UpDownShift,HighLow,ColorMode,5,StepMaBarToTest );

int trendPrev = iCustom(NULL,StepMaTimeFrame,"StepMA_v7",Length,Kv,StepSize,MA_Mode,Advance,Percentage,UpDownShift,HighLow,ColorMode,5,StepMaBarToTest+1);

double TwentyOneEMA = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,1);

double FiftyFiveEMA = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,1);

if(TwentyOneEMA > FiftyFiveEMA)

{

if (trendCurr>0)

{

for(int i=1; i<=Bars-lookback; i++)

{

if (trendCurr<0)

return(LONG);

else return(NONE);

}

}

}

if(TwentyOneEMA < FiftyFiveEMA)

{

if (trendCurr<0)

{

for(int i2=1; i2<=Bars-lookback; i2++)

{

if (trendCurr>0)

return(SHORT);

else return(NONE);

}

}

}

return(NONE);

}

Any ideas appreciated, I also tried (int i=1; i<=lookback; i++)

 

...

jayjonbeach,

You are testing the value of trendCurr over and over in the loop without changing it (so it will always return NONE)

Try putting the iCustom() in the loop and then test that value. Something like this :

if (trendCurr>0)

{

for(int i=1; i<=lookback; i++)

{

int testValue = iCustom(NULL,StepMaTimeFrame,"StepMA_v7",Length,Kv,StepSize,MA_Mode,Advance,Percentage,UpDownShift,HighLow,ColorMode,5,StepMaBarToTest+i);

if (testValue<0) return(LONG);

}

return(NONE);

}

jayjonbeach:
Well I tried a couple things, but so far nothing has worked.

Here is one of the ways I tried this:

extern int lookback = 10;

extern int EMA1 = 21;

extern int EMA2 = 55;

int GetEntrySignal()

{

int trendCurr = iCustom(NULL,StepMaTimeFrame,"StepMA_v7",Length,Kv,StepSize,MA_Mode,Advance,Percentage,UpDownShift,HighLow,ColorMode,5,StepMaBarToTest);

int trendPrev = iCustom(NULL,StepMaTimeFrame,"StepMA_v7",Length,Kv,StepSize,MA_Mode,Advance,Percentage,UpDownShift,HighLow,ColorMode,5,StepMaBarToTest+1);

double TwentyOneEMA = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,1);

double FiftyFiveEMA = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,1);

if(TwentyOneEMA > FiftyFiveEMA)

{

if (trendCurr>0)

{

for(int i=1; i<=Bars-lookback; i++)

{

if (trendCurr<0)

return(LONG);

else return(NONE);

}

}

}

if(TwentyOneEMA < FiftyFiveEMA)

{

if (trendCurr<0)

{

for(int i2=1; i2<=Bars-lookback; i2++)

{

if (trendCurr>0)

return(SHORT);

else return(NONE);

}

}

}

return(NONE);

}

Any ideas appreciated
Reason: