MNB 10.4 Streamlined by Snailbeard

Post Reply
nonlinear
Trader
Posts: 293
Joined: Fri Jun 01, 2012 2:56 pm
Location: Washington DC

Re: MNB 10.4 Streamlined by Snailbeard

Post by nonlinear »

I will give her a try, Brian. Thanks. Did you add anything to try to reduce the DD - does not look like it at first glance, but I know you were looking at using CSS differently.

After I loaded it up, the EA placed two sell stops, but they do not line up with the pivots.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Re: MNB 10.4 Streamlined by Snailbeard

Post by snailbeard »

Just come across a couple of bugs in some code inherited from an earlier EA, if anyone is running these EAs they should be aware that occassionally this code does spurious things!

In fact, you don't have to run it to spot several issues, most modern development environments would actually catch these and generate warnings.

If this code is called every tick then it is particularly wasteful on CPU as well!

Those of you who have seen my earlier bug reports might remember that I reported an oversized lotsize on a number of occasions - which is why you shouldn't run experimental EA's on real accounts!

Code: Select all

//+------------------------------------------------------------------+
//| expert Get Next Support function
//+------------------------------------------------------------------+
double GetNextSupport(string symbol) {
	double bidPrice = MarketInfo(symbol, MODE_BID);
	double digits   = MarketInfo(symbol, MODE_DIGITS);

	RefreshRates();
	double pivot;
	double bot = 0;

	if	( UseSR2 )
		bot = MS2;
	if	( UseMidSR2)
		bot = S1;
	if	( UseSR1 )
		bot = MS1;

	for (int cc = 0; cc <= ArraySize(Pivots); cc++) {
		if (bidPrice > Pivots[cc] && bidPrice < Pivots[cc + 1] &&  bidPrice > bot) {
			pivot = NormalizeDouble(Pivots[cc], digits);

			if ((bidPrice - pivot ) < (MinimumToNextSR / PFactor(symbol)))
				pivot = NormalizeDouble(Pivots[cc - 1], digits);

			return(pivot);
		}
	}
}
In the past I've used examples like this to assess job applicants.
nonlinear
Trader
Posts: 293
Joined: Fri Jun 01, 2012 2:56 pm
Location: Washington DC

Re: MNB 10.4 Streamlined by Snailbeard

Post by nonlinear »

Is the bug in the below code?
snailbeard wrote:Just come across a couple of bugs in some code inherited from an earlier EA, if anyone is running these EAs they should be aware that occassionally this code does spurious things!

In fact, you don't have to run it to spot several issues, most modern development environments would actually catch these and generate warnings.

If this code is called every tick then it is particularly wasteful on CPU as well!

Those of you who have seen my earlier bug reports might remember that I reported an oversized lotsize on a number of occasions - which is why you shouldn't run experimental EA's on real accounts!

Code: Select all

//+------------------------------------------------------------------+
//| expert Get Next Support function
//+------------------------------------------------------------------+
double GetNextSupport(string symbol) {
	double bidPrice = MarketInfo(symbol, MODE_BID);
	double digits   = MarketInfo(symbol, MODE_DIGITS);

	RefreshRates();
	double pivot;
	double bot = 0;

	if	( UseSR2 )
		bot = MS2;
	if	( UseMidSR2)
		bot = S1;
	if	( UseSR1 )
		bot = MS1;

	for (int cc = 0; cc <= ArraySize(Pivots); cc++) {
		if (bidPrice > Pivots[cc] && bidPrice < Pivots[cc + 1] &&  bidPrice > bot) {
			pivot = NormalizeDouble(Pivots[cc], digits);

			if ((bidPrice - pivot ) < (MinimumToNextSR / PFactor(symbol)))
				pivot = NormalizeDouble(Pivots[cc - 1], digits);

			return(pivot);
		}
	}
}
In the past I've used examples like this to assess job applicants.
nonlinear
Trader
Posts: 293
Joined: Fri Jun 01, 2012 2:56 pm
Location: Washington DC

Re: MNB 10.4 Streamlined by Snailbeard

Post by nonlinear »

Here is the common error I receive: 2013.06.11 09:00:02 bwa_MNB10Streamlined EURUSD,H4: Alert: USDCHFgetLots() gave a lot size larger than lotAlertSize: SLPts: 80.00000, TickValue: 1.07564, Exposure: 86.05111\nFreeMargin: 50350.23000, riskPercent: 2.00000, AllowedExposure: 503.50230\nreduceLotsize:: lotBuff: 35.00000, reduceRiskPercent: 1.00000, AllowedExposure: 503.50230\nCalculated size: 5.85000, lotAlertSize: 0.90000, Reset to Min: 0.10000
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Re: MNB 10.4 Streamlined by Snailbeard

Post by snailbeard »

nonlinear wrote:Is the bug in the above code?
There are (more than one).

I have rewritten my version
a) trap errors
b) cache calculations
c) reorder for performance
c) log errors

And what if I want to do similar calculations on other pivot time frames:
so generalised and abstracted as well:

Code: Select all

double GetNextResistance(int pairIndex, double& aPivots[][], double highestPivot, double minPipsToNextSR, double& pivotStop, bool& bPriceBeyondPivots )
{
    double pivot = 0;
    int iBadIndex = 0;
    int nextIndex = 0;
    int nextNextIndex = 0;
    int prevIndex = 0;
    double dHighestPivot = highestPivot;
    string strReport;
    bool bTraceAll = false;
        
    RefreshRates();
    double askPrice = MarketInfo(Pairs[pairIndex], MODE_ASK); // changes every tick
    double digits   = MarketInfo(Pairs[pairIndex], MODE_DIGITS); // this could be cached

    pivotStop = 0;

    double pfOnce = PFactorFast(pairIndex); // use cached value
    double dMinGapToNextPivot = minPipsToNextSR / pfOnce;

    bPriceBeyondPivots = false;

    if( dHighestPivot <= EPSILON  )
        bPriceBeyondPivots = true;
    else if ( dHighestPivot > aPivots[pairIndex][MAXPIVOTLINES-1] )
        bPriceBeyondPivots = true;
        
    if( bPriceBeyondPivots == true )
    {
        strReport = "GetNextResistance() - bad value for dHighestPivot : " + DoubleToStr(dHighestPivot,5) + " ";
        strReport = "or bad value for pivot : " + DoubleToStr(aPivots[pairIndex][MAXPIVOTLINES-1],5) + " ";
        Print(strReport);
    }
    
    if( askPrice >= dHighestPivot ) 
        bPriceBeyondPivots = true;
        
    static datetime testdate = D'2013.01.27 22:00';
    if(IsTesting() && testdate ==  iTime(Pairs[pairIndex], PERIOD_H1, 0) )
    {
        strReport = "Trace GetNextResistance() at : " + TimeToStr(testdate) + ", "; 
        strReport = strReport + "askPrice : " + DoubleToStr(askPrice, 5) + ", " ;
        strReport =strReport + "dHighestPivot : " + DoubleToStr(dHighestPivot, 5) + ", " ;
        Print(strReport);
    }
        
    if( bPriceBeyondPivots == false )
    {
        int iPivotArraySize = MAXPIVOTLINES;
        for (int cc = 0; cc < iPivotArraySize; cc++)
        {
            nextIndex = cc+1;
            nextNextIndex = cc+2;
            if( nextIndex >= iPivotArraySize ) iBadIndex = nextIndex;
            if( iBadIndex != 0 )
            {
                bPriceBeyondPivots = true;
                break;
            }
            if (askPrice > aPivots[pairIndex][cc] && askPrice < aPivots[pairIndex][nextIndex] )
            {
                pivot = NormalizeDouble(aPivots[pairIndex][nextIndex], digits);
                pivotStop = NormalizeDouble(aPivots[pairIndex][cc], digits);

                if ( (pivot - askPrice) < dMinGapToNextPivot)
                {
                    if( nextNextIndex >= iPivotArraySize ) 
                    {
                        bPriceBeyondPivots = true;
                        iBadIndex = nextNextIndex;
                        break;
                    } else {
                        pivot = NormalizeDouble(aPivots[pairIndex][nextNextIndex], digits);
                        pivotStop = NormalizeDouble(aPivots[pairIndex][nextIndex], digits);
                    }
                }
                return(pivot);
            }
        }
        bool bReportMissingPivots = true;
        if( bReportMissingPivots )
        {
            Print(Pairs[pairIndex] + "askPrice:  " + DoubleToStr(askPrice, 5)  + " :- GetNextResistance() not found...");
            Print("top price: " + DoubleToStr(dHighestPivot, 5)  + ", iPivotArraySize: " + iPivotArraySize);
            if( iBadIndex != 0 ) Print( "Ran out of pivots:   caught array index error: " + iBadIndex);
        }
    }
    return(0);
}
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Re: MNB 10.4 Streamlined by Snailbeard

Post by snailbeard »

nonlinear wrote:Here is the common error I receive: 2013.06.11 09:00:02 bwa_MNB10Streamlined EURUSD,H4: Alert: USDCHFgetLots() gave a lot size larger than lotAlertSize: SLPts: 80.00000, TickValue: 1.07564, Exposure: 86.05111\nFreeMargin: 50350.23000, riskPercent: 2.00000, AllowedExposure: 503.50230\nreduceLotsize:: lotBuff: 35.00000, reduceRiskPercent: 1.00000, AllowedExposure: 503.50230\nCalculated size: 5.85000, lotAlertSize: 0.90000, Reset to Min: 0.10000
Yes thats one of the side effects of the bugs.
trader689
Trader
Posts: 674
Joined: Thu Nov 17, 2011 12:53 am

Re: MNB 10.4 Streamlined by Snailbeard

Post by trader689 »

just a quick update, my demo of 10.4 streamlined running OOTB is generating no bugs so far, and trading exceedingly well with very little drawdown.
its also been a good couple of weeks for my OOTB 2.01a and 2.01b (andy version) demos, (although those had more initial drawdown) so lets see what happens.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Re: MNB 10.4 Streamlined by Snailbeard

Post by snailbeard »

The final update to this EA is available in case it is useful to anyone.

It will produce plenty of trades some good and some which will hit the stop loss.
Sometimes the stop loss makes a good entry point for a real trade :D

To manually select trades look at D1, H4 and H1 Bollinger Bands:
price crossing mid bollinger at a SR can often be a good sign for that direction
or price moving back towards opposite Bollinger from outer Bollinger at SR.
Best trades when the Bollinger is obviously sloping in the right direction.
For a very strong trend candles might be riding the outside of the Bollinger.
Worst trades if Bollinger is obviously sloping opposite to trade direction.
theforexedge
Trader
Posts: 220
Joined: Thu Apr 26, 2012 10:31 pm
Location: Torquay

Re: MNB 10.4 Streamlined by Snailbeard

Post by theforexedge »

Brian

Thanks for coding this revision, it's been trading on my demo account this week and behaving very well so far..! Can I PM you for the update or will you post in the thread..?

Thanks, Jason
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Re: MNB 10.4 Streamlined by Snailbeard

Post by snailbeard »

theforexedge wrote:Brian

Thanks for coding this revision, it's been trading on my demo account this week and behaving very well so far..! Can I PM you for the update or will you post in the thread..?

Thanks, Jason
I have uploaded the updated version.

Also just a reminder that you can better results by running different settings for different pairs or changing them when the pair changes behaviour, the idea of the streamlined version is that you can have more copies running on one PC before things grind to a halt.

In back test USDJPY did much better when I used WSR1 instead of WSR2.
So it was a 'curve fitting' back test and recently USDJPY has been hitting WSR3 and recent 350+ pip retracement! Big retracements have caused multiple losses in earlier versions of the EA.
The EA pivot code doesn't have any pivots in this range anyway so it goes quiet.
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Nanningbob 10.x”