Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
EasyLanguage Daily Profit and Daily Loss limit in strategy
Updated March 11, 2021
Top Posters
looks_one
ABCTG
with 6 posts (4 thanks)
looks_two
20YRTRADER
with 3 posts (0 thanks)
looks_3
AlexBa
with 3 posts (0 thanks)
looks_4
djplastic
with 2 posts (0 thanks)
Best Posters
looks_one
Big Mike
with 20 thanks per post
looks_two
Ranger
with 6 thanks per post
looks_3
insideday
with 3 thanks per post
looks_4
ABCTG
with 0.7 thanks per post
trending_up
32,812 views
thumb_up
36 thanks given
group
17 followers
forum
25 posts
attach_file
1 attachments
EasyLanguage Daily Profit and Daily Loss limit in strategy
March 25th, 2010, 02:46 AM
Manta, Ecuador
Site Administrator Developer Swing Trader
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,475 since Jun 2009
Thanks Given: 33,251
Thanks Received: 101,679
I needed this for my own strategies, so I wanted to share it here.
This will allow a dollar limit of daily loss and daily profit targets, whereby if one or the other is hit then the strategy will stop for the day.
If you wanted to make it weekly, it wouldn't be hard to do. The input for daily loss should be a + value (ie: "250" means a loss of 250, don't use "-250").
Code
// for use in signal inputs : dailyprofit ( 500 ), dailyloss ( 250 ); vars : todaynet ( 0 ), yesterdaynet ( 0 ); if date <> date [ 1 ] then begin yesterdaynet = NetProfit ; end ; if MarketPosition = 0 then begin todaynet = NetProfit - yesterdaynet ; end ; condition1 = - dailyloss < todaynet and todaynet < dailyprofit ; // entries if condition 1 then begin // put your long and short code here end ;
Condition1 evaluates to true if the profit for today is between the max loss and max profit. It evaluates to false if one or the other is exceeded. So place your entry code (buy/sellshort) inside the if block.
Let me know if it proves useful!
Mike
Thanked by:
Alexlaxmikant , Bullywig , Donovan2580 , Enalmada , ezrollin , FuManChou , Iluvchocmilk , JBroex , jsk123 , montanajtt , NGtrader , rossw , Sezor , Sharon9999 , TradingDrills , tradingonvolume , Trovatore , Vientomarsol , westsider , yeli
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
March 26th, 2010, 08:55 AM
Port St Lucie, FL
Posts: 46 since Jan 2010
Thanks Given: 9
Thanks Received: 48
Here's a variation of your signal BM; perhaps others may find this useful too.
RANGER
Attached Files
Elite Membership required to download: Net Profit and Time Limit Code Snippet(Signal).txt
March 27th, 2010, 09:32 AM
vienna
Posts: 22 since Aug 2009
Thanks Given: 0
Thanks Received: 38
This is the strategy template from the TS wiki , maybe it is useful for someone who wants to add some code lines to their straregy
Code
// EasyLanguageTemplate [ Strategy ]
// Just select features from the Template
// that you need for your strategy
// delete the ones you do not need.
[ IntraBarOrderGeneration = False ];
// True = Enables Entries or Exits
// on every Tick during the bar
// Much more complex coding
// If using IOG then Backtesting
// must have Look Inside Bar Testing
// activated to be approximately accurate
[ BaseCurrency = Account ];
// Can ONLY be put on Forex Symbol
// Give an error on non Forex symbols
// Forces account currency to be
// the default for reports, etc.
//[ SameTickOpt = True ];
// Can ONLY be put on Indicators
// Forces a change in price by one tick
// before TS will process code
//[ InfiniteLoopDetect = False ];
// Forces Loop Detection OFF
[ LegacyColorValue = True ];
// True = Old EL Colors as default
// False = New RGB Colors as default
Inputs:
SMAFLength(18),
SMASLength(34),
StartTime(945),
EndTime(1145),
LTrailingTicks(0),
STrailingTicks(0);
Variables:
//{ Setup Variables For Inputs }
vSMAFLength(0),
vSMASLength(0),
vStartTime(0),
vEndTime(0),
vLTrailingTicks(0),
vSTrailingTicks(0),
Price ( "" ),
Decimals( 0 ),
{ Daily NetProfits }
vNetProfit(0),
vDailyNetProfit(0),
{ Calculation Variables }
IntraBarPersist SMAFast(0),
IntraBarPersist SMASlow(0),
{ Trade High & Low }
IntraBarPersist TLHigh(0),
IntraBarPersist TLLow(0),
{ Daily High, Low, Open & Close when using IntraDay Charts }
IntraBarPersist PriorDayHigh(0),
IntraBarPersist PriorDayLow(0),
IntraBarPersist PriorDayOpen(0),
IntraBarPersist PriorDayClose(0),
IntraBarPersist TodayOpen(0),
IntraBarPersist TodayHigh(0),
IntraBarPersist TodayLow(0),
{ Weekly High & Weekly Low when using IntraDay Charts }
IntraBarPersist WeekHigh(0),
IntraBarPersist WeekLow(0),
{ Monthly High & Monthly Low when using IntraDay Charts }
IntraBarPersist MonthHigh(0),
IntraBarPersist MonthLow(0),
{ TradeStation Variables }
IntraBarPersist MP(0), // MarketPosition
IntraBarPersist MP1(0), // Prior Tick MarketPosition
IntraBarPersist PP(0), // PositionProfit
IntraBarPersist BSE(0), // BarsSinceEntry
IntraBarPersist BSExit(0), // BarsSinceExit
IntraBarPersist BarsLastExit(0),
IntraBarPersist CC(0), // CurrentContracts
IntraBarPersist CC1(0), // Prior Tick CurrentContracts
IntraBarPersist PPPC(0), // PositionProfit Per Contract
IntraBarPersist PPPE(0), // PositionProfit Per Entry
IntraBarPersist CE(0), // CurrentEntries
IntraBarPersist EP(0), // EntryPrice
IntraBarPersist AEP(0), // Average Entry Price
IntraBarPersist vBarNumber(0), // BarNumber
IntraBarPersist LastBar(False), // LastBarOnChart
IntraBarPersist vCategory(0), // Category
IntraBarPersist VCurrentBar(0),
IntraBarPersist CE(0), // CurrentEntries
IntraBarPersist PPTotal(0), // PositionProfit Total
OneTick(0),
vBarType(0),
vBarInterval(0);
//{ ++++++++++++++++++++++++++++++ }
//{ +++++++ CurrentBar = 1 +++++++ }
//{ ++++++++++++++++++++++++++++++ }
If CurrentBar = 1 then
begin
// Place code here you want processed ONLY on the First Bar of the Chart
//{ Category Setup }
vCategory=Category;
//{ Decimal Place SetUp by Goose }
Price = NumToStr( MinMove/PriceScale, 10 ) ;
for Value2 = 1 to 12
begin
if RightStr( Price, 1 ) = "0" then
Price = LeftStr( Price, StrLen( Price ) - 1 )
else
Value2 = 12 ; // stop loop when zero not found
end ;
Decimals = StrLen(Price) -2 ; // subtract 2 for decimals
{ One Tick }
OneTick = MinMove / PriceScale;
//{ Order Entry Routing SetUp For Stocks }
If vCategory = 2 then SetRouteName("ARCX");
//{ BarType - // 0=tick 1=IntraDay 2=Daily 3=Weekly 4=Monthly }
vBarType=BarType;
vBarInterval=BarInterval;
//{ Store Inputs into Variables - reduced CPU load }
vSMAFLength = SMAFLength;
vSMASLength = SMASLength;
vStartTime = StartTime;
vEndTime = EndTime;
vLTrailingTicks = LTrailingTicks;
vSTrailingTicks = STrailingTicks;
end;
//{ +++++++++++++++++++++++++++++++ }
//{ ++++ TradeStation Variables +++ }
//{ +++++++++++++++++++++++++++++++ }
//{ Get TradeStation Variables - use commands one time only to reduce CPU load}
LastBar = LastBarOnChart;
MP1 = MP; // Prior Tick MarketPosition
MP = MarketPosition;
EP = EntryPrice;
AEP= AvgEntryPrice;
PP = PositionProfit;
CC1 = CC; // Prior Tick CurrentContracts
CC = CurrentContracts;
CE = CurrentEntries;
If CurrentBar = 1 then
vBarNumber = 1
else
vBarNumber = vBarNumber[1] + 1;
{ TICK level BarsSinceEntry WorkAround }
// TradeStation BarsSinceEntry Command is
// Inaccurate with Stop & Reverse Entries
// or Scaling In Trades
// This workaround is always correct
If (MP <> 0 and MP1 = 0) // This tick in a Trade & Prior tick was Flat
or (MP = 1 and MP1 = -1) // This tick in a LONG Trade & Prior tick was SHORT Trade
or (MP = -1 and MP1 = 1) // This tick in a SHORT Trade & Prior tick was LONG Trade
or (CC > CC1) // Another Entry in the same direction
then
BSE = 0
else
If BarStatus(1) = 2 and MP <> 0 then // Increase BarSinceEntry Counter at End of Bar only
BSE = BSE + 1
else
If MP = 0 and MP1 <> 0 then // This Tick no trade & last tick was in a trade
BSE = -999;
{ or - Bar Level BarsSinceEntry WorkAround }
If (MP <> 0 and MP[1] = 0) // Current Bar in a Trade, Prior Bar Flat
or (MP = 1 and MP[1] = -1) // Current Bar Long, Prior bar Short
or (MP = -1 and MP[1] = 1) // Current Bar Short, Prior bar Long
or CC > CC[1] then // Scaling In Trade
begin
BSE = 0;
end
else
If MP <> 0
begin
BSE = BSE[1] + 1;
end
else
If MP = 0 then
begin
BSE = -999;
end;
{ BarsSinceExit WorkAround - Bar Level }
// TradeStation BarsSinceExit Command is Inaccurate with Stop & Reverse Entries and Scaling-In Multiple Entries
If MP <> 0 then
begin
BarsLastExit = 0;
end
else
If BarsSinceExit(1) = 0 or (MP = 0 and MP[1] <> 0) then
begin
BarsLastExit = BarsLastExit[1] + 1;
end;
{ BarsSinceExit WorkAround - Tick Level }
// TradeStation BarsSinceExit Command is Inaccurate with Stop & Reverse Entries and Scaling-In Multiple Entries
MP1 = MP;
MP = MarketPosition;
CC1 = CC;
CC = CurrentContracts;
If (MP = 0 and MP[1] <> 0) // This tick bar Flat and Prior tick was in a Trade
or CC < CC1 // this tick less contracts
begin
BSExit = 0; // New Exit Just Occurred this bar set BSExit Variable
// Place any code here you want executed on same bar as exit occurred
end
else
If BarStatus(1) = 2 then
begin
BSExit = BSExit[1] + 1; // Increase BSExit bar counter for number of bars since last exit occurred
end;
{ BarStatus(1) = 0 WorkAround }
// Code donated by Goose
// To process code on the First Tick of a Bar BarStatus(1) = 0 is problematic
// This workaround provides a reliable solution
[IntrabarOrderGeneration = True]
Variables:
IntrabarPersist Bar_Number( 0 ) ;
if Bar_Number <> CurrentBar then
begin
Bar_Number = CurrentBar ;
// Put code here you want processed on first tick of a bar
end ;
{ Position Profit Per Contract & Per Entry }
If CE > 0 and CC > 0 then
begin
{ PPTotal = PositionProfit Total }
PPTotal = PP;
{ PPPC = PositionProfit Per Contract }
If PPTotal <> 0 then
PPPC = PPTotal / CC;
{ PPPE = PositionProfit Per Entry }
If PPTotal <> 0 then
PPPE = PPTotal / CE;
end;
{ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ }
{ ++++ IntraDay Calculation of Daily High, Low, Open & Close ++++++ }
{ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ }
If Date <> Date[1] then
begin
PriorDayClose = Close[1];
PriorDayHigh = TodayHigh;
PriorDayLow = TodayLow;
PriorDayOpen = TodayOpen;
TodayHigh = High;
TodayLow = Low;
TodayOpen = Open;
end
else
begin
TodayHigh = MaxList( High, TodayHigh ) ;
TodayLow = MinList( Low, TodayLow ) ;
end;
{ +++++++++++++++++++++++++++++++++++++++++++++++ }
{ +++++ IntraDay Chart - Weekly High & Low ++++++ }
{ +++++++++++++++++++++++++++++++++++++++++++++++ }
If DayOfWeek( Date ) < DayOfWeek( Date[1] ) then
begin
WeekHigh = High;
WeekLow = Low;
end
else
begin
WeekHigh = MaxList( High, WeekHigh ) ;
WeekLow = MinList( Low, WeekLow ) ;
end;
{ +++++++++++++++++++++++++++++++++++++++++++++++ }
{ +++++ IntraDay Chart - Monthly High & Low ++++++ }
{ +++++++++++++++++++++++++++++++++++++++++++++++ }
If Month(Date) <> Month(Date[1]) then
begin
MonthHigh = High;
MonthLow = Low;
end
else
begin
MonthHigh = MaxList( High, MonthHigh ) ;
MonthLow = MinList( Low, MonthLow ) ;
end;
//{ ++++++++++++++++++++++++++++++++++++++ }
//{ ++++ First Bar of Each New Day ++++++ }
//{ ++++++++++++++++++++++++++++++++++++++ }
If Date <> Date[1] then
begin
// Place code here you want executed on the first bar of each new day
end;
//{ ++++++++++++++++++++++++++++++++++++++++++ }
//{ ++++ First Bar of Each New Session ++++++ }
//{ ++++++++++++++++++++++++++++++++++++++++++ }
If CurrentSession(0) <> CurrentSession(0)[1] then
begin
// Place code here you want executed on First Bar of each New Session
end;
//{ ++++++++++++++++++++++++++++++++++++++ }
//{ ++++ First Bar of Today ONLY ++++++++ }
//{ ++++++++++++++++++++++++++++++++++++++ }
If Date <> Date[1] and Date = CurrentDate then
begin
// Place code here you want executed on First Bar if Today is the Current Date
end;
//{ ++++++++++++++++++++++++++++++++++++++++++ }
//{ ++++ First Bar of Yesterday ONLY ++++++++ }
//{ ++++++++++++++++++++++++++++++++++++++++++ }
If Date <> Date[1] and Date = CurrentDate - 1 then
begin
// Place code here you want executed on First Bar Of Yesterday ONLY
end;
//{ ++++++++++++++++++++++++++++++++++++++++ }
//{ ++++ First Bar of Each New Week +++++++ }
//{ ++++++++++++++++++++++++++++++++++++++++ }
If (( vCategory = 2 and Date <> Date[1] )
or ( vCategory <> 2 and CurrentSession(0) <> CurrentSession(0)[1] ) )
and ( ( vCategory = 2 and DayOfWeek(Date) = 1 )
or ( vCategory <> 2 and DayOfWeek(Date) = 0 ) ) then
begin
// Place code here you want executed of First Bar of each New Week
end;
//{ ++++++++++++++++++++++++++++++++++++++++ }
//{ ++++ First Bar of Each New Month ++++++ }
//{ ++++++++++++++++++++++++++++++++++++++++ }
If Month(Date) <> Month(Date[1]) then
begin
// Place code here you want executed of First Bar of each New Month
end;
{ ++++++++++++++++++++++++++++++++++++++++++++++++++ }
{ ++++++++++ First Bar of MONDAY Only ++++++++++++ }
{ ++++++++++++++++++++++++++++++++++++++++++++++++++ }
// For this example if you wanted to execute code on the first bar of Monday Opening Bar ONLY
// 0 = Sunday, 1=Monday, 2=Tuesday, etc.
If DayOfWeek(Date) = 1 and Date <> Date[1] then
begin
// Put code here to execute on First Bar of every Monday
end;
//{ +++++++++++++++++++++++++++++++++++ }
//{ ++++ New Trade High & Low +++++++ }
//{ +++++++++++++++++++++++++++++++++++ }
If (MP <> 0 and MP[1] = 0) // In Trade This Bar and Prior Bar Was Flat
or (MP = 1 and MP[1] = -1 ) // In SHORT Trade This Bar and Prior Bar was LONG Trade
or (MP = -1 and MP[1] = 1 ) then // In LONG Trade This Bar and Prior Bar was SHORT Trade
begin
{ First Bar of a New Trade }
TLHigh = High;
TLLow = Low;
end
else
{ Still in Trade so Track Trade High & Trade Low }
If MP <> 0 then
begin
TLHigh = MaxList( High, TLHigh ) ;
TLLow = MinList( Low, TLLow ) ;
end
else
{ Flat - Reset Variables }
If MP = 0 then
begin
TLHigh = 0;
TLLow = 9999;
end;
//{ +++++++++++++++++++++++++++++++++++++++ }
//{ ++++++ Calculations Section ++++++++++ }
//{ +++++++++++++++++++++++++++++++++++++++ }
If Barstatus(1) = 2 then
begin
// Place calculations here you only want to run once per bar at the end of each bar
// IntraDay Chart Calculation of Daily NetProfit
// Strategy Code
// Can use this to calculate Daily NetProfit
// One use is to stop trading if hit a given daily Profit Objective or Loss Amount
If Date = CurrentDate and Date <> Date[1] then
begin
vNetProfit = NetProfit;
end
else
If Date = CurrentDate then
begin
{ Calculate Daily NetProfits }
vDailyNetProfit = NetProfit - vNetProfit;
end;
{ Calculations }
SMAFast = Average(Close,vSMAFLength);
SMASlow = Average(Close,vSMASLength);
end;
//{ +++++++++++++++++++++ }
//{ +++ Entries +++++++++ }
//{ +++++++++++++++++++++ }
If Time >= vStartTime and Time < vEndTime then
begin
//{ Order Routing SetUp For Stocks }
If vCategory = 2 then
SetRouteName("ARCX");
//{ LONG Initial Entry }
If SMAFast crosses above SMASlow then
Buy ("L-SMA-X") next bar at market;
//{ SHORT Initial Entry }
If SMASlow crosses under SMASlow then
SellShort ("S-SMA-X") next bar at market;
end; // If BarStatus(1) = 2 then
//{ +++++++++++++ }
//{ ++ Exits ++++ }
//{ +++++++++++++ }
If MP <> 0 then
begin
//{ Order Routing SetUp for Stocks }
If vCategory = 2 then
SetRouteName("ARCX");
// Exits Here
If MP = 1 and Close < TLHigh - (vLTrailingTicks * OneTick) then
Sell ("LX-Trailing") next bar at market;
If MP = -1 and Close > TLLow + (vSTrailingTicks * OneTick) then
BuyToCover ("SX-Trailing") next bar at market;
end; // If MP <> 0 then
October 4th, 2010, 07:31 AM
copenhagen, denmark
Experience: Intermediate
Platform: multicharts, Ninja
Broker: IB & Kinetick
Trading: ES
Posts: 47 since Aug 2010
Thanks Given: 16
Thanks Received: 23
Big Mike
I needed this for my own strategies, so I wanted to share it here.
This will allow a dollar limit of daily loss and daily profit targets, whereby if one or the other is hit then the strategy will stop for the day.
If you wanted to make it weekly, it wouldn't be hard to do. The input for daily loss should be a + value (ie: "250" means a loss of 250, don't use "-250").
Code
// for use in signal inputs : dailyprofit ( 500 ), dailyloss ( 250 ); vars : todaynet ( 0 ), yesterdaynet ( 0 ); if date <> date [ 1 ] then begin yesterdaynet = NetProfit ; end ; if MarketPosition = 0 then begin todaynet = NetProfit - yesterdaynet ; end ; condition1 = - dailyloss < todaynet and todaynet < dailyprofit ; // entries if condition 1 then begin // put your long and short code here end ;
Condition1 evaluates to true if the profit for today is between the max loss and max profit. It evaluates to false if one or the other is exceeded. So place your entry code (buy/sellshort) inside the if block.
Let me know if it proves useful!
Mike
H
I everyone
I am trying to implement a daily profit/ loss limit in my trading strategy. To understand exactly what is going on I implemented Big Mike Code in a simple MACD cross over, prior to implementing it my "production trading code" - .
For some reason the code below doesn't work, and don't understand why it isn't working
What I am trying to achieve is very simple; - I want the trading to stop IF dailyprofit or dailyloss is reached within the specified timeframe.
What am i missing ??
Rgds Mengelbrecht
Multicharts - Code:
inputs:
FastLength( 12 ),
SlowLength( 26 ),
MACDLength( 9 ),
starttrade (0800),
endtrade(1600),
dailyprofit(500),
dailyloss(250);
Variables:
todaynet(0),
yesterdaynet(0),
var0( 0 ),
var1( 0 ),
var2( 0 ) ;
var0 = MACD( Close, FastLength, SlowLength ) ;
var1 = XAverage( var0, MACDLength ) ;
var2 = var0 - var1 ;
if date <> date[1] then begin
yesterdaynet = NetProfit;
end;
todaynet = NetProfit + openpositionprofit - yesterdaynet;
condition1 = var2 crosses under 0 ;
condition2 = var2 crosses over 0 ;
condition98 = (-dailyloss < todaynet and todaynet < dailyprofit) and (Time > starttrade and time < endtrade);
if condition98 then begin
if condition1 then sellshort ( "MacdSE" ) next bar at market;
if condition2 then buy ( "MacdLE" ) next bar at market ;
end;
January 31st, 2015, 01:06 AM
Toronto, Canada
Posts: 1 since Jan 2015
Thanks Given: 0
Thanks Received: 0
Hi Mengelbrecht and all:
I am trying to set up an automated strategy involving a daily stop loss/profit target in Easy Language. I was browsing the forum for any answers and discovered Mengelbrecht encountered the same problem that I am having, in 2010, but I don't know whether the issue was resolved as that's where the thread ends.
In a nutshell, I also wanted to somehow incorporate in the code, a mechanism to terminate a current position if its profit/loss makes the daily profit/loss reach the target. I independently wrote an almost identical code as the code posted by Mengelbrecht, but also put [Intrabarordergeneration=true], and declared some variables as "intrabarpersist". Still, it didn't work.
If that issue has been resolved, could someone please post a working code that is taking into account any current position (the code should be probably using "positionprofit") and terminates that position when the daily profit/loss is reached?
Thanks!
January 31st, 2015, 03:55 AM
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629
volatilius,
post your code and I am sure someone here in the forum can point you in the right direction.
Regards,
ABCTG
volatilius
Hi Mengelbrecht and all:
I am trying to set up an automated strategy involving a daily stop loss/profit target in Easy Language. I was browsing the forum for any answers and discovered Mengelbrecht encountered the same problem that I am having, in 2010, but I don't know whether the issue was resolved as that's where the thread ends.
In a nutshell, I also wanted to somehow incorporate in the code, a mechanism to terminate a current position if its profit/loss makes the daily profit/loss reach the target. I independently wrote an almost identical code as the code posted by Mengelbrecht, but also put [Intrabarordergeneration=true], and declared some variables as "intrabarpersist". Still, it didn't work.
If that issue has been resolved, could someone please post a working code that is taking into account any current position (the code should be probably using "positionprofit") and terminates that position when the daily profit/loss is reached?
Thanks!
February 2nd, 2015, 09:12 AM
copenhagen, denmark
Experience: Intermediate
Platform: multicharts, Ninja
Broker: IB & Kinetick
Trading: ES
Posts: 47 since Aug 2010
Thanks Given: 16
Thanks Received: 23
volatilius
Hi Mengelbrecht and all:
I am trying to set up an automated strategy involving a daily stop loss/profit target in Easy Language. I was browsing the forum for any answers and discovered Mengelbrecht encountered the same problem that I am having, in 2010, but I don't know whether the issue was resolved as that's where the thread ends.
In a nutshell, I also wanted to somehow incorporate in the code, a mechanism to terminate a current position if its profit/loss makes the daily profit/loss reach the target. I independently wrote an almost identical code as the code posted by Mengelbrecht, but also put [Intrabarordergeneration=true], and declared some variables as "intrabarpersist". Still, it didn't work.
If that issue has been resolved, could someone please post a working code that is taking into account any current position (the code should be probably using "positionprofit") and terminates that position when the daily profit/loss is reached?
Thanks!
Hi volatilius
sorry for the late respons, I have been away from my desk all weekend.
This is code that someone send me:
inputs: dailyprofit(300),dailyloss(300);
variables: todaynet(0), yesterdaynet(0), priordate (date) ;
once
begin
priordate = Date - 1;
end;
if date > priordate then begin
priordate = date;
yesterdaynet = NetProfit;
end;
todaynet = NetProfit + openpositionprofit - commission – yesterdaynet;
You need to integrate this into the strategy that you have developed
Have fun
Rgds
Mengelbrecht
May 9th, 2016, 08:28 PM
Chicago
Posts: 4 since Apr 2013
Thanks Given: 3
Thanks Received: 0
Hello Mike,
How can this code be modified to set a profit objective for the day that acts as a profit stop? For example the profit breaches a $200 profit level and keeps trading unless the profit falls back below $200 in the same day. Any ideas?
May 11th, 2016, 06:29 PM
Prague
Posts: 2 since Nov 2013
Thanks Given: 1
Thanks Received: 0
Hi,
is there way to get yesterday Netprofit to compare with todays Netprofit please?
Last Updated on March 11, 2021