# 4 points sqew in auto trading

Questions about MultiCharts and user contributed studies.
paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

### 4 points sqew in auto trading

Here i have a simple code, based on what i gathered. It works ok (it's done to generate orders, not necessarely profit;) I hope to learn the basics of auto trading from it. So 3 bars up i buy, 3 bars down is short, stoploss & takeprofit @10 points. Nothing fancy.

Now when the order occurs i get a spread of 20 points between my profit and loss limit. That makes sense, since i set those to 10 points each. The problem is that i expected this to be set on entryprice. And it does not correspond, examples:

Entry price 69, TP75 * SL55. I would expect entryprice in the middle of TP-SL @ 65.
Entry price 77, TP83 * SL63. I would expect entryprice in the middle of TP-SL @ 73.
Entry price 83, TP97 * SL77. I would expect entryprice in the middle of TP-SL @ 87.
Entry price 80, TP94 * SL74. I would expect entryprice in the middle of TP-SL @ 84.
Entry price 56, TP42 * SL62. I would expect entryprice in the middle of TP-SL @ 52.
Entry price 38, TP24 * SL44. I would expect entryprice in the middle of TP-SL @ 34.

... etc ... There is allways that same 4 points sqew between the figures. Also, this 4 points sqew bring my stoploss 4 points closer and my takeprofit 4 points further. Can someone explain why ?

Code: Select all

`variables:TP(10) , {Points to Take Profit }SL(10)  {Points to Stop Loss };[IntrabarOrderGeneration = True]; ////////////////////////////////////{entry Long }if (marketposition = 0) and (high >= high[1]) and (high[1] >= high[2]) and (high[2] >= high[3])and (low >= low[1]) and (low[1] >= low[2]) and  (low[2] >= low[3]) then   begin    buy ("tiers1L") 1 contract next bar at market ;   end;if (marketposition > 0) then   begin   //   SetStopContract;    setstoploss(SL) ;   setprofittarget(TP) ;   end;   //////////////////////////////////////   {short }if (marketposition = 0) and (low <= low[1]) and (low[1] <= low[2])and (low[2] <= low[3])and (high <= high[1]) and (high[1] <= high[2]) and  (high[2] <= high[3]) then   begin    sellshort ("tiers1C") 1 contract next bar at market;   end;if marketposition < 0 then   begin//   setstopposition;   setstoploss(SL) ;   setprofittarget(TP) ;   end;   print(time,"  Entry: ", AvgEntryPrice_at_Broker_for_The_Strategy,"  ",entryprice,"  TP: ", TP,"  SL: ", SL);`

Thank you !

evdl
Posts: 400
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 123 times

### Re: 4 points sqew in auto trading

Can it have something to do with the difference between the avgentryprice and the fill price. Where the difference is the broker transaction costs. (avgentryprice = fillprice -/- transactioncosts). There are some post about this on the forum I think.
These users thanked the author evdl for the post:
JoshM

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

### Re: 4 points sqew in auto trading

I tough about that. The broker takes 2 euros commission not 2 points. 2 points is worth 20 euros. So no, i don't think it comes from there. Plus the trade cost should not influence the entry / exit levels ! should they ?! ...

JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1494 times
Contact:

### Re: 4 points sqew in auto trading

paul.robillard wrote:Plus the trade cost should not influence the entry / exit levels ! should they ?! ...

Like Evdl said, SetProfitTarget and SetStopLoss use the commission and slippage settings from the strategy settings (if I'm not mistaken).

Try adding the Commission and Slippage words to your output to see where the difference might come from. Otherwise, follow Evdl's suggestion about searching on the forum.

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

### Re: 4 points sqew in auto trading

ok, i just did that and 2 comes out under commisison. Does that mean i should take that commision out of the properties of the signal ?

My solution was to ajust the SL & TP accordingly, altrough i don't actually find this being the right thing to do. But it works !