EA_based Trailing Stop - page 5

 

Hi dave0,

I moved your post to this thread.

Just look at the thread because, if I remember - 1 or 2 similar EA was posted here (for trailing stop).

It is not same with your request but it can be modified in your way - hope some coders will help you.

 

Thank you, hopefully someone will be able to help me.

Basically I am after something that can close a trade when 2 MA's cross on a given timeframe, rather than trailing a stop based on 1 MA.

thanks again.

dave.

 

Hi I've come up with something that seems to do the trick:

int Checkcross()

{

double fastNow, fastBack, slowNow , slowBack;

fastNow = iMA(Symbol(), TIMEframe , fast , fast.now , fast.method , fast.price , 0);

slowNow = iMA(Symbol(),TIMEframe , slow , slow.now , slow.method , slow.price , 0);

fastBack = iMA(Symbol(), TIMEframe , fast , fast.now , fast.method , fast.price , 1);

slowBack = iMA(Symbol(),TIMEframe , slow , slow.now , slow.method , slow.price , 1);

if(fastBack < slowBack){

Comment("fast WAS LESS last bar than Slow \nUsing timeframe ", TIMEframe);

if( fastNow > slowNow ){ return(1); }

}

else if(fastBack > slowBack)

{Comment("fast WAS GREATER last bar than Slow \nUsing timeframe ", TIMEframe);

if(fastNow < slowNow ){ return(1);}

}

else {return(0);}

}

Could someone have a look at the code and confirm if this is the right way to go about it? it seems to be working in the strategy tester window.

thanks!

dave.

 

Dave

If you are looking for a way to determine if the cross is happening on a current bar, replace this part

if(fastBack < slowBack){

Comment("fast WAS LESS last bar than Slow \nUsing timeframe ", TIMEframe);

if( fastNow > slowNow ){ return(1); }

}

else if(fastBack > slowBack)

{Comment("fast WAS GREATER last bar than Slow \nUsing timeframe ", TIMEframe);

if(fastNow < slowNow ){ return(1);}

}

else {return(0);}

}

[/php]with this

if ((fastNow-slowNow)*(fastBack-slowBack)<0)

return(1); // crossing now

else return(0); // no crossing

If you want it to return the type of cross, then it gets a bit more complicated

[php]if ((fastNow-SlowNow)*(fastBack-slowBack)<0)

if (fastNow>SlowNow)

return( 1); // fast crossing slow up

else return(-1); // fast crossing slow down

else return( 0); // no crossing

 

that's a more intelligent way of doing it!

 

I'm Confused About Leverage

Hey everyone,

I'm just learning about FOREX and while I was reading I couldn't understand something about leverage.

Let's say I open a micro account with $1,500 and I have a leverage of about 1:100. My account would have $150,000, right?

Now using this example from Trading Forex: How to Make Money in Forex Currency Trading

-You open one lot (100,000), buying with the British pound at 1% margin and wait for the exchange rate to climb. When you buy one lot (100,000) of GBP/USD at a price of 1.5000, you are buying 100,000 pounds, which is worth US$150,000 (100,000 units of GBP * 1.50 (exchange rate with USD)). If the margin requirement was 1%, then US$1500 would be set aside in your account to open up the trade (US$150,000 * 1%). You now control 100,000 pounds with US$1500. Your predictions come true and you decide to sell.

-You close the position at 1.5050. You earn 50 pips or about $500. (A pip is the smallest price movement available in a currency).

Say I make that trade and profit $500 dollars, how does this translate into what I actually have? Because it seems very unlikely that I would make $500 on my initial $1,500 investment.

Thanks for the help!

 

Simple Exit EA for MT4

Hi all

Does anyone know of a MT4 EA which just simply exits all positions on an individual currency pair if 2 moving averages cross? (No entries needed, just an exit).

That's it! I thought there would be a high demand for such a trailing stop method but the more I try to find one online the more I realise perhaps no-one uses such a thing?!?!

Any pointers would be gratefully received!!

Thanks

 

Try UniversalMACross EA - For Exit On Cross

OlisFX:
Hi all

Does anyone know of a MT4 EA which just simply exits all positions on an individual currency pair if 2 moving averages cross? (No entries needed, just an exit).

That's it! I thought there would be a high demand for such a trailing stop method but the more I try to find one online the more I realise perhaps no-one uses such a thing?!?!

Any pointers would be gratefully received!! Thanks

Hi OlisFx,

You can start with - UniversalMACross EA... this has the "Exit On Cross" function and nice modular coding to learn from.

There are also many other "Exit On Cross" EA examples you can find with a TSD search.

Hope this helps,

Robert

 
mladen:
An update of the EMATrailingStop EA

__________________________

Changes :
It can monitor all the symbols or just the symbol it is attached to. If TrailAllSymbolsoption set to true it will trail all the symbols (regardless of the symbol it is attached to - you can freely jump between symbols, it will not change the way it is working), if set to false, it will trail only the symbol it is attached to

It can monitor stopLoss less EAs. With magicNumber.from and magicNumber.to you "regulate" which magic numbers should it trail (magic number 0 are usually only manual trades, so if you include 0 it will monitor and trail manual trades along with chosen magic numbers)

It can close monitored trades when certain profit is reached. When CloseWhenProfitis set to > 0, it starts "profit monitoring" and if the total profit for trades it takes care of exceeds CloseWhenProfitit will close all those trades

It can trail trades that are "in profit" or every trade. if TrailOnlyInProfitis set to true, it will trail only those trades that are already in positive profit, otherwise it will traill all the trades

__________________________

One more new feature is the regulated with the showMessagesoption : if set to true it will show messages like those on the right lower side of the picture (as you can see you do not have to be at the chart where you symbols of interest are), otherwise messages are going to be redirected to journal tab

Rest of the parameters did not change and they have the same meaning as in previous version.

__________________________

Of versions : there are no versions 1.1, 1.2 or 1.3 (at least public versions of it) Those were internal versions used by newdigital and me when testing this EA. So the versions existing are v1 and v1.4

Dear Mladen,

I like your updated EA, really nice..

Would you mind to make one variant of this EA by using Envelope?

Upper Envelope acts as Trailing SL for Sell Order & Lower Envelope acts as Trailing SL for Buy Order..

Thanks in advance

 

Trail Only in Profit

Hi all!

First of thank you for this wonderful EA.

Just a quick question, for the "trailonlyinprofit" does it activate when the ema crosses the entry point? or when pips are in a positive?

As you can see from my screenshot, im 32 pips in profit, but the trailing stop has not moved even once.

My settings for the EA are:

TrailAllSymbols: False

TrailOnlyInProfit: True

CloseWhenInProfit: 0.0

showMessages: True

EmaTimeFrame:0

Price:0

EmaPeriod:40

EmaShift:0

InitialStop:20

My enter my entries manually. Any insight and help would be great.

Thank you all,

Danielyg

Files:
screenshot.jpg  214 kb
Reason: