stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Multi 10:4 Trader EA
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1619
Page 10 of 160
Author:  jiaxingx [ Fri Mar 15, 2013 11:01 am ]
Post subject:  Re: Multi 10:4 Trader EA

I think that the function GetNextResistance() can be replaced..

Code: Select all


double GetNextResistance(string symbol) {
	double askPrice = MarketInfo(symbol, MODE_ASK);
	double bidPrice = MarketInfo(symbol, MODE_BID);
	double digits   = MarketInfo(symbol, MODE_DIGITS);
	
	RefreshRates();
	double pivot;

	for (int cc = 0; cc < ArraySize(Pivots); cc++) {
		if (bidPrice > Pivots[cc] && bidPrice < Pivots[cc + 1]) {
			pivot = NormalizeDouble(Pivots[cc + 1], digits);
			
			if (MathAbs(bidPrice - pivot) < (MinimumToNextSR / PFactor(symbol)))
				pivot = NormalizeDouble(Pivots[cc + 2], digits);
	
			return(pivot);
			
		} 
	}    
}


Author:  SteveHopwood [ Fri Mar 15, 2013 11:02 am ]
Post subject:  Re: Multi 10:4 Trader EA

Global Prime demos do not have everything needed by EA's turned on by default. Go into Tools/Options/Expert advisors; make sure all the left side boxes are ticked and none of the right side boxes are ticked.

:D
Author:  slipshod [ Fri Mar 15, 2013 11:21 am ]
Post subject:  Re: Multi 10:4 Trader EA

MrLong, the CalculateTakeProfit and CalculateStopLoss functions both assume that the entry will be made at market, which means that they are capable of setting SL & TP values on the wrong side of the true entry.

I've made a few changes to the code and the erroneous errors are gone & TP/SL values seem more sensible to my untutored eye, but I'm not that familiar with 10.4 and for all I know I could be breaking its logic. Would you prefer I post the changes here, send them in a PM or would you rather think it through on your end?
Author:  MrLong [ Fri Mar 15, 2013 11:31 am ]
Post subject:  Re: Multi 10:4 Trader EA

slipshod wrote:MrLong, the CalculateTakeProfit and CalculateStopLoss functions both assume that the entry will be made at market, which means that they are capable of setting SL & TP values on the wrong side of the true entry.

I've made a few changes to the code and the erroneous errors are gone & TP/SL values seem more sensible to my untutored eye, but I'm not that familiar with 10.4 and for all I know I could be breaking its logic. Would you prefer I post the changes here, send them in a PM or would you rather think it through on your end?

Hi,

Yes please post them here, then others can learn also.

Thanks
Andy
Author:  slipshod [ Fri Mar 15, 2013 11:54 am ]
Post subject:  Re: Multi 10:4 Trader EA

Ok I'll get everything together in the next post.

Before I do though, I noticed that while I've had it running today, 3 buys have been made at different times at market, and then instantly closed (same timestamp on the exit as the entry) with a popup message saying that sellers have entered the market. Together these have taken $50 out of a $10k demo account.
Author:  MrLong [ Fri Mar 15, 2013 12:03 pm ]
Post subject:  Re: Multi 10:4 Trader EA

slipshod wrote:Ok I'll get everything together in the next post.

Before I do though, I noticed that while I've had it running today, 3 buys have been made at different times at market, and then instantly closed (same timestamp on the exit as the entry) with a popup message saying that sellers have entered the market. Together these have taken $50 out of a $10k demo account.

Yes, I was looking for a way of exiting a trade when the market changes and tried the correlated pairs.

You can swith this off with:

extern bool closeWhenMarketReverse =true;
Author:  slipshod [ Fri Mar 15, 2013 12:07 pm ]
Post subject:  Re: Multi 10:4 Trader EA

Here's the changes I made on my end, hope they're useful! If there's anything incorrect or that could have been done better please let me know :)

firstly there's changes to function calls in start()...

Code: Select all

stop = CalculateStopLoss(CurrentPair, OP_BUY, price);
take = CalculateTakeProfit(CurrentPair, OP_BUY, price);
Do the same for sells as well, with OP_SELL of course. Now for the functions themselves:-

Code: Select all

double CalculateStopLoss(string symbol, int type, double entry) {
        // askPrice and bidPrice no longer needed as we're using the real entry value
	// double askPrice = MarketInfo(symbol, MODE_ASK);
	// double bidPrice = MarketInfo(symbol, MODE_BID);
	double stop, price = entry;

	RefreshRates();

	if (type == OP_BUY) {
		//price = askPrice;
		if (!CloseEnough(stopLoss, 0)) {
			stop = price - (stopLoss / factor);
		}

		
		if (UseMovingAverage)
			stop = MaVal;
	} 

	if (type == OP_SELL) {
		//price = bidPrice;
		if (!CloseEnough(stopLoss, 0)) {
			stop = price + (stopLoss / factor);
		}

		
		if (UseMovingAverage)
			stop = MaVal;
	} 

	return(stop);
} 

double CalculateTakeProfit(string symbol, int type, double entry) {
	// again, no need for askPrice and bidPrice anymore
	//double askPrice = MarketInfo(symbol, MODE_ASK);
	//double bidPrice = MarketInfo(symbol, MODE_BID);
	double take, price = entry;

	RefreshRates();

	if (type == OP_BUY) {
                // make sure that take is incorrect to start with, that way we can be sure when
                // we get a valid take value...
		take = entry - 20 * Point;

		if (!CloseEnough(takeProfit, 0)) {
			take = price + (takeProfit / factor);
		}
		
                // note that below I set take to higher resistance levels even if the Use flag for them
                // hasn't been set, but only if the desired resistance level is below our entry...
		if (UseMidSR1)
			take = MR1;
		if (UseSR1 || take < entry)
			take = R1;
		if (UseMidSR2 || take < entry)
			take = MR2;
		if (UseSR2 || take < entry)
			take = R2;
		if (take < entry)
                {
                        // still can't get a valid take value using the pivots, so I've defaulted
                        // to 2 * ATR as a placeholder to ensure we have something to use.
                        take = entry + iATR(symbol, PERIOD_H4, 20, 0)*2;
                }
	} 

	if (type == OP_SELL) {
		take = entry + 20 * Point;

		if (!CloseEnough(takeProfit, 0)) {
			take = price - (takeProfit / factor);
		}
		
		if (UseMidSR1)
			take = MS1;
		if (UseSR1 || take > entry)
			take = S1;
		if (UseMidSR2 || take > entry)
			take = MS2;
		if (UseSR2 || take > entry)
			take = S2;
		if (take > entry)
		   take = entry - iATR(symbol, PERIOD_H4, 20, 0)*2;
	}

	return(take);
}
Btw another change I've made is to split the lotsize in half and enter twice, once with a TP and once without (I'll trail the market with the second order). I don't know if this is valid under 10.4 rules or would improve or harm its profitability, but its something I wanted to try. Its a simple change, can post it if anyone wants ... if it does prove useful perhaps its something Andy could add an option for in a future version?
Author:  slipshod [ Fri Mar 15, 2013 12:12 pm ]
Post subject:  Re: Multi 10:4 Trader EA

MrLong wrote:Yes, I was looking for a way of exiting a trade when the market changes and tried the correlated pairs.

You can swith this off with:

extern bool closeWhenMarketReverse =true;
Do you mean false? true is its default value & is what was set.

It seemed odd actually that it'd enter these orders in the first place, mid-candle and at market, with the price barely moving. Every other trade the EA makes seems to be a pending order so it seemed out of place.

Edit: Another thing while I think of it. The EA was running at a pretty high rate on my CPU, so I added a Sleep(100) at the end of the start() function, which dropped it dramatically.
Author:  websie [ Fri Mar 15, 2013 12:17 pm ]
Post subject:  Re: Multi 10:4 Trader EA

I know absolutely nothing about coding but when looking at this EA this bit here about the time of deleting the pendings you have set for 16.00 which is 4pm, was it really meant to be 6pm, in which case it's 18.
Is that correct to change the 16 to 18?
extern int PendingTradeDeletionHour = 16; //6.00 pm
Author:  roje [ Fri Mar 15, 2013 12:20 pm ]
Post subject:  Re: Multi 10:4 Trader EA

Is it working parameter MinimumPipsToNextSR ? Several minutes ago EA opened AUDCAD too early, though i set 10 pips. Should I set 100 when i have 5 digits broker ?
All times are UTC Page 10 of 160