exit nBars from entries - not BarsSinceEntry
exit nBars from entries - not BarsSinceEntry
Can someone point me towards a bar count function or similar in MC. I am testing a strategy that enters on successive days while the trend is established. I would like to evaluate results using exits nBars from entries, where n is constant. The function “BarsSinceEntry” only counts from the bar of the first entry, so all open positions are treated, and exited, as one position. I want to scale out, position by position. Assuming I give a personal label to each entry, is it possible to tie an exit to each entry, if nBars have elapsed? could someone recommend an approach I should take to achieve this? Many thanks in advance
-
- Posts: 100
- Joined: 17 Jul 2009
- Location: Germany
Thanks geektrader, but this function closes all open positions and cannot be attached to individual positions, confirmed here :
http://forum.tssupport.com/viewtopic.ph ... sinceentry
so I am looking for a function that will do this, or, the approach I should take to do this (e.g. a bar counter variable ?) thanks
http://forum.tssupport.com/viewtopic.ph ... sinceentry
so I am looking for a function that will do this, or, the approach I should take to do this (e.g. a bar counter variable ?) thanks
-
- Posts: 11
- Joined: 04 Jan 2011
Re: exit nBars from entries - not BarsSinceEntry
Hi auscan, did you ever figure this out? I've got the same problem, I'm entering multiple positions and need a way to check how many bars ago the last position was entered.
If I could figure out a way to confirm that a Buy order was placed I could just count from there.
If I could figure out a way to confirm that a Buy order was placed I could just count from there.
Re: exit nBars from entries - not BarsSinceEntry
Auscan & Sean,
you have to think about a structure for any position with the "contracts" statement. May you have to extend this through a maxposition-variable to compare it bar by bar with your current position. That means like this (very simple example) :
It should be something like this. I've not tested it so far. It's just to open your mind how the structure of the code should like be. May you provide us with more rules you have we can go on with further help in coding your project.
Regards.
Mike
you have to think about a structure for any position with the "contracts" statement. May you have to extend this through a maxposition-variable to compare it bar by bar with your current position. That means like this (very simple example) :
Code: Select all
input: lots(1); // how much to buy/sell per entry
input: maxpos(5); // max lots of position to hold for all signals
var: poslots(0); // variable for lots which are currently held
var: cond1long(false); // buy condition for 1st lot of overall position
var: cond2long(false); // buy condition for 2nd lot of overall position
var: count1(0); // count for the 1st entry
var: count2(0); // count for the 2nd entry
var: mp(0); // shorter definition of marketposition
poslots = currentcontracts; // current contracts which are held in position
cond1long = (poslots < maxpos) and a>b; // entry condition for 1st buy (long)
cond2long = (poslots < maxpos) and c>d; // entry condition for 2nd buy (long)
cond1exit = count1=5; // exit 1st long if 1st entry is 5 bars away
cond2exit = count2=9; // exit 2nd long if 2nd entry is 9 bars away
if cond1long then begin
buy lots contracts at market;
count1=count1+1;
end;
if cond2long then begin
buy lots contracts at market;
count2=count2+1;
end;
if mp>0 and count1=5 then begin
sell lots contracts next bar at market;
count1=0;
end;
if mp>0 and count2=5 then begin
sell lots contracts next bar at market;
count2=0;
end;
......
Regards.
Mike