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;