use of "entryprice" in auto trading

Questions about MultiCharts and user contributed studies.
paul.robillard
Posts: 28
Joined: 22 Mar 2012
Has thanked: 4 times

use of "entryprice" in auto trading

Postby paul.robillard » 02 May 2012

Hello, I'm getting in & out of the market with this code. I suspect the "entryprice" is not computed for i see the takeprofit order = 5. Why ?


if .... then

Code: Select all

begin
   buy ("tiers1L") 1 contract next bar at market ;
   TP1L = (entryprice + 5)  ;
   SLL = (lowest(low,3) - 1) ;   
   end;
   
//   setstopposition ;
   setstoploss(SLL) ;
   setprofittarget(TP1L) ;


Thank you !

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Re: use of "entryprice" in auto trading

Postby TJ » 02 May 2012

paul.robillard wrote:Hello, I'm getting in & out of the market with this code. I suspect the "entryprice" is not computed for i see the takeprofit order = 5. Why ?


if .... then

Code: Select all

begin
   buy ("tiers1L") 1 contract next bar at market ;
   TP1L = (entryprice + 5)  ;
   SLL = (lowest(low,3) - 1) ;   
   end;
   
//   setstopposition ;
   setstoploss(SLL) ;
   setprofittarget(TP1L) ;


Thank you !


it is a timing issue...

When does "next bar at market" happens?

When can you get the entryprice?

paul.robillard
Posts: 28
Joined: 22 Mar 2012
Has thanked: 4 times

Re: use of "entryprice" in auto trading

Postby paul.robillard » 02 May 2012

When does "next bar at market" happens?
... Next bar open
When can you get the entryprice?
... Next bar when the market order went trough.

Hmmm ... I should get my TP1L & SLL out of the BEGIN ?

youn56
Posts: 46
Joined: 29 Mar 2012
Has thanked: 13 times
Been thanked: 6 times

Re: use of "entryprice" in auto trading

Postby youn56 » 02 May 2012

Hi,
I think Your entryprice will take the value at the end of the bar, not before.
The first tick after your buy signal filled (but before the end of the bar), you initialise your takeprofit "TP1L" to entryprice+5---> 0+5.
Your limitprice (5 $/€) is probably immediatly executed.

paul.robillard
Posts: 28
Joined: 22 Mar 2012
Has thanked: 4 times

Re: use of "entryprice" in auto trading

Postby paul.robillard » 02 May 2012

I realise there are a number of things that are fundamentally different in backtesting signals & live trading signals. I would like to see a resource that points out those fundamental differences. That would certainly shorten my learning curve :)

paul.robillard
Posts: 28
Joined: 22 Mar 2012
Has thanked: 4 times

Re: use of "entryprice" in auto trading

Postby paul.robillard » 02 May 2012

Do you know what the workaround is ? Obviously i'm missing out ://

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Re: use of "entryprice" in auto trading

Postby TJ » 02 May 2012

paul.robillard wrote:Do you know what the workaround is ? Obviously i'm missing out ://


What seems to be the problem?

youn56
Posts: 46
Joined: 29 Mar 2012
Has thanked: 13 times
Been thanked: 6 times

Re: use of "entryprice" in auto trading

Postby youn56 » 02 May 2012

I think than the IOG option could resolve your problem or this code:
if marketposition = 1 then begin
TP1L = (entryprice + 5) ;
sell next bar at TP1L limit;
end;

But with this code, your "TP1L" will be set at the end of the bar.
Last edited by youn56 on 02 May 2012, edited 1 time in total.
These users thanked the author youn56 for the post:
paul.robillard

paul.robillard
Posts: 28
Joined: 22 Mar 2012
Has thanked: 4 times

Re: use of "entryprice" in auto trading

Postby paul.robillard » 02 May 2012

What is the "IOG option" ?

youn56
Posts: 46
Joined: 29 Mar 2012
Has thanked: 13 times
Been thanked: 6 times

Re: use of "entryprice" in auto trading

Postby youn56 » 02 May 2012

format signal-->format-->properties-->Enable Intra-Bar Order Generation

User avatar
JoshM
Posts: 2080
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1483 times
Contact:

Re: use of "entryprice" in auto trading

Postby JoshM » 02 May 2012

paul.robillard wrote:I realise there are a number of things that are fundamentally different in backtesting signals & live trading signals. I would like to see a resource that points out those fundamental differences. That would certainly shorten my learning curve :)

There are not that many big differences between real-time trading and backtesting in my view, it's more a difference between 'average', 'good' and 'better' coding.

I would suggest starting with the sticky posts from TJ in the FAQ forum, the documentations pdf and off-course the Wiki. I didn't saw a SetStopContract function in your code, perhaps that might be worth trying. The use of MarketPosition, AvgEntryPrice and (if you choose to use IOG) BarStatus are functions to make the coding life (quite) easier. And don't forget to track & debug your code with Print. :)

Anyway, there is an wiki article about Backtesting vs Live Trading.
These users thanked the author JoshM for the post (total 2):
evdlpaul.robillard


Return to “MultiCharts”