MQL4 Learning - page 50

 
matrixebiz:
Hello, I have an EA that calls an indicator and after a few trades it stops working and I have to close MT4 and re-open for the EA to work again for a few trades then Stops. Any fix for this?

It could be something wrong with the logic that on special case it make never ending loop or other else. Please chek your code.

 

Good advice but also check your journal tab for any errors that might give you a clue to your problem.

Lux

 

Love it!!

ralph.ronnquist:
Adding my thought to this, I agree with the ney-sayers: if the EA's observations bear no correlation with the price movement, then its trades are random, and they stay random also if reversed. In fact, you may improve the logic until your ears go pointy, and the trades still stay random

That statement by Ralph Ronnquist made me spit out my drink and almost choke!! It made my day

Doug

 

Help Edit this EA

friends in the house, help edit the attached ea. i trade cci on 5min tf. i need the ea to be able to work based on the logic shown below.

presently it just open buy or sell around the zero line not minding the direction of trend. it now makes profit from the swing around the zero line and sometimes big loss. other times it open sell instead of buy and vice versa. (this is because it does not wait to count the 6bars according to cci rules)

the logic i found (meant for MT3) which i want coders to assist and code into the ea is

{==Variable Setup}

Var: vCCI(0);vCCI=CCI(14); {Or 20 as you like.}

Var: LSMA(0);LSMA=LinearRegValue(C,25,0);

Var: EMA34(0);EMA34=Xaverage(C,34)

Var: ExitTrail(0),ExitValue(0),ExitReason("None"); {Used for exit}

{==ZLRs Entry}

If 1=1

and vCCI[1]>=0 and vCCI[2]>0 and vCCI[3]>0 and vCCI[4]>0 and vCCI[5]>0 {6 bars Above Zero}

and Highest(vCCI,5)>=100 {Comes from outside 100s -- Also - no chop mode}

and vCCI[1]<100 {Pulled back inside 100s}

and vCCI>vCCI[1] and vCCI[2]>vCCI[1] {Hook}

and vCCI<130 {Not oversold}

and vCCI-vCCI[1]>5 {Strong V -- Optional, adjust as you wish.}

and C>EMA34 and EMA34>EMA34[1] {Close above rising 34EMA}

and C>LSMA and LSMA>LSMA[1] {Close above rising LSMA}

Then Begin

Buy ("ZLR") This Bar at close;

End;

{==1st Hook Exit}

{You will notice that the trailing routine exits at the ExitValue-.0005}

{You can change the .0005 to a higher or lower value to let your trades breathe.}

{You can also change it to exit AT MARKET if you just want to exit at 1st hook immediately.}

If MarketPosition=1 and vCCI<vCCI[1] Then Begin ExitValue=L; ExitTrail=1; ExitReason="Hook"; End;

If vCCI>vCCI[1] then ExitTrail=0; {Hooked back, Turn off, keep going.}

{==Trailing Routine}

If ExitTrail=1 and MarketPosition=1 then sell ("eXit") next bar at ExitValue-.0005 stop;

by interpretation it means, check the following variables, cci up to 6 bars, lsma above or below 25, ema 34 and exit. it is using zero line reject and hook from extreme of cci.

thank you

Files:
framework.mq4  5 kb
 

Moving objects

let's say I have some code that draws some object on the chart (like a rectangle).

Would anyone be able to tell me how to move this object in MQL4?

When the price moves I want the object to move.

Any suggestions?

Thanks

 

After price moved you have to calculate new coordinates for your object and use OrderMove().

 

Thanks so much for the reply.

Do you have any code examples that you could provide. This is greatly appreciated. Thank you

 

Try my script for trailing stops and takes. When you have opened order, grab the script with left button and put on the opened order on the chart exactly.

You will see two lines up and down real price. You can move these lines as you want - these are stop and take. When price touch any of them order will be closed. If trailingline is true you will see as stop line will move to price.

Good luck!

P.S. This is a script, put in \scripts derictiory.

Files:
 
Roger09:
After price moved you have to calculate new coordinates for your object and use OrderMove().

Is there a function in mql to move the order ???

Will test it asap next week

FerruFx

 

I have found this in the money management tread what need to be done to it to make it work in real time.

Any help would be great.

Cheers

Beno

double WinRate()

{

double Ticket;

double CountWins = 0;

for(Ticket=0;Ticket<OrdersTotal();Ticket++)

{

OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY);

if(MyAccount==AccountNumber() && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)

{

//------>>>>

if(OrderType()==OP_BUY)

{

if(OrderClosePrice() >= OrderOpenPrice())

CountWins++;

}

else if(OrderType()==OP_SELL)

{

if(OrderClosePrice() <= OrderOpenPrice())

CountWins++;

}

}

}

if(CountWins > 0)

return(MathRound(CountWins/OrdersHistoryTotal())*10);

else

Print("Real Time WinRate not Available");

return(mWinRate);

}
Reason: