NexusFi: Find Your Edge


Home Menu

 





Bar Magnifier exit problem


Discussion in MultiCharts

Updated
    1. trending_up 1,575 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 1 attachments




 
Search this Thread

Bar Magnifier exit problem

  #1 (permalink)
Orjan
Stockholm Sweden
 
Posts: 20 since Apr 2012
Thanks Given: 12
Thanks Received: 2

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//

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
What broker to use for trading palladium futures
Commodities
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Orjan,

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.

Regards,
ABCTG


Orjan View Post
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//


Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
Orjan
Stockholm Sweden
 
Posts: 20 since Apr 2012
Thanks Given: 12
Thanks Received: 2


Thanks ABCTG,

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 //

Attached Thumbnails
Click image for larger version

Name:	Pic1.JPG
Views:	187
Size:	18.2 KB
ID:	172593  
Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Orjan,

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).

 
Code
if (MarketPosition = 1) then  
begin           
   Sell ("XLPT") all contracts next bar at entryprice + profittarget limit;  // profittarget=10 p //
   Sell ("XLSL") all contracts next bar at entryprice - stoploss stop;	    // stoploss=10 p //
end ;
Regards,
ABCTG


Orjan View Post
Thanks ABCTG,

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 //


Follow me on Twitter Reply With Quote
  #5 (permalink)
Orjan
Stockholm Sweden
 
Posts: 20 since Apr 2012
Thanks Given: 12
Thanks Received: 2

ABCTG,

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;

Reply With Quote




Last Updated on January 23, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts