multipleEntries question?

Questions about MultiCharts and user contributed studies.
Dug
Posts: 31
Joined: 26 Aug 2009
Location: London

multipleEntries question?

Postby Dug » 02 Sep 2009

I am having problems with multiple entries and exits. The problem i get is that when I pyramid longs and each long has a different stop, they ALL exit when the first stop has been hit. I have tried numerous different solutions from the forums etc; but i am stuck.

If i try something such as "X contracts total" to tell the program to exit a set number of contracts i get a workaround, but then when i portfolio back test the numbers get screwed up when i test using a percentage of the equity portfolio.

So I thought it had to be left as just trying match entries and exits. But as I said the first exit, exits every position. (Very infuriating)

the code basically just checks any stops, then checks for triggers buying a breakout high.....the issue seems to be in the checking the stops, and exiting all positions when the first stop is hit...
Any help would be much appreciated....thanks.

....................
inputs:ATRLen(30),BreakLen(40),FilterMA(120),longsOn(true),ShortsOn(true),On2(true),On3(false),On4(false), On5(false);
vars: Typ(0), TCount(0);
vars: nb1(0),nb2(0),nb3(0),nb4(0),nb5(0); {next buy levels}
vars: ns1(0),ns2(0),ns3(0),ns4(0),ns5(0); {next sell levels}
vars: Lstop1(0),Lstop2(0),Lstop3(0),Lstop4(0),Lstop5(0);
vars: Sstop1(99999),Sstop2(99999), Sstop3(99999), Sstop4(99999), Sstop5(99999) ; {stop levels}
vars: LT1(0),LT2(0),LT3(0),LT4(0),LT5(0);
vars: ST1(0),ST2(0),ST3(0),ST4(0),ST5(0); {trade on/off = 1/0}

{initialise}
if currentbar=1 then begin
cleardebug;
end;

{Entry triggers}
{conditions ##########################################}


condition1=high>Highest(high,BreakLen)[1] ; {initial Trigger}
condition2=low<lowest(low,BreakLen)[1];



{Check STOPS being Triggered on 1st contract##########################################}
{LONGS##########################################}
if low<Lstop1 and LT1=1 then begin
sell ("lx1") entry("le1") at this bar on close;

//sell ("lx1") entry("le1") 1 contract total at this bar on close;
//sell ("lx1") entry("le1") 1 contract total at next bar on open;

LT1=0;
Lstop1=0;

end;

if low<Lstop2 then begin
if LT2=2 then sell ("lx2") entry("le2") at this bar on close;
//if LT2=2 then sell ("lx2") entry("le2") at next bar on open;
LT2=0;
Lstop2=0;
end;




{Check NEW entries##########################################}
{LONGS##########################################}
if longson then begin
if condition1 and LT1=0 then
begin
{1st contract and stop}
buy ("le1") this bar on close;

LT1=1;
end;
{2nd contract##########################################}
if condition1 and On2 then begin
{1st contract}
if LT2=0 then begin
{buy ("le2") 1 contracts this bar on close;}
nb2=Close+(.5*AvgTrueRange(ATRLen));
Lstop2=Close-(1.5*AvgTrueRange(ATRLen)); {must leave here to turn off trigger}
LT2=1;
end;

{2nd contract}
if Close>nb2 and LT2=1 then begin

buy ("le2") this bar on close;
LT2=2;
nb2=99999;
end;
end;

end; //for longs on




{TRAIL STOPS##########################################}
{FirstContract}
if LT1=1 then begin
Lstop1=maxlist(Lstop1,close[1]-(2*AvgTrueRange(ATRLen)));
end;

{2nd Contract##########################################}
{if Lt2=2 then Lstop2=maxlist(Lstop2,Close-(2*AvgTrueRange(ATRLen)));
if ST2=-2 then Sstop2=minlist(Sstop2,Close+(2*AvgTrueRange(ATRLen)));}
{OR}
if Lt2=2 then Lstop2=maxlist(Lstop2,lowest(close,20)[1]);

messagelog(date,"-BE-", Close,"-LStop1-2-",LStop1,Lstop2,"-CE-",currentcontracts,currententries,"-HHL-",close[1]-(2*AvgTrueRange(ATRLen)),"-llv-",lowest(close,20)[1]);
Attachments
picture1.png
picture of the signals
(67.86 KiB) Downloaded 272 times

Dug
Posts: 31
Joined: 26 Aug 2009
Location: London

Postby Dug » 03 Sep 2009

Found it....
it was a bug as it did not work, and the TS people seem to have fixed it in 5.5 Beta version...


Return to “MultiCharts”