PureBytes Links
Trading Reference Links
|
Jody,
What is happening is that PositionProfit(1) will give
you the profit of the last trade, but the if statement
will be true on every bar after a wining trade is
closed. So if trade #2 happens 15 bars after the 1st
trade closed, then Num will have a value of 15, as 15
bars went by where your if-then statement was
evaluated true. What you want is something like:
> Variables: Num(1), MarketPos(0);
>
> MarketPos = MarketPosition;
> If PositionProfit(1) < 0 Then Num = 1;
>
> If MarketPos = 0 and MarketPos <> MarketPos[1] then
> If PositionProfit(1) > 0 Then Num = Num + 1;
>
> Buy Num Contracts Blah Blah;
This will increment Num by one only the bar after the
trade is closed, or to be more exact, after
marketPosition changes.
Victor Cuadra
www.cuadraE.com
--- Jody Ellis <ellis_jody@xxxxxxxxxxx> wrote:
>
> I am trying to play around with an martingale type
> position sizing formula
> that adds another contract with each winning trade.
> Below is the code I have
> used and have tried many variations, but I cannot
> seem to get it to work.
>
> The idea is once I have a loss, the num variable
> returns to 1 and starts
> again. So, if I have a win, then num goes to 2 for
> the next trade. If I have
> 2 winners, num goes to 3 etc,etc. I want the system
> to increase with a new
> contract with each consecutive win.
>
> I have read many times that Anti-Martingale
> strategies work best, but I just
> want to see the differences for myself. I have tried
> this on an S&P system
> and after the first winner of 1 contract the system
> then buys amounts like
> 11, 76, 27 etc on the next trade. Can somebody help
> me out? Here's the code:
>
> Variables: Num(1);
>
> If PositionProfit(1) < 0 Then Num = 1;
> If PositionProfit(1) > 0 Then Num = Num + 1;
>
> Buy Num Contracts Blah Blah;
>
> I have also tried this code but it still won’t count
> correctly:
>
> Variables: Num(1);
>
> If PositionProfit < 0 Then Num = 1;
> If PositionProfit >= 0 Then Num = Num + 1;
>
> Buy Num Contracts Blah Blah;
>
> I have also tried setting the PositionProfit up as a
> variable and referring
> to it, but still no joy. Here’s that attempt:
>
> Variables: Num(1), PP(0);
>
> PP = PositionProfit;
>
> If PP < 0 Then Num = 1;
> If PP >= 0 Then Num = Num + 1;
>
> Buy Num Contracts Blah Blah;
>
> Any ideas? Thanks.
>
>
>
=====
Victor Cuadra
www.cuadraE.com
|