[WIP] Cowabunga MT4 Expert Advisor

Hello there,
I’m trying to write the code in order to create a “Cowabunga Expert Advisor” for MetaTrader 4 platform. Starting from the indicator i found here - Cowabunga.mq4 - (sorry, I don’t remember the author) I wrote some functions, defined the buy and sell market enters, and for simplicity for now the program closes a position when you are gaining or loosing 20 pips (obviously this is not the Cowabunga system, but I want to test the first part of the code for now).
I’ve tried to test the advisor into MT but it seems not working as expected, you can download the file CowabungaEA.mq4 and verify it on your own: it opens a lot of positions and closing them immediatly, and NOT when the original Cowabunga indicator shows the arrow signal. I made some mistakes (I’m not an expert programmer)! :smiley:

If someone that can do the work could help me… It would be useful for many of us, I think :slight_smile:

Glad to see someone is working on an EA. Maybe someone can help fill in the gaps to make it work. Good-Luck :slight_smile:

That’s what I hope. Sorry but I’m not really good programming, I’m doing my best to do this stuff work, but I need a help…

Well those lines of a Billion > < == %% || statements makes its almost impossible to comprehend what is going on. I also prefer to make seperate functions to control the program, instead of lumping everything in the start().

for instance you could do something like

int stochCross(double stoch1, double stoch2)
{
   static int direction = 0;
   static int new_direction = 0;
   
   if(stoch 1> stoch2)
       direciton = 1;
   if(stoch 1 < stoch 2)
       direciton = -1;

   if(direction != new_direction)
   {
        new_direction = direction;
        return(new_direction);
    }
return(0);
}

From there in start just reference:
signal = stochCross(stoch1, stoch2);
then from there something like
if(signal == 1)
placeorder;
etc.
makes for less messy code, and code that people can read. Also eliminates the need for current_stoch and previous_stoch.

Hello Eight, thank you for the reply!
You are right, the code will be more readable with some sub-funcions, I will re-write all the stuff soon; for the moment I’ve corrected a lot of stupid errors I made before and now it seems to be working as expected (regarding the market-entry section).

Stay tuned. :slight_smile:

we are waiting impatiently:rolleyes: :eek:
is it going to take foever???/:confused:

New version released: CowabungaEAv4.mq4

I’ve fixed a lot of errors regarding the “open orders” part, now it should enter the market correctly; HOWEVER, backtesting it with MetaTrader and looking at the “playback” chart with the Cowabunga indicator put on it, the strange thing is that the expert takes very few trades (you can verufy that looking at the “Total Trades” value into the report): I should now understand if this is due to a tester imprecision or a mistake I’ve done into the code (I’m propending for the first hypotesis).

As you can see from the picture below, from the backtesting it seems that something doesn’t work. In effect, I’m still wondering how to code correctly the exit-from-the-market part. Actually, the expert close a buy position when (alternatively):

  1. Bid is lower than a “StopLoss” value, calculated as the minimum value between a fixed number of bars(1) (the number is stored into a variable called “Shift”); however for testing purposes I’ve introduced a “MaxStop” variable that stores the maximum numbers of pips you can loose (see the code for more information);
  2. We have reached a certain number of pips profit, stored into the “Profit” variable;

Now I’m going to test the Cowabunga expert live with the MetaTrader demo account to see if it enters the market correctly when the Cowabunga indicator displays the arrows; after that we should thake care of the exit problem. If you can help someway, please do that! :slight_smile:

Notes:

(1) As you know, the stop loss into the Cowabunga system is fixed to the most recent low or high “swing” (regarding a long or short position respectively); however, I’m having some throubles coding this swing into MetaTrader language. For the moment is assumed that it is the minimum (or maximum) value between a certain number of bars, but I’m pretty sure this is incorrect.


I read the cowabunga system about the 5EMA 10EM ,MACD histogram and the res does it now mean you don’t need the pivot point stuff and all other indicators like hammer ,marubuzos,spinning tops and the rest 4 ur trading

Thanks men, I will try it right away and will contact you shortly.:):wink:

cheers

my advice to you at this point is that you dont use one indicator independently to place your trades, you need confirmatory signals from other indicators… i.e if you are trading a live account, you dont want to make mistakes.:cool:

If you adhere strictly to the cowabunga system (no sentiments or discretion), you may not have problems with entering a good trade but you need confirmatory indicators like resistance/support/pivot lines to get maximum profit and guide to exiting trades.:stuck_out_tongue:

happy trading

I have back tested it… doesnt look good:eek: and it has not been able to place any trade today… you still have a lot of work to do.:slight_smile:
You may check out these forums for indicators/EA maybe it may help you out.

Buy and sell signal - Forex Trading | MetaTrader Indicators and Expert Advisors
StrategyBuilderFX
Trading Systems @ Forex Factory
Unbelievable NO-LOSS EA - Forex Trading | MetaTrader Indicators and Expert Advisors

There were no Cowabunga signals today…

You said that there were no cowabunga signals but with the mechanical cowabunga system I was able to pick up 274 pips yesterday and 108 pips today trading GBP/JPY:rolleyes::rolleyes: check out this thread for the post.
Happy viewing
http://forums.babypips.com/free-forex-trading-systems/6736-almighty-gbp-jpy-versus-cowabunga-system.html

You may have noticed in other Cowabunga threads that I have recently successfully re-programmed the Cowabunga MT4 Indicator (from which Kepler based his Expert Advisor).

The main problem with the original Cowabunga.MT4 was that it didn’t handle MACD properly. It is important to realise that in MT4 the MACD Histogram value comes from the iOsMA function (OsMA indicator) not from the iMACD function / indicator.

Cowabunga only observes the MACD Histogram value, not the value of the MACD lines, so iMACD is useless to Cowabunga. The iMACD function gives the value of the second MACD line (known as the signal line in MT4, it is the MA of the 1st MACD line), it is not the Histogram. The Histogram value should be the difference between the two lines. All this confusion arose because the makers of MT4 decided that in the MACD indicator they would present the first MACD line as a histogram and leave of the real MACD Histogram altogether. Their logic appears to have been that if you want the MACD Histogram use the OsMA indicator (or iOsMA function). They know what they are doing but it seems to have confused everybody else.

Check out my discussion of all this and my updated Cowabunga indicator in the other two Cowabunga threads, make sure you look at the latest version which is “Cowabunga- Any Pair.MT4”.

Regarding the expert advisor, it is probably just a a case of replacing all iMACD with iOsMA in the code. If I get time I’ll also try to have a look at your code and help.

Kepler, maybe between us we can get a really groovy Cowabunga EA and get some profitable back testing results.

Kepler, Well done for all your great work so far. I hope you are still watching this thread.

Regards,

Pipalot :slight_smile:

Dear Kepler (and Tegasite),

In fact there was a Cowabunga signal on 25th September 2007 at 10.45am British Summer Time (9.45am GMT, or 5.45am EST whichever you prefer).

You maybe didn’t see it if you were using MACD instead of OsMA (the MACD Histogram).

See also PipSurfer’s blog for that day, he saw the same signal, unfortunately he lost 40 pips on it!

Regards,

Pipalot

Dear pipalot,
unfortunately I’m very busy in this period so I can’t work on the EA. Thank you for the precious suggestion, I’m still following the thread but as I said at the moment I have really a little amount of time.

OK Kepler,

Thanks for your reply. If I get time to look at the code of your EA then I’ll keep you posted with any updates that I make / results etc.

Kind regards,

Pipalot :slight_smile:

Thank you for your help! :slight_smile:

COWABUNGA EA CONSIDERATIONS

I got interested in Cowabunga in my search for better entry systems for an automated trader.
These are my observations, thoughts and improvements to the EA.

  1. WHAT we are doing is more important than HOW to code this or that aspect. We must always come back to this.
    WHAT am I doing with this EA?
    I am trying to help code the EA EXACTLY as Big Pippin does it.

  2. To really code what Big Pippin is doing, you need to study his blog.
    He lays out his rules (in ‘Read this First’ - find it in the blog) but you also have to look carefully at what he DOES, as the rules are not always precisely stated.
    I have observed that unless - perhaps - a trader has a strong math/science type background, his statement of the rules is likely to be “in the ballpark”, but not precise enough to code and get good results.

For example, Big Pippin does not necessarily trade on the same bar as an MA cross, or the next bar.
So, for how many bars after each timeframe’s cross is a trade valid?
That is the kind of rule that can be coded and a computer can follow.
On the 4 Hour chart he takes the trend as EMA 5 above (or below) the EMA 10, for many bars after the cross, essentially until the re-cross.
But on the M15 chart he usually trades soon after the MA cross. I have set it up for 5 bars, but you can experiment, changing the variable ‘MaxMACrossShift’ in the Strategy Tester, “Expert Properties” screen. I have not reviewed all of Big Pippin’s blog to find what is the value that 90 or 95% of his trades fall within, (4 bars? 10 bars?) so I eyeballed a bunch and started with 5.

  1. A bar’s time is the OPEN time. For backtesting, the close of the current bar is not usable, I believe because it is already known to the program when the bar opens: but you can use the OPEN of the current bar, and for consistency, prior bars. OR use Closes up to the previous bar.
    It would be interesting to backtest two versions AFTER all else is correct, to compare using OPENs up to the current bar (shifts of 0 and 1), to the present code which has closes of the previous two bars (shifts of 1 and 2). the differences would not be great I think, but we could be surprised.

CODING SPECIFICS:

  1. Solved: Not taking trades. Because of coding logic: it only took a trade ON the 4 Hour crossover bar, but Big Pippin actually considers the Main trend as when (for long) the 5 EMA is above the 10 EMA. This is true for many bars at a stretch.

  2. Need to use Metatrader’s OSMA, not MACD, to match Big Pippin’s charts. Kept this.

  3. Added code to prevent a trade opening on the same bar as a close of trade. Avoids unprofitable mess

  4. I setup Profit and Maxstop in pips instead of decimals, for ease of use.

  5. Added a MinStop to always give the price some “wiggle room”.
    Setting MaxStop to 500 and MinStop to 0 effectively nullifies them.
    MaxStop and MinStop would ideally not be there if all Big Pippin’s rules are coded, and work well.

  6. Corrected coding errors in the exits (*Point).

  7. Recoded the initial stoploss calculations to occur before order entry. Orders should have stops in case your connection fails.

  8. Changed some of the logic to more closely match what Big Pippin does.

WORK NEEDED TO BE DONE

Add Money management. I prefer simple code based on Larry William’s system. This is to keep you out if the stop is too wide, per Big Pippin.

Exits. Code the exits as Big Pippin describes and shows. A TakeProfit of 20 or 30 is not what the doctor ordered.
And also code the “exit by 4 PM.”

Close trades before news events.

I hope someone else can tackle this.
Many of these are contained in EA’s at ForexTSD. (I read a lot at ForexTSD.)

Testing! If you find some consistently profitable settings let us know!


FINAL THOUGHTS

I do not ever expect a perfect match between the EA and Big Pippin’s trades. A 2/3 correlation would be quite good.

WARNING: Even if profitable this program is not safe to trade with real money as it does not have sufficient error handling, etc.

Final Point: I repeat:
WHAT we are doing is more important than HOW to code this or that aspect. We must always come back to this.
WHAT am I doing with this EA?
I am trying to help code the EA EXACTLY as Big Pippin does it.
(That will also give us a reference to try changes and compare to the ‘pure’ Cowabunga system.)

Let us know what you find out with it!

Big Be,

Nice to see your still working on this. Just a couple thoughts. The advisor runs fairly slowly in backtesting.

You are checking your 4H and 15Min info with every tick. The 4H info really doesn’t change that often and I believe that doing this manually you would probably only check after a new 4H bar has come out.

Big Pippin only opens trades on the close of a bar. With the expert advisor, it is easiest to do this on the first tick of the next bar(as I believe you have talked about). Again, while manually trading this system one would watch for the signals, if they happen in the middle of a bar, wait until the end in order to ensure that it is not a fake out. But in an automated system we need to simply check on the first tick of the bar if the previous bar’s close values give us the signal. If you limit all your logic to the first tick in a bar, things will run faster and be more accurate to the system.

I too am working on an EA for this, but I am as of yet unwilling to release my source code. My backtesting shows the system opening positions when the indicator says to, but I am still loosing money. I won’t release a loosing EA.