NexusFi: Find Your Edge


Home Menu

 





Finding Max Open Profit


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Turbosteve with 6 posts (1 thanks)
    2. looks_two Jura with 2 posts (2 thanks)
    3. looks_3 NW27 with 2 posts (2 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 5,433 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 10 posts
    2. attach_file 0 attachments




 
Search this Thread

Finding Max Open Profit

(login for full post details)
  #1 (permalink)
 Turbosteve 
Sydney Nsw Australia
 
Experience: Intermediate
Platform: Amibroker, Multicharts
Broker: I.B, CQG
Trading: NQ, 6E, SPI
Posts: 18 since Jun 2012
Thanks Given: 50
Thanks Received: 8

Hi All

Im trying to plot a trailing stop on my chart of the current open trade. I need to find the Max profit that was achieved with the aim of closing the trade when 50% of the open profit is lost. I have tried OpenEntryMaxProfitPerContract and MaxContractProfit but its not getting the result I hope for. It appears to be using the second last bar, not the last bar to work out the Max Profit (I think).

Heres some code I have been playing with;


if LastBarOnChart then
begin

nMaxProfit = OpenEntryMaxProfitPerContract(0); // current position max profit
nTL_TrailStop = nMaxProfit * ( nTrailPercStop_i/100 ); // default 45%
nTrail = ( entryprice(0) + nTL_TrailStop );
nTL_St_Date = currentdate ;
nTrailingStopLine = tl_new(nTL_St_Date -1 ,0100, nTrail, nTL_St_Date,2300, nTrail);
tl_setsize( nTrailingStopLine , 3);
tl_setcolor( nTrailingStopLine , green);

end;

Theres probably an easy solution which doesnt involve Highest High or something like like.

Stephen

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trader Dale [email protected] or Scammer Dale
Trading Reviews and Vendors
Volume profile TradeStation
EasyLanguage Programming
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ISO Equity Curve Indicator
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
GFIs1 1 DAX trade per day journal
28 thanks
Tao te Trade: way of the WLD
21 thanks
Diary of a simple price action trader
17 thanks
Deaddogs Stock Trading
14 thanks
Daytrading ES & NQ
14 thanks

(login for full post details)
  #3 (permalink)
 Turbosteve 
Sydney Nsw Australia
 
Experience: Intermediate
Platform: Amibroker, Multicharts
Broker: I.B, CQG
Trading: NQ, 6E, SPI
Posts: 18 since Jun 2012
Thanks Given: 50
Thanks Received: 8


I think LastBarOnChart is actually triggered for the second last bar?

This could be causing the last bar not to be evaluated?

Started this thread Reply With Quote
(login for full post details)
  #4 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


Turbosteve View Post
I think LastBarOnChart is actually triggered for the second last bar?

This could be causing the last bar not to be evaluated?

If you have bars with minute time stamps (HHmm, for example 8:09 am) then LastBarOnChart is triggered on the last bar. However, if you have bars with seconds time stamps (HHmmss, 8:09:34 am), then LastBarOnChart_s should be used.

Btw, just always use LastBarOnChart_s since that also works correctly with minute bars.

Btw 2, if you intend to backtest this code, it might be advisable to use MarketPosition instead of LastBarOnChart_s. Something like this:

 
Code
if (MarketPosition(0) <> 0) then begin 

	nMaxProfit = OpenEntryMaxProfitPerContract(0); // current position max profit
	// other code here

end;

Reply With Quote
The following user says Thank You to Jura for this post:
(login for full post details)
  #5 (permalink)
 Turbosteve 
Sydney Nsw Australia
 
Experience: Intermediate
Platform: Amibroker, Multicharts
Broker: I.B, CQG
Trading: NQ, 6E, SPI
Posts: 18 since Jun 2012
Thanks Given: 50
Thanks Received: 8

Im now very sure that it is evaluating the second last bar not the last.

Any Idea's how to evaluate the Last bar as well. Its in a Signal not indicator.

Started this thread Reply With Quote
(login for full post details)
  #6 (permalink)
 Turbosteve 
Sydney Nsw Australia
 
Experience: Intermediate
Platform: Amibroker, Multicharts
Broker: I.B, CQG
Trading: NQ, 6E, SPI
Posts: 18 since Jun 2012
Thanks Given: 50
Thanks Received: 8

Thanks Jura

Im using the code in a Signal and test MarketPosition(0) = 1.

I think the problem is Im using it on Daily Bars only. I dont have access to intra day data as Im still evaluating Multicharts (for the last 2 weeks). I will be backtesting on intra day data once I buy Multicharts.

Perhaps this problem I am coming up with is a limitation which is exposed only on Daily Data. On an intra day Signal test I would be using 5min and 1hr charts and then the issue is not such a big deal.

Your thoughts?

P.S I have been reading some of your replies last night. Your obviously a very good programmer.

Started this thread Reply With Quote
The following user says Thank You to Turbosteve for this post:
(login for full post details)
  #7 (permalink)
 
Jura's Avatar
 Jura   is a Vendor
 
Posts: 775 since Apr 2010
Thanks Given: 2,352
Thanks Received: 690


Turbosteve View Post
I think the problem is Im using it on Daily Bars only.

That's possible; I've also experienced problems with the last daily bar not being evaluated by the code. It turned out that I had the wrong session template with an instrument with a exchange time zone that was different from mine.

You can change the session template by double-clicking on the instrument, tab Settings, and then Sessions.

Btw, you can easily test if the code processes all bars (including the last) with:
 
Code
Print("Bar date time: ", FormatDate("dd-MM-yyyy", ELDateToDateTime(Date)), FormatTime(" HH:mm:ss", ELTimeToDateTime_s(Time_s)));
The information in the PowerLanguage Editor output log will then show for the last bar the same date time as on the chart. If that's not the case, you may need to change your session settings.

Reply With Quote
The following user says Thank You to Jura for this post:
(login for full post details)
  #8 (permalink)
 NW27 
Newcastle, Australia
 
Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker: IB
Trading: SPI,FTSE100, 6E, 6A
Posts: 285 since Oct 2010
Thanks Given: 108
Thanks Received: 188

Why can't you just use the current bars high price - entry price.


Sent from my GT-I9100T using Tapatalk 2

Reply With Quote
(login for full post details)
  #9 (permalink)
 Turbosteve 
Sydney Nsw Australia
 
Experience: Intermediate
Platform: Amibroker, Multicharts
Broker: I.B, CQG
Trading: NQ, 6E, SPI
Posts: 18 since Jun 2012
Thanks Given: 50
Thanks Received: 8

Jura

The last bar Date printed was the second last bar Date not the last bar Date (today). Changing session template or timezone didnt help either. Im from Australia and testing on the XJO daily data. Thanks for the help though.

Hi NW27

High will give you the high of the second last bar in a Signal. Obviously in an Indicator it will give you the last bar.

I tried this a few hours ago;

nMaxProfit = Highest(high[0], barsSinceEntry) - entryprice(0);

Again its looking at the second last bar even though the Last bar (today) is higher.

I think its how the Multicharts backtesting engine works. It will give the correct signal on the next bar as it assumes you cant give a signal until the bar is closed AND the next bar is opened. Like setting a buy / sell on next bar. eg sell ("Above 3 Week 50% Stop") next bar at (MyWeekly50 - 10) Stop;

BTW NW27. I have been reading this forum for a few weeks and notice you trade SPI. I want to get historical SPI data and a live data feed. Any hints? ( I have been using IG Markets for a few years but want to backtest and auto execute).

Started this thread Reply With Quote
(login for full post details)
  #10 (permalink)
 NW27 
Newcastle, Australia
 
Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker: IB
Trading: SPI,FTSE100, 6E, 6A
Posts: 285 since Oct 2010
Thanks Given: 108
Thanks Received: 188


Steve
For a quick fix of SPI data, goto Ampfutures and get a demo multicharts user account.

Neil

Sent from my GT-I9100T using Tapatalk 2

Reply With Quote
The following 2 users say Thank You to NW27 for this post:





Last Updated on July 4, 2012


© 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