Multi 10:4 Trader EA

Post Reply
MrLong

Re: Multi 10:4 Trader EA

Post by MrLong »

slipshod wrote:Hi Andy, if its ok I'll add some code below (will edit this post when done) as a tide-over until you're back & can do the job properly. Don't worry mate, enjoy your holiday - we'll keep the fires burning until you're back :)

Edit: Ok firstly you'll need to add the following to the EA's code up the top - in v1.09 its at line 83 under the // candletiger comment.

Code: Select all

extern bool   useAO = true;
extern bool   useStoch = true;
extern bool   useRSI = true;
Leave UseRSIInsteadOfStoch there, as it'll be used for dashboard display purposes - but no longer for the actual trading.

Then line 2310-ish you'll see the function trendDirect() replace it with the following:-

Code: Select all

bool trendDirect(string symbol, int type)
{
    double mA   = iMA(symbol, PERIOD_H4, 240, 0, MODE_LWMA, PRICE_OPEN, 0);
    double sT   = iStochastic(symbol, PERIOD_H4, 5, 3, 3, MODE_LWMA, 1, MODE_SIGNAL, 0);
    double aO   = GetAo(symbol, PERIOD_H4, 0);
    double aO1  = GetAo(symbol, PERIOD_H4, 1);
    double lO   = iLow(symbol, PERIOD_H4, 0);
    double hO   = iHigh(symbol, PERIOD_H4, 0);
    double gRSI = GetSlopeRSI(symbol, PERIOD_H4, 0);

    if (useStoch)
    {
       if (type == OP_BUY)
       {
           if (useBothForPullback)
           {
               if (lO > mA && sT < 20 && aO < 0 && aO1 < aO)
                   return(true);
           }
           else if (lO > mA && sT < 20)
               return(true);
       }

       if (type == OP_SELL)
       {
           if (useBothForPullback)
           {
               if (hO < mA && sT > 80 && aO > 0 && aO1 > aO)
                   return(true);
           }
           else if (hO < mA && sT > 80)
               return(true);
       }
    }

    if (useRSI)
    {
        if (type == OP_BUY)
        {
            if (useBothForPullback)
            {
                if (lO > mA && gRSI < RSITMAlowlevel && aO < 0 && aO1 < aO)
                    return(true);
            }
            else if (lO > mA && gRSI < RSITMAlowlevel)
                return(true);
        }

        if (type == OP_SELL)
        {
            if (useBothForPullback)
            {
                if (hO < mA && gRSI > RSITMAhighlevel && aO > 0 && aO1 > aO)
                    return(true);
            }
            else if (hO < mA && gRSI > RSITMAhighlevel)
                return(true);
        }
    }

    if (useAO)
    {
        if (type == OP_BUY && lO > mA && aO < 0 && aO1 < aO)
            return(true);
        else if (type == OP_SELL && hO < mA && aO > 0 && aO1 > aO)
            return(true);
    }

    return(false);
}
A few things to note:-

Its not a choice whether to use Stoch or RSI. You can use both or either. Just make sure one of them at least is set to true.

Awesome Oscillator is used as a confirming measure for Stoch/RSI trades if you set useBothForPullback to true, or as an entry in its own right if you set useAO to true. Set both those to false and it won't be used at all. The AO needs to be in positive territory for a sell trade or negative for a buy trade, and it now needs to have moved closer to the other direction than the previous H4 candle as that's how I read Bob's rule in the manual.

Lastly if I've stuffed something up here by all means don't hesitate to point it out!

Edit: improved the logic a bit, separating out the useAO parts from the useStoch and useRSI. Should work exactly the same.
Hi slipshod,

I was just looking though the code and cannot see the benefit of only being able to open an order in a 4H time envelope. While crossing the zero line.

If price continued, the EA would not be able to place orders after the first 4 Hour period of
crossing the zero line if using the AO as an order.

What's your opinion?

Thanks for all your help in this thread.

Andy
User avatar
droland
Trader
Posts: 52
Joined: Tue Nov 15, 2011 9:40 pm
Location: Vancouver, BC, Canada

Re: Multi 10:4 Trader EA

Post by droland »

mobthehop wrote:slipshot,
thanks for all your bug hunting and corrections....
If you do not mind me saying,
Its not a choice whether to use Stoch or RSI. You can use both or either.
does not comply with the 10.4 either, it should be either/or and SH expressed his preference for RSI....

As Stoch and RSI are defined as variables, would it not make more sense to set only one of them as external boolean and when set to false, the other is considered true (eg external bool RSI = true, if set to false, Stoch will be applied without being an external)

Just a thought, not a criticism...

Mop

PS: Thank you very much for your pending order script - use it all day long....
I sorted and read through all Slipshods posts and couldn't find the pending order script. Would you or Slipshod mind posting it again.
Thank you
User avatar
slipshod
Trader
Posts: 404
Joined: Tue Dec 27, 2011 9:14 am
Location: Australia

Re: Multi 10:4 Trader EA

Post by slipshod »

MrLong wrote:I was just looking though the code and cannot see the benefit of only being able to open an order in a 4H time envelope. While crossing the zero line.

If price continued, the EA would not be able to place orders after the first 4 Hour period of
crossing the zero line if using the AO as an order.

What's your opinion?

Thanks for all your help in this thread.
Hi Andy, the changes I made don't assume a cross of the zero line. For a long entry, the AO must still be in negative territory, but less negative than it was the previous candle, and vice versa for shorts as per the rule in the manual screenshot you posted earlier:-

Best case Buy Scenario
AO below its zero line
AO's bar has turned green (this happens when its higher than the previous candle's AO bar).

In actual fact my implementation was a bit loose - it'll accept a buy entry on any AO green bar, whereas reading it again that word "turned" implies that the previous bar was red.
mobthehop wrote:
slipshod wrote:Its not a choice whether to use Stoch or RSI. You can use both or either.
does not comply with the 10.4 either, it should be either/or and SH expressed his preference for RSI....

As Stoch and RSI are defined as variables, would it not make more sense to set only one of them as external boolean and when set to false, the other is considered true (eg external bool RSI = true, if set to false, Stoch will be applied without being an external)
That's what the useRSIInsteadOfStoch setting implies, but the logic of the coding used Stoch and AO all the time anyway, with RSI being used only if those other two didn't trigger an entry. My change allows the user to explicitly state what combination of the three methods are used - can easily just set Stoch to false and RSI to true or vice versa, but yes it doesn't force an either-or choice.

To do that, useStoch and useRSI could be dropped (keep useAO though) and in trendDirect() useStoch could be replaced with !useRSIInsteadOfStoch, and useRSI replaced with useRSIInsteadOfStoch - pretty straightforward. I'll leave Andy to decide which way he wants to go with this when he returns from his well-earned break ... which probably consists of sneakily snatching half an hour here & there through the day to check this forum on his iPad :D

Edit: Here's a version of trendDirect with the above changes for both UseRSIInsteadOfStoch and AO...

Code: Select all

bool trendDirect(string symbol, int type)
{
    double mA   = iMA(symbol, PERIOD_H4, 240, 0, MODE_LWMA, PRICE_OPEN, 0);
    double sT   = iStochastic(symbol, PERIOD_H4, 5, 3, 3, MODE_LWMA, 1, MODE_SIGNAL, 0);
    double aO   = GetAo(symbol, PERIOD_H4, 0);
    double aO1  = GetAo(symbol, PERIOD_H4, 1);
    double aO2  = GetAo(symbol, PERIOD_H4, 2);
    bool aObuy = (aO < 0 && aO > aO1 && aO1 < aO2);
    bool aOsell = (aO > 0 && aO < aO1 && aO1 < aO2);
    double lO   = iLow(symbol, PERIOD_H4, 0);
    double hO   = iHigh(symbol, PERIOD_H4, 0);
    double gRSI = GetSlopeRSI(symbol, PERIOD_H4, 0);

    if (!UseRSIInsteadOfStoch)
    {
       if (type == OP_BUY)
       {
           if (useBothForPullback)
           {
               if (lO > mA && sT < 20 && aObuy)
                   return(true);
           }
           else if (lO > mA && sT < 20)
               return(true);
       }

       if (type == OP_SELL)
       {
           if (useBothForPullback)
           {
               if (hO < mA && sT > 80 && aOsell)
                   return(true);
           }
           else if (hO < mA && sT > 80)
               return(true);
       }
    }
    else
    {
        if (type == OP_BUY)
        {
            if (useBothForPullback)
            {
                if (lO > mA && gRSI < RSITMAlowlevel && aObuy)
                    return(true);
            }
            else if (lO > mA && gRSI < RSITMAlowlevel)
                return(true);
        }

        if (type == OP_SELL)
        {
            if (useBothForPullback)
            {
                if (hO < mA && gRSI > RSITMAhighlevel && aOsell)
                    return(true);
            }
            else if (hO < mA && gRSI > RSITMAhighlevel)
                return(true);
        }
    }

    if (useAO)
    {
        if (type == OP_BUY && lO > mA && aObuy)
            return(true);
        else if (type == OP_SELL && hO < mA && aOsell)
            return(true);
    }

    return(false);
}
Btw I can't for the life of me remember a Pending order script! I must be getting old and/or severely lacking in my coffee intake. I use some drag-drop scripts for moving SLs and TPs (there's several like that on mql4.com) but nothing for pendings that I recall :|
Last edited by slipshod on Wed Apr 03, 2013 10:28 pm, edited 1 time in total.
forextradingemails

Re: Multi 10:4 Trader EA

Post by forextradingemails »

tried 1.09 on demo and real. massive differences! real -£27 demo +£125. Really whats the difference? Demo alpari real FXCM. Although that being said real is slowly clawing back was -£30 yesterday
SWG123
Trader
Posts: 565
Joined: Wed Nov 16, 2011 3:02 pm
Location: Cape Town

Re: Multi 10:4 Trader EA

Post by SWG123 »

Is this a possible bug? I have a second buy trade opened on UCHF, both with magic numbers attributed to Multi 10.4, but only the first one appears in the dashboard.
uchf h4 10.4 130403.gif
uchf open trades.GIF
EDIT: Have refreshed grid, changed TFs, no change.
You do not have the required permissions to view the files attached to this post.
User avatar
slipshod
Trader
Posts: 404
Joined: Tue Dec 27, 2011 9:14 am
Location: Australia

Re: Multi 10:4 Trader EA

Post by slipshod »

SWG the dashboard's not always updating - switch timeframes & it should show the correct trades.

Edit: If that fails try restarting Empty4. If that fails ... I'm scratching my head :)
linuspoon
Trader
Posts: 23
Joined: Fri Sep 14, 2012 5:52 am

Re: Multi 10:4 Trader EA

Post by linuspoon »

simplex wrote:Hi Linus,

I never faced this error - neither on my development machine nor on test.

Can you provide ANY information about the circumstances this error occurs? Only on EA startup? On every tick? After trade open? After trade close? ... etc. The more detail you can provide the better. Already did a code review, found nothing ...

Cheers, simplex
This error only occurs in one of my demo Empty4 but not on another one. The error occurs once the EA starts. On every tick (may not be every tick but there are a number of errors within 1 min interval), the same error will appear in the Expert tab one line after another continuously until either I stopped the EA or change the GridMethod to 1 or if I set showDisplay to false.

Linus
MrLong

Re: Multi 10:4 Trader EA

Post by MrLong »

SWG123 wrote:Is this a possible bug? I have a second buy trade opened on UCHF, both with magic numbers attributed to Multi 10.4, but only the first one appears in the dashboard.
uchf h4 10.4 130403.gif
uchf open trades.GIF
EDIT: Have refreshed grid, changed TFs, no change.
Hi,

Are the magic numbers the same?
User avatar
Pinbar
Posts: 5
Joined: Mon Apr 01, 2013 11:40 pm
Location: Way South of London

Empty4 ...

Post by Pinbar »

slipshod wrote:SWG the dashboard's not always updating - switch timeframes & it should show the correct trades.

Edit: If that fails try restarting Empty4. If that fails ... I'm scratching my head :)
If that fails ... Delete Empty4 log files & possible other trash within directories (careful) ...
If that fails ... Delete ex4, modify mq4, recompile all code involved ...
If that fails ... All of the above, but this time also hard code your settings before F5 & restarting Empty4 ...
If that fails ... Download a new Empty4 instance (Bob had to!) and move all MQ4 there ... (a fresh start)!
If that fails ... Call it a day (any ideas?)

Shooting Star
MrLong

Re: Multi 10:4 Trader EA

Post by MrLong »

slipshod wrote:
MrLong wrote:I was just looking though the code and cannot see the benefit of only being able to open an order in a 4H time envelope. While crossing the zero line.

If price continued, the EA would not be able to place orders after the first 4 Hour period of
crossing the zero line if using the AO as an order.

What's your opinion?

Thanks for all your help in this thread.
Hi Andy, the changes I made don't assume a cross of the zero line. For a long entry, the AO must still be in negative territory, but less negative than it was the previous candle, and vice versa for shorts as per the rule in the manual screenshot you posted earlier:-

Best case Buy Scenario
AO below its zero line
AO's bar has turned green (this happens when its higher than the previous candle's AO bar).

In actual fact my implementation was a bit loose - it'll accept a buy entry on any AO green bar, whereas reading it again that word "turned" implies that the previous bar was red.
mobthehop wrote:
slipshod wrote:Its not a choice whether to use Stoch or RSI. You can use both or either.
does not comply with the 10.4 either, it should be either/or and SH expressed his preference for RSI....

As Stoch and RSI are defined as variables, would it not make more sense to set only one of them as external boolean and when set to false, the other is considered true (eg external bool RSI = true, if set to false, Stoch will be applied without being an external)
That's what the useRSIInsteadOfStoch setting implies, but the logic of the coding used Stoch and AO all the time anyway, with RSI being used only if those other two didn't trigger an entry. My change allows the user to explicitly state what combination of the three methods are used - can easily just set Stoch to false and RSI to true or vice versa, but yes it doesn't force an either-or choice.

To do that, useStoch and useRSI could be dropped (keep useAO though) and in trendDirect() useStoch could be replaced with !useRSIInsteadOfStoch, and useRSI replaced with useRSIInsteadOfStoch - pretty straightforward. I'll leave Andy to decide which way he wants to go with this when he returns from his well-earned break ... which probably consists of sneakily snatching half an hour here & there through the day to check this forum on his iPad :D

Edit: Here's a version of trendDirect with the above changes for both UseRSIInsteadOfStoch and AO...

Code: Select all

bool trendDirect(string symbol, int type)
{
    double mA   = iMA(symbol, PERIOD_H4, 240, 0, MODE_LWMA, PRICE_OPEN, 0);
    double sT   = iStochastic(symbol, PERIOD_H4, 5, 3, 3, MODE_LWMA, 1, MODE_SIGNAL, 0);
    double aO   = GetAo(symbol, PERIOD_H4, 0);
    double aO1  = GetAo(symbol, PERIOD_H4, 1);
    double aO2  = GetAo(symbol, PERIOD_H4, 2);
    bool aObuy = (aO < 0 && aO > aO1 && aO1 < aO2);
    bool aOsell = (aO > 0 && aO < aO1 && aO1 < aO2);
    double lO   = iLow(symbol, PERIOD_H4, 0);
    double hO   = iHigh(symbol, PERIOD_H4, 0);
    double gRSI = GetSlopeRSI(symbol, PERIOD_H4, 0);

    if (!UseRSIInsteadOfStoch)
    {
       if (type == OP_BUY)
       {
           if (useBothForPullback)
           {
               if (lO > mA && sT < 20 && aObuy)
                   return(true);
           }
           else if (lO > mA && sT < 20)
               return(true);
       }

       if (type == OP_SELL)
       {
           if (useBothForPullback)
           {
               if (hO < mA && sT > 80 && aOsell)
                   return(true);
           }
           else if (hO < mA && sT > 80)
               return(true);
       }
    }
    else
    {
        if (type == OP_BUY)
        {
            if (useBothForPullback)
            {
                if (lO > mA && gRSI < RSITMAlowlevel && aObuy)
                    return(true);
            }
            else if (lO > mA && gRSI < RSITMAlowlevel)
                return(true);
        }

        if (type == OP_SELL)
        {
            if (useBothForPullback)
            {
                if (hO < mA && gRSI > RSITMAhighlevel && aOsell)
                    return(true);
            }
            else if (hO < mA && gRSI > RSITMAhighlevel)
                return(true);
        }
    }

    if (useAO)
    {
        if (type == OP_BUY && lO > mA && aObuy)
            return(true);
        else if (type == OP_SELL && hO < mA && aOsell)
            return(true);
    }

    return(false);
}
Btw I can't for the life of me remember a Pending order script! I must be getting old and/or severely lacking in my coffee intake. I use some drag-drop scripts for moving SLs and TPs (there's several like that on mql4.com) but nothing for pendings that I recall :|
Hi Slipshod,

We'll see which works best.
if (type == OP_BUY && lO > mA && aO < 0 && aO1 < aO) <==== if aO is lower than zero, then the last bar must also ?

The grid updating problem I was experiencing before I left, I didn't check toughly that refreshGrid() was being called when needed, would appear that the grid is being updated
with blank data for some reason, because the labels do exist but have no data..

Andy
Last edited by MrLong on Thu Apr 04, 2013 5:44 am, edited 1 time in total.
Post Reply

Return to “Nanningbob 10.x”