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

  #1 (permalink)
 
Big Mike's Avatar
 Big Mike 
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,322 since Jun 2009
Thanks Given: 33,143
Thanks Received: 101,476

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

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Request for MACD with option to use different MAs for fa …
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
50 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

  #3 (permalink)
Ranger
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
Reply With Quote
The following 6 users say Thank You to Ranger for this post:
  #4 (permalink)
insideday
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

Reply With Quote
  #5 (permalink)
 
mengelbrecht's Avatar
 mengelbrecht 
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 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


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;

Reply With Quote
  #6 (permalink)
volatilius
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!

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

volatilius,

post your code and I am sure someone here in the forum can point you in the right direction.

Regards,

ABCTG


volatilius View Post
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!


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:
  #8 (permalink)
 
mengelbrecht's Avatar
 mengelbrecht 
copenhagen, denmark
 
Experience: Intermediate
Platform: multicharts, Ninja
Broker: IB & Kinetick
Trading: ES
Posts: 47 since Aug 2010
Thanks Given: 16
Thanks Received: 23


volatilius View Post
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

Reply With Quote
The following user says Thank You to mengelbrecht for this post:
  #9 (permalink)
ELong
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?

Reply With Quote
  #10 (permalink)
djplastic
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?

Reply With Quote





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