Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader Expert Advisors

MetaTrader Expert Advisors Post and discuss the MetaTrader expert advisors here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 13th May 2010, 14:42
Default Avatar
Junior Member
 
Join Date: May 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question My EA is trigger happy

Hi there,

My EA pulls the trigger multiple times on the same bar. As soon as a trade closes, and the buy/sell signal is till there, it opens another trade.

Is there anyway to postpone the next trade, or to ensure it doesn't trade again until at least another bar has opened? How can I have it check how long it has been since the last trade closed

Your help will be greatly appreciated!
MT
Reply With Quote
  #2 (permalink)  
Old 14th May 2010, 07:33
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,542
Thanks: 18
Thanked 20 Times in 16 Posts
Default

It's quite easy to do. You just have to add a code to check if the current number of bars is greater than the previous number of bars. Then you can continue trading if there were new bars and return if the amount of bars is the same. In MQL4 it would look like this:

MQL5 Code:
    if (LastBars == Bars) return(0);
    else LastBars = Bars;

Bars is a system variable for the amount of bars in the charts. LastBars should be declared as a global variable (int).

In MQL5 you just have to use Bars() function instead of the Bars variable:

MQL5 Code:
    if (LastBars == Bars(_Symbol, _Period)) return;
    else LastBars = Bars(_Symbol, _Period);

Hope that helps.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Happy Halloween - 50% Off! Linaddd Advertisements 0 1st November 2009 07:26
happy earnings forex forex-happy Advertisements 0 26th January 2009 00:50
Happy earnings forex-happy Advertisements 0 3rd January 2009 17:50


All times are GMT. The time now is 03:15.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Inactive Reminders By Icora Web Design

SEO by vBSEO 3.3.2