adventures of a newbie - page 7

 
niko:

To CB:


Hey high flyer! I did all I could with Tim's tasks and thus decided to start looking at your code in more detail.


I went through your code, trying to understand and fix the errors in it. I managed to reduce the errors to just 'unbalanced parenthesis' for string fnGenerateSignal(). I don't know why it says unbalance in this case.


As always I would appreciate your thoughts on my progress with your code! Bear in mind there are still a lot of bits and bobs I don't understand, even the very basic stuff.

See annotations.

Noticed the following:

- you were declaring functions to expect variables passed to them as parameters, but then not actually passing them on the function call - so I've asked you just to move the variables up to the top block so they are available to all your functions for now - let's just keep it as simple as poss for now

- you seemed to think you had to declare the name of your function as a variable too. Here's how to use functions, pass variables in and out of them:


To declare:

int abcdef(int x, string s) //meaning the function with name abcdef accepts input of an integer and a string and returns an integer as its output (in this case either 0 or 9)

{

the function does stuff with x and s

if (some condition)

return(9);

else

return(0);

}


And to call:

...

myResponse = abcdef(myInteger, myString);

if (myResponse == 9)

{

blah

 

Hey CB,

Thank you. this is the bit I couldn't figure out, you made it very clear to me. I think I'm on the right lines now.

CB, question1:

bool fnOrderDuplicate()

{

iDuplicateOrders=0 // CB shouldn't iDuplicateOrders be declared as int or double?

iOrders = OrdersTotal()-1 //I understand now with your help, this calls the OrdersTotal function. but again shouldn't iOrders be declared as a variable?

CB,question2:

int fnTrade() //Why is this not "int fnTrade(string sSignal)", as we are using sSignal in the function. ?

{ if(sSignal=="OP_BUY")

...

CB,quesytion3:

You asked me to remove return(0) and } at the end of the code. but this would mean the Start() does not close with a typical 'return(0) and brackets are not closed, as all prevoius brackets (from what I checked) are particular to opening and closing of the specific functions we designed. ?

 
niko:

Hey CB,

Thank you. this is the bit I couldn't figure out, you made it very clear to me. I think I'm on the right lines now.

CB, question1:

bool fnOrderDuplicate()

{

iDuplicateOrders=0 // CB shouldn't iDuplicateOrders be declared as int or double?

iOrders = OrdersTotal()-1 //I understand now with your help, this calls the OrdersTotal function. but again shouldn't iOrders be declared as a variable?

CB,question2:

int fnTrade() //Why is this not "int fnTrade(string sSignal)", as we are using sSignal in the function. ?

{ if(sSignal=="OP_BUY")

...

CB,quesytion3:

You asked me to remove return(0) and } at the end of the code. but this would mean the Start() does not close with a typical 'return(0) and brackets are not closed, as all prevoius brackets (from what I checked) are particular to opening and closing of the specific functions we designed. ?

Q1: Both these variables ARE defined. Look at the variables I suggested you moved up to the section where you defined your externs. This will automatically make them available to all functions.

Q2: The variable sSignal, if declared outside all functions, is available to all functions without the need to explicitly pass it in the function call.

Q3: Ah - now I see your misunderstanding. Wondered why you'd put that return statement and curly bracket there. Its catered for by my comment about the fnTrade() statement. You'll notice I'd asked you to add a return call and closing bracket in there. The reason is that you were (wrongly) declaring all your functions within the start() function code-block.


CB

 
niko wrote >>

Hey Tim,

I did the bit's you asked me to do for the code. Thank you for providing detailed answers to my questions and for writing a lot of comments throughout the code to help me get my head around this. I am starting to see how things patch together, how to use arrays properly and call specific functions (and the role of global and local variables).

I attached the latest version of our code.

One question, is there any reason why we didn't make EntryRules function to contain everything (including flags) to give us a buy/short condition, but instead we call upon it with flags later on to make the entry decision?

Hi Nick


I've tidied up a few things in the code and hopefully answered your questiions. The EntryFunction is now complete. You just need to call it from the start (main) function as I have indicated in the code and pass it the required parameters as shown. Just a few minutes work I hope and then you can have a go at compiling and testing. I expect you will have a few little bugs to contend with but hopefuly nothing major.


When compiled, try running the EA in the tester and have a look in the log file to see if it appears to be doing what you would expect it to at this stage. You should be able to see BUY and SELL signals for each of the currency pairs.


I would say at this point that your code is about 75% complete.


The next step after this is to write another function to check for open orders for a given currency pair and trade direction.


I would suggest having a look at the MT4 documentation under Trading functions. OrdersTotal(), OrderSelect(), Order Symbol() & OrderType() look likely candidates for this task.


As to your question about making the EntryRules function contain everything including the flags, I can see no reason why not. Why don't you have a go at modifying the EntryRules function.

I suggest you do this after you have compiled, run and tested what you have already done.


Regards

Tim

 

CB: Thanks man, this helps to clarify things further for me. For some reason I thought everything had to be within the start function.

Question: Shouldn't we declare ema's within the start function as we want them calculated/updated with every tick?

 

Hey Tim: Thank you once again for your help. I'l proceed with things at my end as soon as I leave work this evening. working with you and CB I now have more ideas on how to put things together, and starting to think more flexibly about it all.

 
niko:

CB: Thanks man, this helps to clarify things further for me. For some reason I thought everything had to be within the start function.

Question: Shouldn't we declare ema's within the start function as we want them calculated/updated with every tick?

No. If you declare a variable within a function, it is only available within that function. If you declare it outside all functions, it is available to all functions. Therefore you can declare the ema variables at the top and then do math on them within the start function.


CB

 
cloudbreaker wrote >>

No. If you declare a variable within a function, it is only available within that function. If you declare it outside all functions, it is available to all functions. Therefore you can declare the ema variables at the top and then do math on them within the start function.

CB

Thank's CB, I get it now!

 

Hey Tim,


I'm back now from Turkey. I had an amazing time in Kusadasi, and really didn't want to leave. Turkish people are so much friendlier than Brits. I felt at home there, even though I never been there before.


I spent the last 5 hours or so upgrading the code we are designing. I'ts attached.

The key amendments were:

1. I created an Order Count function, and called it within start function. I expect this to be full of errors as there are bits I still dont get (eg: how to ensure it follows the [c] loop so that it only works per currency pair)

2. I tried to correct the code with regards to name currencySymbol vs. currencySym, as we changed the name half way. But this could have got muddled.

3. I called the EntryRules function within start function


I would really appreciate if you correct the big and little mistakes if you continue introducing //why the old code is wrong, comments, it helps me correct my logical thinking.


As always eagerly await your amendments!

 

Hey CB,


I think Tim is on holiday now as I haven't heard from him for a few days. Thus I am continuing with your code, as it will help me trade (as I am trading manually the strategy now, and it means waking up early hours, etc). I amended all the code as you requested, but for some reason it still returns an error (to do with "==" this time, very strange).


Another thing is I noticed the start function was not closed. So I added "}" after first function within the start (), if we do not do that, code generates an error with the subsequent function string fnGenerateSignal() (saying function definition for that is unexpected).


Thank you as always. I look forward to your comments/amdendments!

Nick

Files:
Reason: