Possible to breakeven/activate stop loss/exit a trade after…
9 replies
Threshold
9 years ago #112105
Possible to breakeven/activate stop loss/exit a trade after 24 Hours(bars)?
My strategy is a Daily bar strategy.
I want to breakeven after exactly 24 hours or exit if the trade is not winning after exactly 24 hours.
I see there is a “BarsSinceOrderOpen” option but this option has to timeframe option. Can you add it? Or are there other possibilities?
stearno
9 years ago #124337
Mark Fric
9 years ago #124363
you can do this by making a rule for this.
Something like:
IF(BarsSinceOrderOpen >= 1) // trade older than day
and OpenPL() > 0
THEN
move SL to BE
and another rule for closing the trade:
IF(BarsSinceOrderOpen >= 1) // trade older than day
and OpenPL() < 0
THEN
ClosePosition
Mark
StrategyQuant architect
Threshold
9 years ago #124383
You guys did not read the question fully or maybe I was unclear. My apologies.
BarsSinceOrderOpen>=1 is exactly what I said wont work because it has no timeframe option. What if the order was entered @ 23:00 yesterday? Then it breaks-even after only 1 hour. BarsSinceOrderOpen does not mean 24 hours. It simple means a new bar. This could be 1 hour 2 hour 3 hours 4 hours 5 hours….
I’m looking for break even after exactly 24 hours (or 24 H1 bars) for D1 strategy.
I need to do:
BarsSinceOrderOpen(Timeframe: PERIOD_H1) > 24
But there is no timeframe option.
My strategy is a Daily bar strategy.
I want to breakeven after exactly 24 hours or exit if the trade is not winning after exactly 24 hours.
I see there is a “BarsSinceOrderOpen” option but this option has *no timeframe option*. Can you add it? Or are there other possibilities?
Mark Fric
9 years ago #124435
ok, I got it. Unfortunately, this is not easy to solve right now, without adding timeframe option to Bars Since Order Open.
But you can do it using a custom function. Add the following functions in EA Wizard/code/CustomFunctions.mq4 file:
and then in EA Wizard in your condition you can call Custom Function: sqGetBarsSinceEntryH1(your magic number) >= 24
Mark
StrategyQuant architect
Threshold
9 years ago #124471
Awesome! Is there a way to apply this to TS activation?
I know how to with BE now.
This is my attempt to apply it to TS Activation.
TS Activation (variable) = TSAktivate
Threshold
9 years ago #124479
The EA wont load successfully after I changed the CustomFunctions.mq4 file.
I’ll upload it. Perhaps my editing was incorrect.
I copy and pasted all the code you provided and added to the end of the file.
Here is my work aswell:
JTamas
9 years ago #124484
I would try this:
1. make a variable : ‘opentime’
2. Rule1#: IF order opened this minute is true THEN assign variable opentime = hour(0 bars ago)
3. Rule 2# IF bars since order open = 1 and Timecurrent = GetTime(opentime, 0, 0)
THEN
whatever
Since you want to close after 24 hours it means that it will happen at the same time as it was opened just one day later.
Threshold
9 years ago #124492
Very simple approach, I do like it.
Tested it, but doesnt work.
Mark Fric
9 years ago #124520
Hi,
is it still not working? Can you attach your strategy here?
As I checked your CustomFunctions file you attached I didn’t see my functions added there, and it compiled correctly.
Mark
StrategyQuant architect
Viewing 9 replies - 1 through 9 (of 9 total)