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)
My entry signal is simple. An outside bar on daily chart: If low of the previous bar is taken out first, I buy when also high of the previous bar is taken out. I use IOG and Bar Magnifier.
I want to exit (if possible) in the same bar as entry. The stoploss is filled at the correct place and price, but the profit target is always filled wrongly at open in the next daily bar, despite if profit target price was reached in the entry bar.
So, why does "next bar" mean the next tick for the stoploss line below, but means next bar(Daily) for profit target? Somebody who can help?
Code:
enterLong = (Low < Low[1]) and (MarketPosition(0) = 0);
if (enterLong) then begin
buyPrice = High[1] + 0.0001;
Buy ("Long") 1 contract next bar at buyPrice stop;
end;
if (BarStatus(1) = 2) and (MarketPosition(0) = 1) then
Sell ("XLPT") all contracts next bar at entryprice + profittarget or higher; //THIS LINE DOES NOT WORK! WHY?//
Sell ("XLSL") all contracts next bar at entryprice - stoploss or lower; //THIS LINE IS OK//
Can you help answer these questions from other members on NexusFi?
because you do this check "if (BarStatus(1) = 2) and (MarketPosition(0) = 1) then" in front of the profit order. It will be only checked at the end of the bar. The check won't affect the stop order and that's why this seems to work.
That solved the problem with exit in the wrong bar.
But as you see in pic1 the profit (XLPT) is taken at different levels, either on the high of the bar, or on the close of the bar. My profit target is in code test only 10 points above entryprice. and should have been filled before close/high. Code:
enterLong = (Low < Low[1]) and (MarketPosition(0) = 0);
if (enterLong) and (barssinceexit(1) >1 OR totaltrades <1)then begin
buyPrice = High[1] + 0.0001;
Buy ("Long") 1 contract next bar at buyPrice stop;
end;
if (MarketPosition = 1) then // If this line is deleted entry and exit is filled at the same price = no profit //
Sell ("XLPT") all contracts next bar at entryprice + profittarget or higher; // profittarget=10 p //
Sell ("XLSL") all contracts next bar at entryprice - stoploss or lower; // stoploss=10 p //
I don't know what you intend with the way you coded the stop and target orders (I know what you are trying I guess) as you didn't specify any order type.
Something like this might get you going. However an exit at the same bar than the entry is best done with intrabar order generation (hence the name).
I have tried using limit and stop order, and that gives the same result as "or higher/lower": in both cases profit target is filled at high or close of the bar. Not at +10 points as expected. I use Intrabar Order Generation, I wrote "IOG" above, sorry for not beeing clear. This is my entire compiled code:
[IntrabarOrderGeneration = true];
Inputs:
profittarget(0.0010),
stoploss(0.0010);
Variables:
enterLong(False),
buyPrice(0);
enterLong = (Low < Low[1]) and (MarketPosition(0) = 0);
if (enterLong) and (barssinceexit(1) >1 OR totaltrades <1) then begin
buyPrice = High[1] + 0.0001;
Buy ("Long") 1 contract next bar at buyPrice stop;
end;
if (MarketPosition = 1) then begin
Sell ("XLPT") all contracts next bar at entryprice + profittarget limit;
Sell ("XLSL") all contracts next bar at entryprice - stoploss stop;
end;