Coding help - page 239

 

Hi,

i have modified the standard stepMA 9 indicator into this one in separate window as histogram but i don't know why buy signals are not sinchronized with the standard indicator (sell signals are). With the new one they occurs one bar back than the original indicator. Why? I have modified only the part of code that determine the graphic aspect of the indicator.

stepma_9_histo_mtf.mq4

stepma_9.0.mq4

Files:
 
thefxpros:
Hi,

i have modified the standard stepMA 9 indicator into this one in separate window as histogram but i don't know why buy signals are not sinchronized with the standard indicator (sell signals are). With the new one they occurs one bar back than the original indicator. Why? I have modified only the part of code that determine the graphic aspect of the indicator.

stepma_9_histo_mtf.mq4

stepma_9.0.mq4

thefxpros

That is a result of how lines are drawn.

When you draw a line you have to start to draw the line 1 bars back in order to make it visible (otherwise it would be a point and it would not be visible on the chart at all). Try these two and compare them now

Files:
 

Hi,

I have been searching for an EA that would open a trade in a similar way as a trailing stop would work.

Let's say I am waiting for a retracement on an instrument. I would want to open my trade as high (or low) on the price as possible. So with an EA like this, I would be able to set my trade parameters and this EA will keep following the price in a similar way as to a trailing stop. When there is a reversal, the trade is hit and opened.

Have you ever seen such an EA?

Thanks

 

Hi All

i try made code, but why can't open trade

int varCurrentTime = TimeCurrent();

for (int iTS = 0; iTS < 2000; iTS++) {

int varZonStart = StrToTime(TimeToStr(varCurrentTime, TIME_DATE) + " " + "00:00");

int varZonEnd = StrToTime(TimeToStr(varCurrentTime, TIME_DATE) + " " + "10:00");

int JamStart=TimeHour(varZonStart);

int JamEnd=TimeHour(varZonEnd);

if (JamStart>JamEnd) {

varCurrentTime = decDateTradeDay(varCurrentTime);

//if (TimeDayOfWeek(varCurTime) < 1) varCurTime = decDateTradeDay(varCurTime);

if (TimeDayOfWeek(varCurrentTime) > 5) varCurrentTime = decDateTradeDay(varCurrentTime);

}

varZonStart = StrToTime(TimeToStr(varCurrentTime, TIME_DATE) + " " + "00:00");

int varShiftStart = iBarShift(NULL, 0, varZonStart - 60 * Period());

int varShiftEnd = iBarShift(NULL, 0, varZonEnd);

varHighest = High;

varLowest = Low;

varCurrentTime = decDateTradeDay(varCurrentTime); //set 1 hari kebelakang

if (TimeDayOfWeek(varCurrentTime) < 1) varCurrentTime = decDateTradeDay(varCurrentTime); //jika minggu mundur lagi

if (TimeDayOfWeek(varCurrentTime) > 5) varCurrentTime = decDateTradeDay(varCurrentTime); //jika sabtu mundur lagi

}

for (int iTSh = 0; iTSh < 2000; iTSh++) {

for (int iTSl = 0; iTSl < 2000; iTSl++) {

if(((varHighest-varLowest)/Pip)<=5) varHL=(varHighest+varLowest)/2;

}

}

double isg10a = iOpen(Symbol(),PERIOD_M15,1);

double isg10b = iClose(Symbol(),PERIOD_M15,1);

int static isg10c = -1;

for (iTS = 0; iTS < 2000; iTS++) {

if(isg10avarHL)isg10c =0;

if(isg10a>varHL&&isg10b<varHL)isg10c =1;

}

if (isg10c==0) To code Buy

else if (isg10c==1) To code Sel

else no trade

 
mladen:
Jim Instead of rewriting the whole thing added a limit to calculate bars and then all those bars are recalculated. That should solve the refreshing problem (juts keep the BarsTocalculate at some reasonable - not too big not too small value. I used 1000 as a default and it seems to be OK like that). Try it out

Dear mladen,

many many thanks for your effort and your very quick help.

I will try out.

Much greatings from Munich

 

Please help me upgrade this volume indicator to attach on my mt4

Hello gurus please kindly help me fix the errors in this volume indicator. I just noticed it unable to attached to my mt4 chart recently. I have done everything possible to fix the errors in the file but to no avail. I suspect it is because of the huge mt4 upgrade. Every other indicator on my mt4 folder both older/newer versions are all working fine. It was working a year ago I last used it. i am not a programmer yet.

Please find attached file

 

Hi MLaden and Mrtools,

I hope you're fine

I need a confirmation of you about the RSX

I see that you use a more simple formula to calculate the RSX :

__________________________

double Kg = (3.0)/(2.0+Length);

double Hg = 1.0-Kg;

if (slope[limit]==-1) CleanPoint(limit,rsxDa,rsxDb);

if (ArrayRange(wrkBuffer,0) != Bars) ArrayResize(wrkBuffer,Bars);

for(i=limit, r=Bars-i-1; i>=0; i--, r++)

{

wrkBuffer[r][12] = iMA(NULL,0,1,0,MODE_SMA,Price,i);

if (i==(Bars-1)) { for (int c=0; c<12; c++) wrkBuffer[r][c] = 0; continue; }

//

//

//

//

//

double mom = wrkBuffer[r][12]-wrkBuffer[r-1][12];

double moa = MathAbs(mom);

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

{

int kk = k*2;

wrkBuffer[r][kk+0] = Kg*mom + Hg*wrkBuffer[r-1][kk+0];

wrkBuffer[r][kk+1] = Kg*wrkBuffer[r][kk+0] + Hg*wrkBuffer[r-1][kk+1]; mom = 1.5*wrkBuffer[r][kk+0] - 0.5 * wrkBuffer[r][kk+1];

wrkBuffer[r][kk+6] = Kg*moa + Hg*wrkBuffer[r-1][kk+6];

wrkBuffer[r][kk+7] = Kg*wrkBuffer[r][kk+6] + Hg*wrkBuffer[r-1][kk+7]; moa = 1.5*wrkBuffer[r][kk+6] - 0.5 * wrkBuffer[r][kk+7];

}

if (moa != 0)

rsx = MathMax(MathMin((mom/moa+1.0)*50.0,100.00),0.00);

else rsx = 50;

____________________________________

Just to be sure to understand how the RSX is calculated with this formula

First with the line:

mom = wrkBuffer[r][12]-wrkBuffer[r-1][12];

in fact wrkBuffer[r][12] is the simple moving average of the price, note the prise as with a usual RSI ?

Right ? But I don't understand which is the period of this SMA (Probably not Length)?

And after, if I have well understand with the lines:

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

{

int kk = k*2;

wrkBuffer[r][kk+0] = Kg*mom + Hg*wrkBuffer[r-1][kk+0];

wrkBuffer[r][kk+1] = Kg*wrkBuffer[r][kk+0] + Hg*wrkBuffer[r-1][kk+1];

mom = 1.5*wrkBuffer[r][kk+0] - 0.5 * wrkBuffer[r][kk+1];

In fact it calculates 3 times the mom (one after the other), with the first mom above (mom = wrkBuffer[r][12]-wrkBuffer[r-1][12];)

Is it right ?

And after this is "classic" with RSX=((mom/moa)+1)*50

Thank you for your next answer, as a coder (on another plateform), you know I like to understand how the codes work

Have a beautiful day

Zilliq

 
zilliq:
Hi MLaden and Mrtools,

I hope you're fine

I need a confirmation of you about the RSX

I see that you use a more simple formula to calculate the RSX :

__________________________

double Kg = (3.0)/(2.0+Length);

double Hg = 1.0-Kg;

if (slope[limit]==-1) CleanPoint(limit,rsxDa,rsxDb);

if (ArrayRange(wrkBuffer,0) != Bars) ArrayResize(wrkBuffer,Bars);

for(i=limit, r=Bars-i-1; i>=0; i--, r++)

{

wrkBuffer[r][12] = iMA(NULL,0,1,0,MODE_SMA,Price,i);

if (i==(Bars-1)) { for (int c=0; c<12; c++) wrkBuffer[r][c] = 0; continue; }

//

//

//

//

//

double mom = wrkBuffer[r][12]-wrkBuffer[r-1][12];

double moa = MathAbs(mom);

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

{

int kk = k*2;

wrkBuffer[r][kk+0] = Kg*mom + Hg*wrkBuffer[r-1][kk+0];

wrkBuffer[r][kk+1] = Kg*wrkBuffer[r][kk+0] + Hg*wrkBuffer[r-1][kk+1]; mom = 1.5*wrkBuffer[r][kk+0] - 0.5 * wrkBuffer[r][kk+1];

wrkBuffer[r][kk+6] = Kg*moa + Hg*wrkBuffer[r-1][kk+6];

wrkBuffer[r][kk+7] = Kg*wrkBuffer[r][kk+6] + Hg*wrkBuffer[r-1][kk+7]; moa = 1.5*wrkBuffer[r][kk+6] - 0.5 * wrkBuffer[r][kk+7];

}

if (moa != 0)

rsx = MathMax(MathMin((mom/moa+1.0)*50.0,100.00),0.00);

else rsx = 50;

____________________________________

Just to be sure to understand how the RSX is calculated with this formula

First with the line:

mom = wrkBuffer[r][12]-wrkBuffer[r-1][12];

in fact wrkBuffer[r][12] is the simple moving average of the price, note the prise as with a usual RSI ?

Right ? But I don't understand which is the period of this SMA (Probably not Length)?

And after, if I have well understand with the lines:

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

{

int kk = k*2;

wrkBuffer[r][kk+0] = Kg*mom + Hg*wrkBuffer[r-1][kk+0];

wrkBuffer[r][kk+1] = Kg*wrkBuffer[r][kk+0] + Hg*wrkBuffer[r-1][kk+1];

mom = 1.5*wrkBuffer[r][kk+0] - 0.5 * wrkBuffer[r][kk+1];

In fact it calculates 3 times the mom (one after the other), with the first mom above (mom = wrkBuffer[r][12]-wrkBuffer[r-1][12];)

Is it right ?

And after this is "classic" with RSX=((mom/moa)+1)*50

Thank you for your next answer, as a coder (on another plateform), you know I like to understand how the codes work

Have a beautiful day

Zilliq

"in fact wrkBuffer[r][12] is the simple moving average of the price, note the prise as with a usual RSI ?"

No. The calculating period for that average is 1, which means that it is equal to the price of the "average" used. In metatader that is the fastest way to get the desired price (if you try to write the "case" structure doing that same thing you will see that it is much slower than the way used in the rsx code)

"In fact it calculates 3 times the mom (one after the other), with the first mom above"

No. See what values it is using in each and every new iteration. mom and moa are constantly changed and reused (in that changed form) during the looping process

 

Thanks a lot Mladen,

It's very strange, if I have well understand wrkBuffer[r][12] is equal to the price, but you use a moving average with a period of 1 to accelerate the calcul. That's so curious...

For the second thing, I think/suppose that is what I try to say

it calculate the mom as a momentum of price

And it calculates another mom with Kg and Hg. It gives a new mom, who is used to created a new mom, and so on, 3 times

Something "easier" (to facilitate the undestanding) like that

mom

mom1=kg*mom

mom2=kg*mom1

mom3=kg*mom2

And at the end it uses mom3, and moa3

I am right ?

 
zilliq:
Thanks a lot Mladen,

It's very strange, if I have well understand wrkBuffer[r][12] is equal to the price, but you use a moving average with a period of 1 to accelerate the calcul. That's so curious...

For the second thing, I think/suppose that is what I try to say

it calculate the mom as a momentum of price

And it calculates another mom with Kg and Hg. It gives a new mom, who is used to created a new mom, and so on, 3 times

Something "easier" (to facilitate the undestanding) like that

mom

mom1=kg*mom

mom2=kg*mom1

mom3=kg*mom2

And at the end it uses mom3, and moa3

I am right ?

Zilliq,

yes, that is how it is done

Reason: