| / | Forum |
|
golden188
2007.09.25 00:50
I am working on an EA and one problem I have come across is that sometimes, a trade
will open, and quickly hit it's limit and I will get the profit. However, new trades
will open in the same bar and I will lose money on those. How can I limit one trade
per bar posted on the chart? For example, if a trade closes in the current bar,
I don't want another trade to be able to open until the new bar is posted. Can
someone give me that language?
|
|
Interview with Jimmy Tirtawangsa (fireflies) Gorez does a good job by predicting that GBPJPY will go south for many weeks. |
|
janklimo
2007.09.25 02:26
int BarsCount = 0; int start() { if (Bars > BarsCount) { //your code to be executed only once per bar goes here BarsCount = Bars; } return(0); }Define a global variable BarsCount. The integer Bars stores the number of bars in the current chart. Once a new bar is added on the chart, your code is executed but then you set BarsCount = Bars, so it will be executed again only when a new bar appears. BarsCount is initially set to 0, so your code is executed the very first time you load the indicator. Jan |
|
NTrader
2007.09.29 17:03
@ janklimo: And if I would evaluate the situation to enter long or short only at
the end of the bar? I mean the close of the bar.
|
|
janklimo
2007.09.29 18:41
NTrader wrote: The open of the new bar comes only one tick after the close of the old bar, so
using the new bar to do the evaluation is the most precise, in my opinion. But
if you really want to do the operation just before the bar close, check whether
the current time is greater of equal to the next bar open time minus a couple of
seconds.@ janklimo: And if I would evaluate the situation to enter long or short only at the end of the bar? I mean the close of the bar. |
|
golden188
2008.02.26 22:04
I'm sorry if I come off as an idiot, but what does this code mean? I don't see how this could limit the EA to only opening 1 trade per bar. How does that work? Also, what does BarsCount=Bars mean? Since you are saying Barscount=Bars, how could Bars > BarsCount work? Don't you say later that they are equal?
|
|
devilian1899
2008.02.26 22:16
Nevermind.... :)
|
|
phy
2008.02.26 22:26
golden188: WHEN is the line BarsCount = Bars executed? WHEN does the expression Bars > BarsCount evaluate as True? |
|
golden188
2008.02.28 04:02
First off, I should say that I am basing my EA off of the MACD Sample EA that was available (and still may be) on this site. I guess I just don't understand where it should go in this code: extern double TakeProfit = 50; //+------------------------------------------------------------------+ total=OrdersTotal(); what i have assumed is that it goes where the language "if Bars<100" currently is. However, I wasn't sure... phy, i appreciate your patience. |