Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 01-14-2009, 11:26 PM
Junior Member
 
Join Date: Dec 2008
Posts: 12
rwb181 is on a distinguished road
a piece of code to remember an entry signal

Hello all,
I have an EA that has a number of different types of entry signals. I can toggle them on and off with true/false inputs. Meaning, if I have #1 and #5 set to true, entry signals will only be generated when both #1 and #5's conditions are met to open a trade and all other signals (or lack thereof) will be ignored.

The problem is, The entry signal has to be generated from both signals on the exact same bar to get an entry. How can I get the EA to remember one of the entry signals for a period of bars while waiting for a possible signal from the other. In other words, if I had an entry signal from #1 in the last "X" bars and am now getting an entry signal from #5 on the last bar (but the last bar didn't give a signal for #1), open a trade anyway. If the signal from #1 was too many bars ago, don't open a trade.

Here is the coding I used for one of the signals. All the others are in the same basic format. I want the time (bar) stipulation to be usable no matter which combination of signals I may or may not be using. Example; I am using signals #1,#4, and #9. I get an entry signal only if all three generated a signal sometime within the last X bars.

//Signal1
Bool BS1= false, SS1=false;
if(Use1)
{
double MA1=iMA(NULL,0,MA1Period,0,0,0,1);
double MA2=iMA(NULL,0,MA2Period,0,0,0,1);
if(MA1>MA2) BS1=true;
if(MA1<MA2) SS1=true;
}
else
{
BS1=true;
SS1=true;
}
//Signal2
bool BS2=false, SS2= false;
if(Use2)
{
double BUpper= iBands(.........................);
double BLower= iBands(..........................);
if(..........) BS2=true;
if(..........) SS2=true;
}
else
{
BS2=true;
SS2=true;
}
if((BS1==true) && (BS2==true)) return(1);
if((SS1==true) && (SS2==true)) return(2);

I am pretty sure that I need to use the "for" operator like this in some way;

int i;
for(i=0;i<=MaxBars-1;i++)

But, I am not sure how to put it in. If someone could show me what they would add to the first signal, I can use the same format for all the others I have added.

Thank you all for your help in this.

Ron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 01-15-2009, 12:31 AM
jmca's Avatar
Junior Member
 
Join Date: Feb 2008
Posts: 19
jmca is an unknown quantity at this point
You could user a timer, basically setting a trade time variable and comparing current time to it. Or you can use iBarShift ( http://docs.mql4.com/series/iBarShift ) which returns the bar with the exact or closest time of a given date/time given.

ex:

datetime lastTradeTime = --whatever the last trade time was--;
int theBarIWant = iBarShift(Symbol(), PERIOD_H1, lastTradeTime, false);
Open[theBarIWant];
Close[theBarIWant];
...whatever...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 01-15-2009, 04:27 AM
Junior Member
 
Join Date: Dec 2008
Posts: 12
rwb181 is on a distinguished road
You have me stumped.

I can't seem to figure out how to incorporate it into my existing signals and work correctly.

I'll keep trying.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 01-15-2009, 05:04 PM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 158
Roger09 is on a distinguished road
I don't really understand your problem (because of my English), but I think you can use:
double MA1=iMA(NULL,0,MA1Period,0,0,0,X);
for X bar.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 01-15-2009, 06:06 PM
Junior Member
 
Join Date: Dec 2008
Posts: 12
rwb181 is on a distinguished road
Quote:
Originally Posted by Roger09 View Post
I don't really understand your problem (because of my English), but I think you can use:
double MA1=iMA(NULL,0,MA1Period,0,0,0,X);
for X bar.
No, that will just allow me to adjust the shift of the bar that is used to do the calculations. What I want, is for an entry signal from one of the different signals I use to remain valid for a certain period of bars. That way, I can get an entry signal if both signals are generated within a given number of bars, not just if they both happen on the same bar.

I think I have it though. I can declare a global variable for each signal, set it to a high number and then add conditions in each individual signal part. If the global is greater than the span of bars I want to cover (which will always be true the first time around), the calculations are done, if not, the entry signal is set to true. If the calculations are done and trigger an entry signal, the global variable is reset to the current bar (using iBarShift) and an entry signal is given.

The first time through, calculations will always be done. If an entry signal is generated, the global will be reset to 0 and the next time through, it will bypass the calculations (because it is now lower than the span of bars I want to cover) and keep the entry signal as true. After each bar is generated, the global will increase by one. When the global value exceeds the span of bars I want to cover, it will be just like it was at the start (the global being greater than said span of bars) and it will go back to doing calculations. If another signal is triggered, it will repeat the process.

I think it should work but, I could be missing something (wouldn't be the first time, nor the last).

Thanks for the help guys. It would have taken me a while to find ibarShift. I am still very wet behind the ears when it comes to programming.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 01-15-2009, 07:43 PM
Junior Member
 
Join Date: Dec 2008
Posts: 12
rwb181 is on a distinguished road
Well, either my idea is right and my coding is wrong or my idea is wrong and my coding is right or both my idea and my coding is wrong. Either way, it doesn't appear to be working.

I'll keep at it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What best indicator to entry signal ? riskyachtar Indicators - Metatrader 4 17 08-24-2008 01:25 PM
How to get EA to remember value of variable from one tick to next? carpe193deim Metatrader 4 1 12-06-2006 08:47 AM
Dont remember but jyrik Expert Advisors - Metatrader 4 0 11-03-2006 06:03 AM
One Entry Per Bar.... babarmughal Expert Advisors - Metatrader 4 4 06-06-2006 01:56 AM
One entry per BUY ORDER babarmughal Expert Advisors - Metatrader 4 1 05-14-2006 02:18 PM


All times are GMT. The time now is 05:48 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.