| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Conditional / Persistent conditions coding https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1670 |
Page 1 of 1 |
| Author: | boldtrader [ Thu Mar 21, 2013 9:28 pm ] |
| Post subject: | Conditional / Persistent conditions coding |
Hi Team, My warmest and deepest appreciation to all the great minds here, active and lurking. And even greater regards to Steve for this great group of talent. I am in need of some really fresh eyes, as I am a self-taught / self learning newbie on mql4. I am hitting against some minor headwinds, but feeling like I am still sailing upstream. Any help is greatly appreciated. I am trying to create a conditional loop(?), whereby when Condition B (which is a combination of data 1 + data 2 + data 3 + ... ) == True, then if Condition A == (which is a combination of data 4 + data 5 + data 6 + ... ) == True in look back of (x # of ) bars, on Period (), [&& no other condition (ie: Condition D) has occurred in look back period], then execute Buy trade. Additionally, as long as Condition B == True, for each future incident of Condition A == True, after initial trade, then Buy. For the Sell side, whereby when Condition D (combination of data 4 - data 5 - data 6 - .... ) == true, then if Condition C (which is a combination of data 1 - data 2 - data 3 - ... ) == True in look back of (20) bars, on Period (20), [&& no other condition (ie: Condition D) has occurred in look back period), then execute Sell trade. I am also looking for ability to expanding into multiple conditions / cases. The following has been setup: #include <stdlib.mqh> #include <stderror.mqh> #include <WinUser32.mqh> int init() { if statements return(0); } int start() { if statements return(0); } // Trading code starts here if (TradeOrAlert) { double dData1 = iCustom(Symbol(),0,"Indi Name", data, mode, # bars]); // #bars may not be needed? double dData2 = iCustom(Symbol(),0,"Indi Name", data, mode, # bars]); double dData3 = iCustom(Symbol(),0,"Indi Name", data, mode, # bars]); double dData4 = iCustom(Symbol(),0,"Indi Name", data, mode, # bars]); double dData5 = iCustom(Symbol(),0,"Indi Name", data, mode, # bars]); double dData6 = iCustom(Symbol(),0,"Indi Name", data, mode, # bars]); double dData7 = iCustom(Symbol(),0,"Indi Name", data, mode, # bars]); double dConditionA = (dData1 +dData2) > (dData3 + dData4) double dConditionB = (dData1 +dData3) > (dData2 + dData5) double dConditionC = (dData2 +dData4) > (dData2 + dData7) double dConditionD = (dData1 +dData3) > (dData4 + dData6) // Condition B while ( dConditionB == true) { then // Condition A if (dConditionB == true) { BUY(Symbol(),B_Symbol_LS_1,B_Symbol_TP_1,B_Symbol_SL_1,B_Symbol_TS_1,"BUY Trade Condition") ; Print ( data info = "+dCondition A+", "+dCondition B+", "...", " ); // Condition D While (dConditionD == true){ then // Condition C if (dConditionC == true) { SELL(Symbol(),S_Symbol_LS_0,S_Symbol_TP_0,S_Symbol_SL_0,S_Symbol_TS_0,"Sell Trade Condition") ; Print ( data info = "+dCondition C+", "+dCondition D+", "...", " ); } return(0); } ===================================================================== One suggestion I received was to use Global Variables: If the condition(s) carry through from bar to bar (which they can sometimes do), to set the conditions as global variables. example: If (ConditionB== true && ConditionA == true) //check for orders / open positions // If nothing, send order else if (ConditionD == ture && ConditionC == true) // check for orders / open positions // if nothing, send order But this brings me back to the coding of the GV.. and I understand they have to be "reset", which the "reset" will have its own terms/conditions to cause the reset to be true or false. I am stuck on making this work out and know there is probably a better way to do this, and organize. I have been reading about global variables, and while it seems that solution may be better, I am not sure how to code that part up. Any help please? |
|
| Author: | fxprotrader [ Fri Mar 22, 2013 1:00 am ] |
| Post subject: | Re: Conditional / Persistent conditions coding |
boldtrader- Following is a function that I wrote to check multiple conditions. Not sure if this fits into what you're doing but I'm going to throw it out there, maybe something in it will help your situation or at least give you an idea. Code: Select all |
|
| Author: | boldtrader [ Fri Mar 22, 2013 4:43 pm ] |
| Post subject: | Re: Conditional / Persistent conditions coding |
Thanks for a quick reply fxprotrader. Will give it some thought as to how I may be able to use your suggestion. Thank you. |
|
| Author: | dietcoke [ Fri Mar 22, 2013 6:43 pm ] |
| Post subject: | Re: Conditional / Persistent conditions coding |
You have two problems to solve from what I can see as well as determining the truth or not of a number of conditions, you also need to hold data for each indicator lookback period. This is best done in arrays. You can find a good primer on using arrays here http://www.forexfactory.com/showthread.php?t=165411 Eg. Code: Select all Code: Select all Code: Select all |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|