12-29-2011, 09:30 PM
|
#1 |
Join Date: Nov 2008 Location: Northeast U.S. Thanks: 373
Thanked 231 Times in 164 Posts
| Enough Profit, Check Profit Here is some object oriented code that I am using in a bigger program to check for a profit threshhold before allowing the program to take profit. It checks for both long and short profit in the current position. If the position goes flat, everything is reset. This code uses the PositionsProvider1 class object. Open the toolbox and drag PositionsProvider1 into the code editor. An icon will appear at the bottom of the code editor. Code: var: intrabarpersist ShrtProfitOK(False), intrabarpersist LngProfitOK(False),
intrabarpersist MostGain(0), intrabarpersist CrrntPL(0);
Method void EnoughProfit()
var: int FlatLngShrt;
Begin
If PositionsProvider1.Count <> Null then begin
FlatLngShrt = PositionsProvider1.Position[0].Type; // Type is Flat, Long or Short
CrrntPL = PositionsProvider1.Position[0].PLPerQuantity; // Profit or Loss divided by Position Qty
End
Else Return; // If Positions Provider is Null, then end the method here
If FlatLngShrt = 0 then Begin // 0 is flat
ShrtProfitOK = False;
LngProfitOK = False;
MostGain = 0; // Reset to zero, if you are flat
CrrntPL = 0;
Return;
End;
{Determine what the most profit this position attained is, and maintain that unless it goes
to a loss}
if CrrntPL > 0 and CrrntPL > MostGain then
MostGain = CrrntPL
Else if CrrntPL < 0 then
MostGain = CrrntPL;
// If the most gain this position has attained is less than the threshhold
If MostGain <= 12.5 then Begin
ShrtProfitOK = False; // Indicate that profit level is not OK
LngProfitOK = False;
End
Else If FlatLngShrt = 1 and MostGain > 12.5 then // 1 is Long
LngProfitOK = True
Else If FlatLngShrt = -1 and MostGain > 12.5 then // -1 is Short
ShrtProfitOK = True;
End;
__________________ Precise, "dialed-in", targeted combination setups, like opening a combination lock; is the experience you should be having while trading. Dial left, right, left, . . . click - the lock opens. |
| |