[Code] Daily Profit/Loss Target

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
geektrader
Posts: 100
Joined: 17 Jul 2009
Location: Germany

[Code] Daily Profit/Loss Target

Postby geektrader » 05 Mar 2010

Hi,

today I wanted to share a function that tells you the profit/loss you´ve made TODAY. It will reset at 0:00 to 0. The function is useful for daily profit/loss goals, just as an example.


Code: Select all

//Function: ProfitToday
variables: var0( 0 ) ;

var0 = 0 ;

for Value1 = 0 to 50
begin
condition1 = EntryDate( Value1 ) = Date;
if condition1 then
var0 = var0 + positionprofit( Value1 ) ;
end ;

ProfitToday = var0 ;


Here is an implementation example that closes the currently open trade and stops trading for the day once a daily profit goal of 150$, or a loss of 150$ has been made. Then it resumes trading at 0:00 of the next day. You would just add it to your existing strategy the following way.


In the INPUTS/VARIABLES section you add:

Code: Select all

input: MaxDailyProfitDollar(150);
input: MaxDailyLossDollar(150);
var: DailyProfitCondition(False);
var: DailyLossCondition(False);

Right before you strategy-code starts you add:

Code: Select all

DailyProfitCondition=ProfitToday < MaxDailyProfitDollar;
DailyLossCondition=ProfitToday > -MaxDailyLossDollar;

if DailyLossCondition and DailyProfitCondition then begin

//--YOUR EXISTING CODE STARTS HERE--

At the end of your existing strategy you add:

Code: Select all

//--YOUR EXISTING CODE ENDS HERE--

end;

if ProfitToday > MaxDailyProfitDollar+(MaxDailyProfitDollar*0.07) then begin
if MarketPosition = 1 Then Sell ( "DailyProfReachedLX" ) next bar at market;
if MarketPosition = -1 Then Buy To Cover ( "DailyProfReachedSX" ) next bar at market;
End;

if DailyLossCondition=false then begin
if MarketPosition = 1 Then Sell ( "DailyLossReachedLX" ) next bar at market;
if MarketPosition = -1 Then Buy To Cover ( "DailyLossReachedSX" ) next bar at market;
End;

engelmeyer elisabeth
Posts: 5
Joined: 03 Nov 2007

Postby engelmeyer elisabeth » 14 May 2010

Thanks,
the code works fine without any changes.
Elisabeth


Return to “User Contributed Studies and Indicator Library”