| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Adding indicator calls to my shell EA's https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4519 |
Page 2 of 3 |
| Author: | SteveHopwood [ Sun Nov 29, 2015 3:46 pm ] |
| Post subject: | More to add to ReadIndicatorValues() |
Go back to ReadIndicatorValues(), to the end of the code you have added previously. I have detected buy and sell signals, but these will in turn be cancelled after I add higher time frame CCA and Stochastic, and either of these filters do not allow a trade. I often have to code systems where one signal will close an opposite direction trade. This snippet is all about OCO stuff: Code: Select all That is usually ReadIndicatorValues() finished but LC does not want a trade opening during the same candle that saw a trade close. Copy this snippet to finish off ReadIndicatorValues() Code: Select all Code: Select all Code: Select all Next up: editing LookForTradeClosure() |
|
| Author: | SteveHopwood [ Sun Nov 29, 2015 3:52 pm ] |
| Post subject: | Editing LookForTradeClosure() |
The function that keeps track of the trading position is CountOpenTrades(). CountOpenTrades() includes a call to the LookForTradeClosure(). LookForTradeClosure() includes any special closure requirements. Here, I only need a trade closing on an opposite direction signal and this is already taken care of by the LookForTradeClosure() function in the latest shell versions. If you are using an older version, just copy paste the entire function over the top of the existing one. Code: Select all |
|
| Author: | SteveHopwood [ Sun Nov 29, 2015 4:09 pm ] |
| Post subject: | Mopping up |
Steppy is complete so far as I understand Little Caro was attempting, so I have attached it so I can refer to line numbers in the .mq4 source code.
I have shown you how to add an indicator to my Buggger All Included shell. You follow exactly the same procedure when using the other two; the additional features happen automatically - I never even think about them apart from setting default values. Next up: adding higher time frame CCA consideration. |
|
| Author: | SteveHopwood [ Sun Nov 29, 2015 7:19 pm ] |
| Post subject: | Adding higher time frame CCA consideration |
I just know when coding an EA for the sort of CCA that we are using here, that somewhere down the line I will be asked to add a higher time frame filter. Usually I add this at the start to save some trouble later, but I am using Steppy for a different purpose. Steppy with htf consideration is attached. Look at line 158: string HigherTimeFrameDisplay=""; This is for the htf display on the chart. Look at line 179+ Code: Select all The DisplayUserFeedback() ending at line 356 has this appended: Code: Select all Code: Select all Code: Select all Next up: adding one of the standard Empty4 indicators |
|
| Author: | SteveHopwood [ Mon Nov 30, 2015 4:21 pm ] |
| Post subject: | Adding one of the standard Empty4 indicators |
Adding any of the usual Empty4 indicators is no harder than is adding a CCA. I have added Stochastic to Steppy. I have programmed him to: buy when Stoch is >= 50 and < 80; sell when <50 and > 20. All these levels are user inputs. This gave me four possible states for Stoch, so here are the constants beginning at line 21 Code: Select all Code: Select all I cannot find an ENUM for Stoch's mode, so I have used an integer instead. StochBuyAbove etc offer users the ability to set their own limits. The chart display starts at line 386; GetStochastic() starts at line 1388: Code: Select all The code block that reads Stochastic and calculates which of the four states it can be in, starts at line 1471: Code: Select all Code: Select all Adding them to the "Bare Bones" and "Bob stuff" versions is exactly the same. Optional features in "Bob stuff" such as Slope and CSS happen automatically. The code to read them is in ReadIndicatorValues() but the code that consults their values is in LookForTradingOpportunities() and cancels an impending trade should they not be correct for trading. I will move it to ReadIndicatorValues() for consistency some time, but I know where it is and so never think about it. Steppy final version is attached. He will have bugs. I don't care. I coded him as training in how I use my shells - I would not even bother to have bad dreams about trading him. Set him up on demo if you want and debug him yourself - that will be good learning for you. Start your own thread about him if you want - just don't tell me about bugs here. I am going to reserve one more post for hints and tips for beginner coders, then I shall unlock this thread. Feel free to ask questions about anything you do not understand - I do not guarantee to answer them but there is no harm in trying. Have fun. |
|
| Author: | SteveHopwood [ Mon Nov 30, 2015 4:23 pm ] |
| Post subject: | Hints and tips for beginner coders |
Here are some tips for those of you just starting to code and trying to use my shells. These are not for the Proper Coders here - those guys are awesome and were born having forgotten more about programming than you or I will ever learn. They are thingies that help keep me from having to spend too many hours hunting down that bloody missing bracket.......................... ----------------------------------------------------------------------------------------- Comment absolutely everything. Code whose meaning and purpose is blindingly clear now will not appear so in 3 months time - or 3 weeks in my case. You also have others to consider when sharing your code, especially when asking for help. You may think your code is so crystal clear that a 3 year old could read it, but nobody else will agree. ------------------------------------------------------------------ BuySignal is a Boolean so,
The correct way to test if one variable is not equal to another is this: if (var1 != var2) -------------------------------------------------------------- If you do not fully grasp operator precedence, then use extra brackets for certainty. For example, if you are not sure if double take = Ask + TakeProfit * factor; will give the correct result, then make certain. Code within brackets is always parsed first, so double take = Ask + (TakeProfit * factor) ; will give the correct result. You can see from my code that I am clueless about operator precedence. ------------------------------------------------------------- You have multiple conditions that must be met for an action to take place. This construct: Code: Select all Code: Select all In the construct where each condition is tested separately, program control is passed to the next code block the instant any of the conditions fails. This can amount to a considerable cpu saving if you have multiple instances of an ea running. ------------------------------------------------------------------ Don't forget to use curly braces if you require more than one instruction to be carried out if a construct passes all the tests. For example, you forget the curly braces in this construct: Code: Select all Code: Select all ---------------------------------------------------------------------------------------- I use the comment in the above snippet as it helps me read my own code. I know which closing brace applies to which opening brace. You will see what I mean immediately when you meet your first block of conditionals inside conditionals inside conditionals........ and haven't a clue which closing brace matches which opening brace. ---------------------------------------------------------------------------------------- You have a conditional or a loop. Outline the block first, before starting to fill it in and compile to make sure you have not got something wrong. Imagine that several instructions have to be followed out if a conditional passes. Outline your block first: if (some condition) { }//if (some condition) then compile to make sure you have not mucked up right from the start. ---------------------------------------------------------------------------------------- Compile regularly. I compile after every block outline then typing every line of code within the block. You will discover why the first time you spend two hours hacking in code without compiling, then have to spend two days hunting down where you went wrong and all the compiler is telling you the the program has come to an unexpected end at line 2344. You will not be best pleased when you find that you missed out a bracket at line 133. Trust me in this, you really, really won't. ----------------------------------------------------------------------------------------- Avoid complicated equations and split them up into readable chunks instead. Yes, complicated equations look really clever and make you feel really good, but they are a bugger to sort out if there is something wrong. Guess how I know? ----------------------------------------------------------------------------------------- |
|
| Author: | FxEon [ Wed Dec 09, 2015 1:49 pm ] |
| Post subject: | Adding indicator calls to my shell EA's |
Thanks for this Steve. I normally code low-level embedded systems using assembler and C/C++. So I have an idea of what's going on with the programming but i need to learn/understand how to use the Empty4 environment properly. Your coding structure (with the comments) makes it easy to see what your up to and accelerates learning exponentially. Was busy breaking down the shell ea function calls to get a handle on program flow. Its easier for me if I can get a flowchart view of code execution and function calling. So this write-up on the indicator calls, decision making and trade execution is extremely useful to me as it saves me two weeks of figuring things out. Have until end January to apply myself to this, then back to being busy surviving life. Again, thank you for the time you spent to make this readable and easy to understand and also for making this available to beginner fx coders. Regards, Eben |
|
| Author: | SteveHopwood [ Wed Dec 09, 2015 2:16 pm ] |
| Post subject: | Adding indicator calls to my shell EA's |
You are most welcome Eben. Thanks for your kind words. One of the mistakes I made whilst writing the tutorial was to leave the trade signal detection code outside the indicator reading construct, which needs to be: Code: Select all I have uploaded my latest shell versions to the shell thread, with the corrected construct. As a C/C++ coder, you will find CrapQl4 a doddle. |
|
| Author: | zaguy [ Sun Feb 21, 2016 6:40 pm ] |
| Post subject: | Adding indicator calls to my shell EA's |
Hello Steve. Thank you for also making it possible for dimwits like me to try and learn some coding. I have been playing around with the coding of some of your recent EAs to see the result in backtesting. I am a newbie to coding (not so much new to forex - but still have a heck of a lot to learn - and your forum has been a great help). Mtw. I have not been involved in Forex for a few years, but remembered you from FF and managed, through Google, to find this amazing forum. I want try something with your "BOB 'n Grid and his ma" EA, but cannot figure out how to do it. If you can assist with the coding, it would be greatly appreciated - although it might just be a waste of time! I want to try out the following: 1. With the triggering of the main trade, 3 pending orders are placed in a grid in the direction of the trade, x pip distance from the main trade and each other, but each trade allowing user input for lot sizes. Eg. Main trade = 0.04 lots, 1st pending trade = 0.03, 2nd pending trade = 0.02 and 3rd pending trade = 0.01. Thank you. I have also read about another strategy that might be interested to look at? - and have attached documents for perusing (it is freely available from a guy called Jordan Lindsey (JCL's Forex, http://www.forextrading.jcls-forex.com). Mayeb we can try it on your trend EAs? |
|
| Author: | SteveHopwood [ Mon Feb 22, 2016 11:08 am ] |
| Post subject: | Adding indicator calls to my shell EA's |
The bot uses the OpenTrades variable to know how many trades there are on the individual chart, so go to void SendPendingMultipleBuyTrades(double price, string comment, int TradesAllowed), and then to line 2168, which is a blank line, and insert OpenTrades = 1; Then line 2181: SendSingleTrade(Symbol(), OP_BUYSTOP, TradeComment, MultiTradeLot, price, stop, take); Change this to SendSingleTrade(Symbol(), OP_BUYSTOP, TradeComment, MultiTradeLot - (OpenTrades / 100), price, stop, take); (or MainTradeLot - depends what you want to do) Insert into the blank line at 2181: OpenTrades++; Same process for void SendPendingMultipleSellTrades(double price, string comment, int TradesAllowed) I have not tested this, so try it and see. |
|
| All times are UTC | Page 2 of 3 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|