How to code? - page 28

 

Need Simple Code help!

What code can I put in my ea so that it will only trade once on the current bar as a result of 2 moving averages crossing???

I am trading on the one minute and sometimes the bar value can go to the high and then low and then high again. If the ea opens a trade when the 2 moving averages cross, the bar value can go below the cross in the same minute and the ea will exit the trade if the trading value goes low temporarily. As a result the ea can open and close a position on the same one minute bar!! Please advise!!

Thanks in Advance!

Dave

<<<

 

I've had this problem before and here's what I did:

Up at the top where you declare your veriables put

static bool ITradedOnThisBar;

then where you send your order put

if(your critera && ITradedOnThisBar!=Bars)

{

ticket=OrderSend(Symbol(),OP_BUY,... );

ITradedOnThisBar = Bars;

}

Doing This will keep you from opening a trade on the same bar that you already opened a trade on, but more importantly you want to keep it from closing on the same bar so I would also add this code where you close your trade, for example:

if(Your Criteria && ITradedOnThisBar != Bars)

{

OrderClose(OrderTicket(),... ); // close position

}

This is probably the most simple way to do what you are trying to do.

 

Refresh buffers code

there is code (patch, fix, upgrade) by Raff 4 multitimeframe (MTF) indicators, working pretty good;

what could be similar code you can add to regular (not mtf) indicators?

If possible, example, please

thank you

//---- Refresh buffers +++++++++++++++++++++ upgrade by Raff

if (TimeFrame>Period()) {

int PerINT=TimeFrame/Period()+1;

datetime TimeArr[]; ArrayResize(TimeArr,PerINT);

ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period());

for(i=0;i=TimeArray[0]) {

//----

/*****************************************************

Refresh buffers: buffer = buffer[0];

******************************************************/

Buffer1= Buffer1[0];

Buffer2= Buffer2[0];

Buffer3= Buffer3[0];

//----

} } }

//+++++++++++++++++++++++++++++++++++++++++ Raff ++++++

 
Willis11of12:
I've had this problem before and here's what I did:

Up at the top where you declare your veriables put

static bool ITradedOnThisBar;

then where you send your order put

if(your critera && ITradedOnThisBar!=Bars)

{

ticket=OrderSend(Symbol(),OP_BUY,... );

ITradedOnThisBar = Bars;

}

Doing This will keep you from opening a trade on the same bar that you already opened a trade on, but more importantly you want to keep it from closing on the same bar so I would also add this code where you close your trade, for example:

if(Your Criteria && ITradedOnThisBar != Bars)

{

OrderClose(OrderTicket(),... ); // close position

}

This is probably the most simple way to do what you are trying to do.

Thanks for the coding. I have installed it in my ea (hopefully in the right spots), and will find out if it will work once the moving averages cross.

Thanks!

Dave

 

I do not know how to code, but I have made several EA's simillar to what you describe using the expert advisor builder. I'm not sure if thats what you are looking for but you might check it out if you haven't already.

Expert Advisor Builder for MetaTrader 4

 

I will check it out. thanks.

 

Is there such a code ?

I wonder if there is such a code (w/ below description).

What would the basic code be w/ the following parameters ? (w/ an understanding that any indicator w/ a value could be plugged in)

(Opening trades)

1. A long trade is placed when an indicator's current value goes higher than previous bar's close value. (intrabar, not close)

2. A short trade is placed when an indicator's current value goes lower than previous bar's close value. (intrabar, not close)

(Closing trades)

1. Long trades are closed when short trades are opened.

2. Short trades are closed when long trades are opened.

thanks

 

try some of these

Index of /_MT4_Experts

 

Thanks AJK. That is quite a list !

 

code help

i'm sure someone has asked this already but i cannot find it when i search the threads.

i would like to know how to code for an EA to place a trade only when the price is between to levels -I.E.

if (price=>1.0000 && price< 1.0050) sell

Reason: