London, UK
Posts: 2 since Oct 2013
Thanks Given: 1
Thanks Received: 0
|
hi everyone,
i tried to incorporate a methodology into my strategy that had been described by Big Mike in one of his tutorials (VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy ). based on the entry price the strategy should come up with multiple stop loss and limit (take profit) orders. to keep it simple i am for now only trading one contract and therefore for each trade the strategy will only place one stoploss and one takeprofit order. i've been trying to get my head around the following problem for the past few hours but couldn't find any solution to it:
whereas the system enters a long/short position ok, it seems like when calculating stoploss and take profit level the strategy might not be using the correct entry price. it seems to be closing out trades on a rather random basis.
(for additional info i'm backtesting on FGBL futures and i am using a 1min chart).
please see code below:
inputs: stopsize(8), tp (10);
vars: ticksize (minmove/pricescale), tgt1 (tp*ticksize), st1(0), longentryprice(0), shortentryprice(0);
//enter position (only at the close of bar):
if barstatus(1) = 2 then begin
if marketposition = 0 and condition1 then
buy("enter long") next bar 1 contracts at close limit;
longentryprice = entryprice;
if marketposition = 0 and condition2 then
sellshort ("enter short") next bar 1 contracts at close limit;
shortentryprice = entryprice;
end;
// trade management (which is causing issues):
if marketposition <> 0 then begin
if marketposition =1 then
st1 = longentryprice - (stopsize*ticksize);
sell ("longtarget_hit") 1 contracts next bar at (longentryprice + tgt1) limit;
sell ("longstop_triggered") 1 contracts next bar at st1 stop;
if marketposition = -1 then
st1 = shortentryprice + (stopsize*ticksize);
buytocover ("shorttarget_hit") 1 contracts next bar at (shortentryprice- tgt1) limit;
buytocver ("shortstop_triggered") 1 contracts next bar at st1;
end;
any help much appreciated,
cheers,
bermondsey
|