Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
You're getting multiple intrabar orders at exits likely because
1. bar magnifier is on
2. entry conditions exist at the time (i.e., fast MA > slow MA); and
3. Your profit exit*** is causing the trade to close very quickly--you might want to confirm you have the symbol settings (scale, movement and bigpointvalue) configured properly.
***
In general (i.e., even with bar magnifier off and no profit exit) new orders will be generated when the last trade closes if entry conditions exist.
bnichols -
I have bar magnifier on, but it doesn't seem to be an issue with other scripts I use. I have that profit target turned off for simplicity and all of the exits that follow the entries are "CloseTrade" exits. So it must still have something to do with the CloseTrade code...
If you think about the order of events in the code the CloseTrade exit is last and the last thing in that block is to turn the CloseTrade variable to False. So how could the next bar after re-entering (which also has a CloseTrade = False in it) still execute the CloseTrade Exit further down the code (which requires CloseTrade = True)?
ehlaban -
I don't see how using conditions would replace using the bool variable we have- is that what you are suggesting? I agree it would be simpler and clearer but I don't think the same end goal can be achieved.. ? unless I am missing something?
I now understand the logic about the CloseTrade better. It indeed is a switch.
A thing i noticed is that when exiting a trade next bar at market
it is possible that another buy is given in the same next bar due to the
IntrabarOrder etc etc. You could use sell this bar at close but this code works for me:
[IntrabarOrderGeneration = True]
inputs: Num1(40), Num2(60), Num3(18), profitamount(4000);
variables: CloseTrade(false);
If marketposition = 0 then
begin
CloseTrade = False;
if Average(close, Num1) Cross Above Average(close, Num2) then
buy ("long") next bar at market;
end;
if marketposition = 1 AND CloseTrade = False then
begin
if Close <= keltnerchannellower(Close, 25, 2.5) then CloseTrade = true;
end;
if marketposition = 1 AND CloseTrade = True then
begin
if Close > Average(Close, Num3) then sell ("CloseTrade") next bar at market;
end;
SetStopContract;
SetProfitTarget(profitamount);
Hi Ehlaban - I think you've solved this puzzle! I haven't had a chance to take a close look yet, but initially all seems to be functioning as it "should" even with intrabarorder gen!
Great job.
Thanks for your help!