NexusFi: Find Your Edge


Home Menu

 





EasyLanguage Daily Profit and Daily Loss limit in strategy


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ABCTG with 6 posts (4 thanks)
    2. looks_two 20YRTRADER with 3 posts (0 thanks)
    3. looks_3 AlexBa with 3 posts (0 thanks)
    4. looks_4 djplastic with 2 posts (0 thanks)
      Best Posters
    1. looks_one Big Mike with 20 thanks per post
    2. looks_two Ranger with 6 thanks per post
    3. looks_3 insideday with 3 thanks per post
    4. looks_4 ABCTG with 0.7 thanks per post
    1. trending_up 32,505 views
    2. thumb_up 36 thanks given
    3. group 17 followers
    1. forum 25 posts
    2. attach_file 1 attachments




 
Search this Thread

EasyLanguage Daily Profit and Daily Loss limit in strategy

  #11 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

djplastic,

the post from @mengelbrecht two above your post shows how to store the previous NetProfit in a variable on a new day. Which is exactly what you'd have to do, too. Then you can use this variable in your checks.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Request for MACD with option to use different MAs for fa …
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
67 thanks
Battlestations: Show us your trading desks!
48 thanks
NexusFi site changelog and issues/problem reporting
47 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #12 (permalink)
djplastic
Prague
 
Posts: 2 since Nov 2013
Thanks Given: 1
Thanks Received: 0

thank you ABCTG , I tried modify code from Mike post 1 and it wasnt exactly what I wanted, now it is much better

Reply With Quote
  #13 (permalink)
 
Bullywig's Avatar
 Bullywig 
Chicago
 
Experience: Intermediate
Platform: NinjaTrader
Broker: NinjaTrader Brokerage
Trading: FDAX, NQ, HG, SI, CL
Posts: 68 since Oct 2015
Thanks Given: 42
Thanks Received: 22



Big Mike View Post
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[1then 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

By any chance, do you have an example of this incorporated into a full coded strategy example? I'm trying to learn how to code some strategies, and not sure where everything should be placed in regards to what you listed here. I assume this is for NT7? Thanks in advance if you can help.

Cheers!

Reply With Quote
  #14 (permalink)
 20YRTRADER 
Atlanta, GA/USA
 
Experience: Advanced
Platform: Ninja Trader & TradeStation
Broker: TradeStation
Trading: Crude Oil, Dow
Posts: 7 since Sep 2015
Thanks Given: 2
Thanks Received: 0

Mike - I was wondering if something similar to this could be implemented for multiple TradeStation (TS) Workspaces? I trade 4 futures markets in TS and my goal for each day is $2K. I sometimes enter 3-4 markets at the same time (via my strategy) as they are all trending in the same direction. Many times they hit the $2k mark and fall off if am not watching every tick. I can get distracted with bathroom trips, snacks, phone calls, etc. I would like to have all my Workspaces shut down if I reach this daily profit or loss target. Is this a possibility? I was thinking you might be able to cross reference all 4 Workspaces some way. Maybe with a 5th chart referencing the other 4 as long as the same account is used? What do you think? Thanks in advance for your help. JK

Reply With Quote
  #15 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

20YRTRADER,

it depends a bit of what exactly you want to do. If you want a global target across all workspaces, this would require some communication between the charts and maybe a separate chart that monitors all targets and blocks/allows the trading on the individual charts. One way to accomplish this in real time could by using a Global Dictionary.

Regards,

ABCTG


20YRTRADER View Post
Mike - I was wondering if something similar to this could be implemented for multiple TradeStation (TS) Workspaces? I trade 4 futures markets in TS and my goal for each day is $2K. I sometimes enter 3-4 markets at the same time (via my strategy) as they are all trending in the same direction. Many times they hit the $2k mark and fall off if am not watching every tick. I can get distracted with bathroom trips, snacks, phone calls, etc. I would like to have all my Workspaces shut down if I reach this daily profit or loss target. Is this a possibility? I was thinking you might be able to cross reference all 4 Workspaces some way. Maybe with a 5th chart referencing the other 4 as long as the same account is used? What do you think? Thanks in advance for your help. JK


Follow me on Twitter Reply With Quote
  #16 (permalink)
 20YRTRADER 
Atlanta, GA/USA
 
Experience: Advanced
Platform: Ninja Trader & TradeStation
Broker: TradeStation
Trading: Crude Oil, Dow
Posts: 7 since Sep 2015
Thanks Given: 2
Thanks Received: 0

What is a Global Dictionary? Is this defined in Easy Language?

Reply With Quote
  #17 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

20YRTRADER,

yes, this is defined in EasyLanguage. Global Dictionaries were introduced with Object Oriented EasyLanguage and can for example be used to share data across studies, charts or between applications.

Regards,

ABCTG


20YRTRADER View Post
What is a Global Dictionary? Is this defined in Easy Language?


Follow me on Twitter Reply With Quote
  #18 (permalink)
AlexBa
Santo domingo/ Dominican Republic
 
Posts: 5 since Oct 2019
Thanks Given: 2
Thanks Received: 0

How can I put this on a Indicator? I want to see it.



Big Mike View Post
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[1then 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


Reply With Quote
  #19 (permalink)
AlexBa
Santo domingo/ Dominican Republic
 
Posts: 5 since Oct 2019
Thanks Given: 2
Thanks Received: 0

You can do it reference to the account balance...
I have not the code to hand, but I can give you later..





20YRTRADER View Post
Mike - I was wondering if something similar to this could be implemented for multiple TradeStation (TS) Workspaces? I trade 4 futures markets in TS and my goal for each day is $2K. I sometimes enter 3-4 markets at the same time (via my strategy) as they are all trending in the same direction. Many times they hit the $2k mark and fall off if am not watching every tick. I can get distracted with bathroom trips, snacks, phone calls, etc. I would like to have all my Workspaces shut down if I reach this daily profit or loss target. Is this a possibility? I was thinking you might be able to cross reference all 4 Workspaces some way. Maybe with a 5th chart referencing the other 4 as long as the same account is used? What do you think? Thanks in advance for your help. JK


Reply With Quote
  #20 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623


AlexBa,

what exactly do you want the indicator to display? Strategy related reserved words won't be available in indicators, but TS offers reserved words that make some strategy related values available in indicators like I_closedequity
for example and you can use this to replace Netprofit in the indicator code. You will however still need a strategy applied to the same chart in order for I_closedequity to return a value different than 0.

Regards,

ABCTG


AlexBa View Post
How can I put this on a Indicator? I want to see it.


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:





Last Updated on March 11, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts