Hi,
can someone help me with this please. I wanna CoverAtMarket if the prvious Close is higher than the Entry Close - if not than "else if". I have try it but i do not get it. For a better undestanding see the picture.
CODE:
Please log in to see this code.
Size:
Color:
This code compares apples to oranges (bar minus entry price):
CODE:
Please log in to see this code.
Instead, I think you're after this:
CODE:
Please log in to see this code.
If you really intended to introduce an artificial delay of 1 bar and compare the previous close (vs. the current bar's Close) then that would be:
CODE:
Please log in to see this code.
Size:
Color:
Hi Eugene,
thanks.
Something don't work correctly.
Entry Close (07.08.) at 65.48
Next Bar Close (08.08.) at 65.13
In this case should "els if" takes action. Because the Current Close is deeper than the previos Close. Slider12 are 2 days.
Only if the current Close is higher than the previos Close, than ExitAtMarket +1 instatt of "slider12" (else if).
Do you have an idea?
Size:
Color:
Damir,
It works exactly as requested. The entry bar is "green" (C > O) so the exit happens on the next bar at open.
P.S. Both your "if" and "else if" signals are AtMarket so to discern them your code might benefit from adding an EntrySignal.
Size:
Color:
Eugene,
It's my fault.
I meant if the "red" bar Close compares with the "green" Entry Bar Close is deeper than should "else if" take aktion. If not than ExitAtMarket next day.
The picuture "ifTakeAction.
The Entry Close is 178,52 "blue bar"
The next bar Close is 178,86" also a blue bar".
In this case the ExitAtMarket should take action on the "green" bar instead of the "red" bar. 1 day erlearier.
I hope it is more understanable now!
Size:
Color:
QUOTE:
In this case the ExitAtMarket should take action on the "green" bar instead of the "red" bar. 1 day erlearier.
That's what code in post #2 should already do: exit one bar earlier than "ifTakeAction.jpg" shows.
Hint: choose PNG over JPG - the latter is suboptimal for charts and screenshots. See
JPEG or PNG – Which Image Format Offers Better Quality?If you like to get further, consider writing your exit logic in pseudocode without ambiguity (e.g.
if C[bar] > C[bar-1] then A, else if O[EntryBar] < H[bar-2] then B etc).
Size:
Color:
Thanks Eugene.
Size:
Color:
Hi Eugene,
pseudocode:
If Close[EntryBar] is bigger than the next day bar Close[bar +1] than ExitAtMarket (on third bar) Open[bar +1] (BarsHeld3)
else if
Open [EntryBar] >= 2 days, than ExitAtMarket Open[bar + 1 ] (BarsHeld 4)
So, i should have in my trade list only 3 or 4 BarsHeld. And 2 BarsHeld olny, if the Limits take Action.
That's why i don't understand the picuture. In this case should "else if" take Action. Open[EntryBar], 1day, 2day and ExitAtMarket Open[bar+1]. And not Next Day after Open[EntryBar]. Maybe the error is that, the first argument should be a "double" and the "second" an int.
If you like i can show you the hole Code.
Size:
Color:
Hi Damir,
QUOTE:
If Close[EntryBar] is bigger than the next day bar Close[bar +1] than ExitAtMarket (on third bar) Open[bar +1] (BarsHeld3)
Makes sense. The next day's close is Close[p.EntryBar + 1]. By analogy, replace
Close with
Open to get the open of that bar.
CODE:
Please log in to see this code.
Also, take precaution against a runtime error if the LastPosition is taken at Bars.Count-1 (compare bar number to not exceed the boundary). We'll get to it once you address my concern below:
QUOTE:
Open [EntryBar] >= 2 days,
I don't follow since that's comparing apples to oranges again. Could you rephrase this:
Open [EntryBar] >= 2 days, than ExitAtMarket Open[bar + 1 ] (BarsHeld 4)
Size:
Color:
Let me try it with the code. I think in the code it's clearer.
Please, see the Attachment.
TXB = TimeBasedExit.
Size:
Color:
So this is a time-based exit; you already know what to do. Here's the missing piece:
CODE:
Please log in to see this code.
Size:
Color:
Hi Eugene,
thank you so far.
I have check the trades.
Sometimes it works fine, sometimes doesn't. I don't know why. Maybe you have an idea.
I have two pictures, see attachments. in both pictures, should happen something others. Namely, like in the code. What do you think?
CODE:
Please log in to see this code.
Size:
Color:
Damir, I stand corrected. One thing in my code is wrong -- it may peek into the future:
CODE:
Please log in to see this code.
You cannot exit at market this bar when EntryBar + 1 == bar+1 - in this case, Close[bar+1] happens after the exit is made at the market open. This is impossible. To ensure this doesn't occur you must append a condition like you already have in your code below to this exit, too:
CODE:
Please log in to see this code.
Our team is currently busy with internal projects. To help troubleshooting of your code, consider naming your exits as per post #4 above. This, along with inspection of variable states under VS debugger, should clear up all doubts you may have regarding how your simple rules work. Good luck.
Size:
Color:
Thank you for the quick response Eugene.
Size:
Color: