[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What is wrong with this code?



PureBytes Links

Trading Reference Links

Hello all;

I've been racking my brains out trying to figure out why this code doesn't
pyramid like I think it should. I'm sure many of you can spot the problem
instantly and I'd sure appreciate your observations.

In short, when I think it should be setting up
to buy (sell) another contract on a stop, it reverses on the next bar.

I'm certainly open to suggestions for better code...

Thanks much for your thoughts!

Daniel Poiree


Input:    Length(20),
            Length(44),
            PyramidSw(0),               {0 is no Pyrimiding, 1 allows
pyramiding}
            PyramidTrigger(1),        {This is the percent that the price
must move to pyramid}
            BackTest(1),                  {Exit all trades on last bar if
set to 1}
            WriteToFile(1),
             StopLossPct(2);

Vars:    Buy_Signal(0),
            Sell_Signal(0),
            Buy_Another(0),
            Sell_Another(0),
            MP(0),
            Cts(0),
            StopLoss(0);

{{Basic code entered here}}

{Problem code below}

If PyramidSw = 1 then Begin
            If MP =  1 then Begin
                        If MP[1] <>  1 Then Buy_Another = EntryPrice * (1 +
(PyramidTrigger * 0.01));
                        If Buy_Another <> 0 Then Buy("Pyrimid_L")
Buy_Another Stop;
                        If Cts = 2 then Buy_Another = 0;
            End;
            If MP = -1 then Begin
                        If MP[1] <> -1 Then Sell_Another = EntryPrice * (1 -
(PyramidTrigger * 0.01));
                        If Sell_Another <> 0 Then Sell("Pyrimid_S")
Sell_Another Stop;
                        If Cts = 2 then Sell_Another = 0;
            End;
End;