Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

Sign in to follow this  
Tradewinds

Enough Profit, Check Profit

Recommended Posts

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.

 

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; 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.