Welcome to the Traders Laboratory Forums.
TradeStation Custom Programming Discuss projects, ideas, obstacles in programming with TradeStation.

Reply
Old 12-29-2011, 09:30 PM   #1

Tradewinds's Avatar

Join Date: Nov 2008
Location: Northeast U.S.
Posts: 891
Ignore this user

Thanks: 373
Thanked 231 Times in 164 Posts
Blog Entries: 6

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.
Tradewinds is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chase Profit or Take Profit? parura Money Management 13 03-02-2011 10:27 AM
Stop After X Profit nab999 Coding Forum 1 06-02-2010 02:50 AM
Profit Target Levels thecloser Coding Forum 8 12-27-2009 09:54 AM
profit targets franky Beginners Forum 19 03-26-2007 06:13 PM
Dollar profit targets rally64 Brokers and Data Feeds 0 12-28-2006 02:04 PM

All times are GMT -4. The time now is 10:03 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.