MQ4 Code Works

hayseed

Master Trader
Jul 27, 2010
1,157
275
149
usa
I know it may not matter, so long as you stick to it, but can you share your golden cross metrics? I cannot get my cross to show 4/19/2021 on the USDJPY
//----

my lines might have been off or something..... that reminded me of something far more important.....h
//-----


//-----

Code:
             bool qup   = (iCustom(symbol,tfs[j],"QQE",5,false,0,1) > iCustom(symbol,tfs[j],"QQE",5,false,1,1)) &&  (iCustom(symbol,tfs[j],"QQE",5,false,0,2) < iCustom(symbol,tfs[j],"QQE",5,false,1,2));
             bool qup50 = (iCustom(symbol,tfs[j],"QQE",5,false,0,1) > 50.0) && (iCustom(symbol,tfs[j],"QQE",5,false,0,2) < 50.0);
             bool qdn   = (iCustom(symbol,tfs[j],"QQE",5,false,0,1) < iCustom(symbol,tfs[j],"QQE",5,false,1,1)) &&  (iCustom(symbol,tfs[j],"QQE",5,false,0,2) > iCustom(symbol,tfs[j],"QQE",5,false,1,2));
             bool qdn50 = (iCustom(symbol,tfs[j],"QQE",5,false,0,1) < 50.0) && (iCustom(symbol,tfs[j],"QQE",5,false,0,2) > 50.0);

             bool fast = (iMA(symbol,tfs[j], 50,0,0,0,1) > iMA(symbol,tfs[j], 50,0,0,0,2));
             bool mid  = (iMA(symbol,tfs[j],100,0,0,0,1) > iMA(symbol,tfs[j],100,0,0,0,2)); 
             bool slow = (iMA(symbol,tfs[j],200,0,0,0,1) > iMA(symbol,tfs[j],200,0,0,0,2));
                      
             bool up = ( fast &&  mid &&  slow && iMA(symbol,tfs[j],50,0,0,0,1) > iMA(symbol,tfs[j],200,0,0,0,1)) && (iMA(symbol,tfs[j],100,0,0,0,1) > iMA(symbol,tfs[j],200,0,0,0,1));
             bool dn = (!fast && !mid && !slow && iMA(symbol,tfs[j],50,0,0,0,1) < iMA(symbol,tfs[j],200,0,0,0,1)) && (iMA(symbol,tfs[j],100,0,0,0,1) < iMA(symbol,tfs[j],200,0,0,0,1));
 
             color wingclr = clrBlack;
             int   wing    =      244;
 

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
Another Question for you... I went on a quest after your bband video. Created the below entry script. Basically, the EA lives on one page. It will iterate through every pair. For each pair, on a new 30minute bar, it will check the below to send a bband grid.

MQL4:
              if((iCustom(pair, 30, "BBands Stops", 0, 4, 1) != EMPTY_VALUE && iCustom(pair, 30, "BBands Stops", 0, 5, 2) != EMPTY_VALUE)
                 ||
                 ((iSAR(pair,30,.01,.2,1) < iLow(pair,30,1) && iSAR(pair,30,.01,.2,2) > iHigh(pair,30,2))&&iCustom(pair, 30, "BBands Stops", 0, 4, 1) != EMPTY_VALUE))
                 {
                  LongMarketOrder(Trade_Size, M30_PT, 0, pair, "bband market with trend");
                  SendBuyGrid(4,Grid_space,Trade_Size,M30_PT,pair,"bband buy grid M30 with trend");
                 }

The Pseudo code = if buffer 4 (uptrend buffer - I assume the lower line) was NOT EMPTY, and if the 5th buffer (downtrend buffer) was NOT EMPTY two candles ago, we have a bband flip.

Is this accurate? for the PSAR i just check to see if the single value is above or below the High/Low because there is only a single buffer to worry about.
 

hayseed

Master Trader
Jul 27, 2010
1,157
275
149
usa
I went on a quest
//----

i like quests.....

how many 240 bbands signals are there in a year.....

the code below uses 20 periods, 10 is faster of course....

//----
Code:
             bool bbandsup = (iCustom(symbol,tfs[j],"bbands stops",20,0,0,2.0,1,1) > iCustom(symbol,tfs[j],"bbands stops",20,0,0,2.0,0,1)) && (iCustom(symbol,tfs[j],"bbands stops",20,0,0,2.0,1,2) < iCustom(symbol,tfs[j],"bbands stops",20,0,0,2.0,0,2));     
             bool bbandsdn = (iCustom(symbol,tfs[j],"bbands stops",20,0,0,2.0,1,1) < iCustom(symbol,tfs[j],"bbands stops",20,0,0,2.0,0,1)) && (iCustom(symbol,tfs[j],"bbands stops",20,0,0,2.0,1,2) > iCustom(symbol,tfs[j],"bbands stops",20,0,0,2.0,0,2));

//------

here's another quest for you....... using only the 50 sma, 100 sma , 200 sma , zigzag and awesome oscillator...... create a system.....

all are in the standard platform......h

//------

gbpusd-d1-oanda-division1-ao.png
 

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
May be a silly question, but do you consider SMA smoothed moving average or simple moving average?

I actually was working on that challenge today. Took some notes and wrote some objectives. I love the limitations you laid out, as it will definitely remove a lot of noise. Figure I have to accomplish the below. Daily will be the top tf for two reasons. 1) for a place to start. 2) it will give me more frequency to test rather than the weekly.

I will call this strategy - "To trade as a hayseed"

Questions I will look to answer with code:

Daily Timeframe
  1. Trend Detector - Long or Short Filter
    1. If true, long only. If false, Short only for low risk. This will not allow for fading currently.
    2. similar to the Peyton lines, I plan to use the crosses. If last signal was bullish, it sticks until opposing signal.
    3. I will use 50sma crossing 200sma
  2. Highest tf Trend Strength - 3 MA alignment on highest tf.
    1. represents strong trade conditions.
    2. Not sure how I will use it yet, but perhaps the idea would be to allow for an aggressive EA for smaller tf.
Wack Every Rally
  1. How to detect Daily chart continuation entry conditions?
    1. Potential early trend continuation on Daily using a 4H slow trigger?
  2. Detect Mid-range Continuation
    1. After Daily continuation confirmation, or after when an existing trend is going on Daily, how to re-enter it?
  3. Detect Mid Range Exhaustion
    1. How do you know when to stop, even if with the trend?
  4. Detect Full Momentum Cycles
    1. Places to leverage aggressive EA's rather than purely taking signals without zigzag
  5. Detect end to full Momentum Cycles

Notes for entries from looking at charts and your posts and videos:
Ideas for safe entries:
  • Take entries without 5 and 12 zzLegs
  • Lining up entries that match signals on higher timeframes


Possible triggers
  • AO 0.00 level cross
  • AO Red -to-Blue or Blue-To-Red (more aggressive)
  • 50sma cross of 200sma on lower time frames
  • full MA untangling on lower time frames

Possible entry schemes
  • If signal is triggered, send a grid every time - covers a range to catch trades
  • If signal is triggered, send multiple orders at same price with different take profits
  • If signal is triggered, send a single order
  • if signal is triggered without zzLeg, create stoploss at the near high/low (could be used for very first continuation entry on the highest time frame
  • simply gather trades for carry (possible during aggressive trend)

Popular exit schemes
  • end on pre-set tp
  • exit on opposing signal (carry trades to end of trend*)
  • exit upon the printing of a new zzLeg that goes with the trend
  • exit upon the length of zzLeg exceeding average length

So basically, what I will be trying to work on
  1. Decide my direction (trend first... entry second)
  2. "Do I want to be trading right now?"
  3. "How do I want to enter?"
 

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
Bit off topic... why do you figure GBPNZD, EURAUD, AUDCAD, etc had such incredible moves today?

I know USD CPI was off mark, but why are we seeing this it other pair so strongly?
 

hayseed

Master Trader
Jul 27, 2010
1,157
275
149
usa
Bit off topic... why do you figure GBPNZD, EURAUD, AUDCAD, etc had such incredible moves today?

I know USD CPI was off mark, but why are we seeing this it other pair so strongly?
//-----

if the pair is in the platform it's on topic.....

a small amount of short covering but more to do with aud and nzd are risk on pairs..... people are beginning to think inflation is under control so all they see is red wine and red roses.....

i'm seeing red to..... but it might be blood..... and might be mine......h
//-----

eurusd-d1-oanda-division1-1700.png
 

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
I have another question for my quest building. Want your take on entry criteria.

Suppose the direction you want to trade based on overall trend is long, I am considering the tow criteria below:

  • Don’t enter long trade unless current tf zz leg is down
  • Don’t enter long trade unless higher tf zz leg is down (think this will kill a lot of trend riding)
  • Don’t enter long trade below 240 tf is daily ATR is exceeded
  • Don’t take long trade 240 or above if weekly ATR is exceeded.

On the surface I feel like these will do great things for win rate, but also feel they are too narrowly focused and will rule out a lot of other profitable signals
 

hayseed

Master Trader
Jul 27, 2010
1,157
275
149
usa
will rule out a lot of other profitable signals
//---

no real harm in that......

those rules look good to me..... buying on a down leg in a uptrend, is the same as oversold in a uptrend.... the bars macd or ao spend below 0 is much smaller compared to the bars it spends above 0..... so momentum is in your favor usually.....

a little momentum can go a long way....h
 

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
//---

no real harm in that......

those rules look good to me..... buying on a down leg in a uptrend, is the same as oversold in a uptrend.... the bars macd or ao spend below 0 is much smaller compared to the bars it spends above 0..... so momentum is in your favor usually.....

a little momentum can go a long way....h
What say you regarding the daily/Weekly ATR left?

Do you believe that to be a strong enough indicator to fully turn off further trading?
 

hayseed

Master Trader
Jul 27, 2010
1,157
275
149
usa
What say you regarding the daily/Weekly ATR left?

Do you believe that to be a strong enough indicator to fully turn off further trading?
//----

that would depend on the direction of trade and the range above/below the open.....

a perfect example is the gbpusd this week ..... the weekly atr is gone...... but you can see in that chart above i was 2 standard lots short in that 1 account alone..... all accounts combined, probably 5 standard lots gbpusd short all entered today after the weekly atr was gone.....

why, because the daily downtrend and almost the full atr this week has been against that downtrend ..... so i had no reservation on shorting it.... and hard....

had i been buying, yes by all means i would not have bought more today after lunch...... might even sold part.....

i'll put in some pending shorts in a few minutes with 30 pip targets....

had the gbpusd fell the entire weekly atr this week, i would not be selling more now......

it's my version of risk aversion.....h
 

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
//----

that would depend on the direction of trade and the range above/below the open.....

a perfect example is the gbpusd this week ..... the weekly atr is gone...... but you can see in that chart above i was 2 standard lots short in that 1 account alone..... all accounts combined, probably 5 standard lots gbpusd short all entered today after the weekly atr was gone.....

why, because the daily downtrend and almost the full atr this week has been against that downtrend ..... so i had no reservation on shorting it.... and hard....

had i been buying, yes by all means i would not have bought more today after lunch...... might even sold part.....

i'll put in some pending shorts in a few minutes with 30 pip targets....

had the gbpusd fell the entire weekly atr this week, i would not be selling more now......

it's my version of risk aversion.....h
That’s incredible insight. What is your value on the daily? Is there a specific tf where you consider the daily ATR in the same way? I feel that 1H would be the highest tfyou could use to try and respect the daily ATR Left for intraday trades.
Post automatically merged:

//----

that would depend on the direction of trade and the range above/below the open.....

a perfect example is the gbpusd this week ..... the weekly atr is gone...... but you can see in that chart above i was 2 standard lots short in that 1 account alone..... all accounts combined, probably 5 standard lots gbpusd short all entered today after the weekly atr was gone.....

why, because the daily downtrend and almost the full atr this week has been against that downtrend ..... so i had no reservation on shorting it.... and hard....

had i been buying, yes by all means i would not have bought more today after lunch...... might even sold part.....

i'll put in some pending shorts in a few minutes with 30 pip targets....

had the gbpusd fell the entire weekly atr this week, i would not be selling more now......

it's my version of risk aversion.....h
Follow up…

Scenario, you’re buying and weekly ATR hit at lunch time… are you done with that pair for the week, or is there something that would have you interested in it again? Perhaps a strong retrace or the like?
 

hayseed

Master Trader
Jul 27, 2010
1,157
275
149
usa
That’s incredible insight. What is your value on the daily? Is there a specific tf where you consider the daily ATR in the same way? I feel that 1H would be the highest tfyou could use to try and respect the daily ATR Left for intraday trades.
Post automatically merged:


Follow up…

Scenario, you’re buying and weekly ATR hit at lunch time… are you done with that pair for the week, or is there something that would have you interested in it again? Perhaps a strong retrace or the like?
//----

today was not normal.... typically by 10am i back off placing trades in the direction of the trend..... even if the atr is barely spent..... movement slows around then.....

most of my trades are placed after 7pm or between london open , 2am cst , and 9am cst.....

yes, if the weekly atr is spent, i might close some and try to re enter again a a better price.... if the weekly atr is gone, there is almost guaranteed a 240 zigzag up leg.... that's a fair exit....

the gbpusd daily atr is about 140 pips.....not sure what periods that is..... 50 pips is a good gbpusd target.....h
 

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
//----

today was not normal.... typically by 10am i back off placing trades in the direction of the trend..... even if the atr is barely spent..... movement slows around then.....

most of my trades are placed after 7pm or between london open , 2am cst , and 9am cst.....

yes, if the weekly atr is spent, i might close some and try to re enter again a a better price.... if the weekly atr is gone, there is almost guaranteed a 240 zigzag up leg.... that's a fair exit....

the gbpusd daily atr is about 140 pips.....not sure what periods that is..... 50 pips is a good gbpusd target.....h
So I imagine I am catching you place trades for a London open!

How much of your trading is waking and placing trades vs EA?

I recall you mentioning your bband ea that hit about 97% success last week. I have recall you averaged 40-50 trades a day from your ftmo challenge.

We’re those manual or EA, and how do you decide which to do?
 

hayseed

Master Trader
Jul 27, 2010
1,157
275
149
usa
So I imagine I am catching you place trades for a London open!

How much of your trading is waking and placing trades vs EA?

I recall you mentioning your bband ea that hit about 97% success last week. I have recall you averaged 40-50 trades a day from your ftmo challenge.

We’re those manual or EA, and how do you decide which to do?
//----

yes you were.....

not sure how to answer ea vs me.... maybe 90% ea..... but that does not mean i'm not very much in the loop.....

if you put the mouse curser over the trade in the open trades tab, it will say , 'placed by ea' or 'placed manually'..... most mine say placed by ea but i gave the ea the go ahead.....

i closed all those gbpusd trades last night and placed the mini lot pending orders like mentioned above..... along with a 3 mini lot order.... so it looks like 6 were ea and 1 manual..... really, all were manual.... none would have been made had metatrader not alerted me..... so maybe all were ea......

right now the usd counts are messed up so must be very selective....h

//-----

gbpusd-h1-oanda-division1-60.png
 

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
Toying with indicator solutions to signal entry opportunities (rallies to wack) and exit opps...

What do you think of the attached (I am not going to lie... my biggest goal is to learn to trade like you. My biggest prideful goal is to make a tool you haven't seen before but brings you value... then maybe I'll have a shot of being truly great).

Extern variables:
  • highertfATRPeriod = chooses length for the higher tf ATR you want to analyze
  • highertf = chooses higher tf for MTF analysis
  • ATRrange1 = chooses look back period 1
  • ATRrange2 = chooses look back period 2
Buffer 1 - MTF of Daily ATR over chosen length.
Buffer 2 - 2x the Daily ATR calculated above

Buffer 3 - Rolling Absolute True Range of the last x bars (chosen by ATRrange1)
Buffer 4 - Rolling Absolute True Range of the last x bars (chosen by ATRrange2)

Couple ways to look at this, using the 240 chart as example, and 1440 as the higher tf:
  • 6ea 240 bars is a day.
  • if you get a string of 6 240bars with a range that exceeds the days rolling ATR... you might be close to finished with that move.
  • if you get a string of 6 240bars with a range that exceeds 2x the ATR... even more so.
  • Using ATRrange2, you can increase the lookback simply to view more data.
Seems like the 2x ATR is a good look to exit a trade with the trend, and the 1x is hit more in the rallies you want to whack.

Benefits - as I see it, when a new daily bar prints, you get a clean slate with your range. What this will do is completely eliminate data from the end of the previous bar that may be showing you you're close to the end of your 240bar run.


Version 2 is also attached. This simply autopopulates the variables. the Aqua is the based on Daily tf, the Green is Weekly.
the look back for the current timeframe is simply the Daily/Period() and Weekly/Period(), respectively.

1660234517052.png

Useful?
 

Attachments

  • RollingATRv2.ex4
    10.2 KB · Views: 4
  • RollingATRv2.mq4
    4.1 KB · Views: 7
  • RollingATR.ex4
    10.1 KB · Views: 6
  • RollingATR.mq4
    3.5 KB · Views: 9

TradeChaser

Active Trader
May 12, 2020
169
6
34
32
My logic was off on that. v3 and v5 are more accurate. Not sure which I like best, or if either are even useful.

v3 flips what your are measuring based on if the current high becomes lower than the look back low. If that is the case, the fomula changes from

High - Low[i+lookback] to Low - High[i+lookback].

v5 just keeps the highest and lowest in the last range and measures the difference. This won't be as sensitive as the above method. For example, if you get a large outside bar that makes the highest and lowest of the last [lookback] bars, the range will be slower to reflect the changes after that large bar.

1660237849460.png


example of the smoothing effect on the H1

1660238065659.png
 

Attachments

  • RollingATRv3.mq4
    4.8 KB · Views: 8
  • RollingATRv3.ex4
    11.1 KB · Views: 4
  • RollingATRv5.mq4
    4.7 KB · Views: 7
  • RollingATRv5.ex4
    10.7 KB · Views: 5

hayseed

Master Trader
Jul 27, 2010
1,157
275
149
usa
Toying with indicator solutions to signal entry opportunities (rallies to wack) and exit opps...
//-----

hmmmmm.... is that a buy i see on that chart......

another way which might be easier to focus on is to create atr bands above and below a moving average...... the thought being in a downtrend you might consider selling something that rose above that band or buy something in a uptrend that fell below the band...... the moving average could be 1 or greater......

in each of those cases quite often the zigzag will back you up.....

first...... establish a trend indication filter......

second....... establish a momentum indication filter.....

third...... establish entry rules......

last...... backtest on every pair..... 0.01 lots.....

let time and rules build the account...... not risk and reward......h
//----

gbpusd-h4-ftmo-s-r.png