CODING A BOLLINGER BAND RE-ENTRY EXPERT ADVISOR STEP BY STEP CONTINUED: Now here the first thing I am going to test is in case of buy orders: I know that I am normally passing in an orderType buy stop. But, just in case it is an orderType buy, I have tested the orderType passed in. So, this argument using the modulus operator, the percent sign 2 (%2). So, an order type buy and an order type buy stop will both have the same value modulus 2... if (orderType%2==ORDER_TYPE_BUY) So, I just need to compare this to an ORDER_TYPE_BUY. In that case, the price…the current market price is the ask price. price = Ask; And I am saying that if the current ask price is greater than or equal to the entry price, minus this stops level that we just calculated (i.e., if that price is too high to enter a buy stop order) then I am going to change the orderType to an ORDER_TYPE_BUY. if (price>=(entryPrice-stopsLevel) ) So, I will be executing a market order, and I am going to change the entry price to the current market price. { entryPrice = price; orderType = ORDER_TYPE_BUY; } And then I calculate the take profit price using the normalized double function again, and I am just taking the entry price, which may have been modified here, and adding the take profit value. And I am also taking the entry price and subtracting the stop loss value to get the stop loss price. tpPrice = NormalizeDouble(entryPrice+tp, Digits()); slPrice = NormalizeDouble(entryPrice-sl, Digits()); So, that was the code for the buy type order. Then I have an else statement and the code for the sell type order is the same. If the orderType %2 is ORDER_TYPE_SELL, then the price is the bid price. If the price in this case is less than or equal to entry price plus the stops level, then again, I am going to execute a market order. So, I change the order type to a type sell, and my entry price becomes the market price. And then, the take profit in this case is entry price minus take profit. And the stop loss price is entry price plus the stop loss. So, these statementc here... ...and here... ...simply convert my call into a market order by changing the type to a buy or a sell type instead of a buy stop or sell stop; and changing the entry price to the current market price. And then I just execute an order send, passing in the market symbol, the order type, the volume from my inputs, the entry price (which may have been modified here if executing a market order), using zero slippage, stop loss price, take profit price, the comment that I input, magic number that was input, and the expiration time that I calculated above.). If this is a market order, then that expiration is going to be ignored. But, if it is a buy stop or a sell stop, then that order will be deleted if the expiry time is reached without the order being executed. And then I just return that. The orderSend will return a ticket number. If it fails for some reason, then the order ticket number will be less than or equal to zero, so I just return that ticket number here. (Remember that the open order function returns an integer...) So next, I will need to go back up to the OnTick event, to the ORDER_TYPE_SELL_STOP and continue the description from there... (Line #78)
CODING A BOLLINGER BAND RE-ENTRY EXPERT ADVISOR STEP BY STEP ... FINISHED: So now, back up to the on tick event… This is the ORDER_TYPE_SELL_STOP where the close was above the upper band, and has now moved below the upper band. And now, I do exactly the same thing for a buy. But, in this case, if bar 2 closed below the lower band, and bar 1 closed above the lower band, then it is a re-entry from below and that is a type buy... And so, I again call the OpenOrder function, but this time I am passing in a BUY_STOP, passing in the high value for bar number 1 as the entry point, and still the width of the band. And then I just return from this function… And that is a complete working Bollinger band strategy expert advisor.
I am finding that EABuilder has certain "limitations" such that the program is unable to create indicators in accordance with my exact parameters. Consequently, the following indicator draws a bunch of "extra" arrows instead of drawing arrows ONLY at the major trend reversals... I have therefore decided to take advantage of the website simply as a study tool, and NOT to purchase access to the complete service until and unless I reach the point where I am able to code indicators on my own that are in full compliance with what I envision, precisely as I conceptualize it. Otherwise, I should think I will not be able to create EAs that work exactly like I imagine, even with the help of their system.
Orchard Forex Trend Ribbon Indicator in Plain English The only way I am ever going to be able to code MT4 Expert Advisors completely on my own is by developing my own personal/thorough understanding of all the related concepts. And experience has taught me that the best way to do that is to rewrite everything in simple/everyday language. So here I go, starting with Orchard Forex's Trend Ribbon Indicator...
Orchard Forex Trend Ribbon Indicator in Plain English (continued...) Inputs specify how you want calculations to be done. These values—these inputs—are recorded in the global scope (i.e., at the beginning of the code). This means they occur outside any of the functions, so any variables defined here in the global scope can be seen inside any of the functions that follow. According to the information I've read, inputs are similar to externs in that both determine the input parameters of an MQL4 program. However, unlike input variables, the values of external variables can be modified in the program during its operation (and external variables are always reinitialized immediately before the OnInit() function is called). Also, I've heard that using the global scope might seem like a convenient way to define variables, but this is not recommended at all, except that one supposedly has no choice when it comes to inputs, which must be set in the global scope. Inputs are clearly identified as such (i.e., input), which is followed by the variable's data type, and then the variable's name, which is invented by (made up by) the coder himself or herself. Note however that it is good practice to come up with an EA naming convention so that one knows which variables in the rest of any EA code are input variables, such as beginning all EA input variables with the prefix "Inp." (These will be the names used as the variable labels appearing in the program's input boxes.) After the name comes the corresponding (assigned) value. If I understand correctly, this is like saying that the name IS the value, which is to say… in the remaining code, when you need or want to enter the value, you don’t use the actual number. Rather, you use the NAME of the input, because it's like when the program looks at the name, what it actually sees is the number. When you first run (initially load) the program, these are the default values that will appear in the input box. (You always finish off the input statements with a semi colon.) However, if you type a double slash on the same line following an input statement along with some type of text, that text will replace the input name as the variable label appearing in the program's corresponding input box. EXAMPLE:
I wanted to code a Triple Moving Average EA that Orchard Forex uploaded to YouTube, but when I finished, I got error messages. After going over the code carefully, I found one place where I failed to end a statement with a semicolon and another place where I omitted an opening parenthesis, but for the life of me, I couldn't find the other four errors that remained. I finally had to have someone else take a look at the code for me, but it turns out that they gave me bad information; so now I'm back to searching on my own. UPDATE: I am making progress... First of all, in the advisor's last bit of code, I should have followed the word "symbol" with TWO closing parentheses instead of just one, and the semicolon should have come BEFORE the final closing brace—not AFTER it... I actually EXPERIMENTED with changing the end of this piece of code in a couple of different ways, yet I was STILL blind to what I was actually looking at in the video. Wait... no I wasn't! Now I see why I couldn't figure it out: In the video, the guy never actually SHOWED the last final brace on the screen!!! So, I wasn't blind after all. It was HIS fault! Another mistake I made was in the ValidateInputs() section, where I typed InpMediumMAPeriods twice. The last part was supposed to be InpSlowMAPeriods<1)... (Something else I did that I almost forgot about was that once I typed "OrderSent" where I was supposed to have typed "OrderSend.")
I will have to check these folks out later today, when I find the time. I will be curious to see if I run into the same problems with them that I ran into when I tried to use EABuilder.com
EABuilder is much simpler to use than fxDreema. I'm finding that using EABuider to adjust indicators so they behave as I envision is really helping me to zero in on the key aspects that matter most in terms of the logic behind my system of trading...
Until I learn how to code all of the key factors, I can at least let indicators like the one below signal me when there are potential trade setups, and then I won't have to watch my charts anymore. I can just check them out when I hear an alert and decide whether it would really make sense to buy or sell the given pair after taking everything into consideration...
I lost my place and cannot find where I was working on the above project in my notes. Plus, now that I have at least one indicator that meets my basic needs, alerting me when there is a potential Numerical Price Prediction trade setup so that I no longer have to watch my charts, I am no longer so anxious about learning to code EAs totally on my own as quickly as possible. Consequently, I am going to start over again with someone else. Instead of trying to learn from Jim Hodges, who goes over a lot of details that have little practical use and spends a lot of time talking about stuff that has little to do with the subject at hand; and Orchard Forex, which thankfully gets right to the point, but is getting into stuff that is confusing me, like classes and building EA Frameworks; My plan now is to spend a little bit of time seeing what I can learn from this guy... René Balke