Has anyone successfully programmed martingale position sizing in Tradestation? I am have trouble getting my code to work. if positionprofit(1)>=0 then size=1; if positionprofit(1)<= then size=size+1; The problem with this is that it calculates every bar, so "size=size+1" keeps counting after every bar. I have tried various tweaks but could not get it to work. It is especially problematic when a trade reverses a previous trade without any time in between.
i'm saying if profit from previous trade is profitable, then add 1 contract to the previous contract size if profit from previous trade is not profitable, then contract size =1
try this. tt=totaltrades; if tt>tt[1] then begin if positionprofit(1)>=0 then size=1; if positionprofit(1)<= then size=size+1; end;
thanks protrader. this is adding on size correctly when there are no bars in between trades. but when there are bars in between trades, it does not add on size.
actually, something strange is happening. i can't pinpoint the exact problem but sometimes it will add size, sometimes it won't.
This code works perfect. I don't know how else I can help without seeing the code and knowing exactly what is going on. _______________________________________________ vars: tt(0),size(1),lasttrade(1); tt=totaltrades; if tt>tt[1] then begin if positionprofit(1)>=0 then size=1; if positionprofit(1)<0 then size=size+1; end; if t=1330 then begin if lasttrade=1 then begin sell short size contracts this bar; lasttrade=-1; end else begin buy size contracts this bar; lasttrade=1; end; end; setexitonclose;
it does not seem to be working properly with this code. Code: vars: tt(0),size(1),lasttrade(1); tt=totaltrades; if tt>tt[1] then begin if positionprofit(1)>=0 then size=1; if positionprofit(1)<0 then size=size+1; end; buy size contract at highd(0) on stop; sell size contract at lowd(0) on stop; setexitonclose;