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.
The following user says Thank You to bnichols for this post:
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)?
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:
The following user says Thank You to ehlaban for this post:
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!
Thanks for your help!