NexusFi: Find Your Edge


Home Menu

 





Adding daily profit & daily loss targets to code


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one yeli with 2 posts (0 thanks)
    2. looks_two Shaban with 1 posts (0 thanks)
    3. looks_3 4042 with 1 posts (0 thanks)
    4. looks_4 kjhosken with 1 posts (1 thanks)
    1. trending_up 4,652 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
yeli
Milano, Italy
 
Posts: 6 since Apr 2021
Thanks Given: 45
Thanks Received: 0

Dear friends
Please help a newbie here - am trying to add dailyprofittarget and dailyloss to a simple moving average cross strat.. I added a dailyprofit/loss code that Big Mike posted a long time ago here...what's wrong there?

Thanks for ANY help!

This is the 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


inputs:
FastPrice( Close ) [DisplayName = "FastPrice", ToolTip =
"Enter an EasyLanguage expression to use in calculation of shorter length moving average."],
SlowPrice( Close ) [DisplayName = "SlowPrice", ToolTip =
"Enter an EasyLanguage expression to use in calculation of longer length moving average."],
FastLength( ) [DisplayName = "FastLength", ToolTip =
"Enter number of bars to use in calculation of shorter length moving average."],
SlowLength( ) [DisplayName = "SlowLength", ToolTip =
"Enter number of bars to use in calculation of longer length moving average."];

variables:
FastAvg( ),
SlowAvg( );

FastAvg = AverageFC( FastPrice, FastLength );
SlowAvg = AverageFC( SlowPrice, SlowLength );

{ CB > 1 check used to avoid spurious cross confirmation at CB = 1 }
if CurrentBar > 1 and FastAvg crosses under SlowAvg then
Sell short 1 contract next bar at market;
setstoploss ();
setprofittarget ();


{ ** Copyright © TradeStation Technologies, Inc. All Rights Reserved **
** TradeStation reserves the right to modify or overwrite this strategy component
with each release. ** }

end;


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran and Israel Stand Down: What $9M in Peace Contracts …
Prediction Markets & Event Contracts
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
CME Raises Energy Futures Margins After Iran-War Volatil …
Commodities
I Have a Thing Called Iran -- Trump Stays in DC as Airsp …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
13 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
 kjhosken 
Seattle, WA/USA
 
Experience: Intermediate
Platform: TOS, TS
Trading: Forex, crude
Posts: 96 since Sep 2016
Thanks Given: 7
Thanks Received: 35

I think this is your problem, there isn't any variable or input placed in the target and stop functions. Put your profit and stop inputs inside the parentheses.


yeli View Post

setstoploss ();
setprofittarget ();


Follow me on X Reply With Quote
Thanked by:
  #3 (permalink)
yeli
Milano, Italy
 
Posts: 6 since Apr 2021
Thanks Given: 45
Thanks Received: 0


Thanks so much for the reply. I left the variables out because i change them all the time..doesn't work also when all variables are filled..


Reply With Quote
  #4 (permalink)
Shaban
Turin + Italy
 
Posts: 201 since Feb 2020
Thanks Given: 26
Thanks Received: 138

Ciao,

se ho capito bene, per quanto concerne lo Stoploss ed il ProfitTarget, dovresti inserirli in questo modo (così li puoi anche ottimizzare):

Inputs: exit_proft(500), Amount(250);




SetProfitTarget (exit_proft);
SetStopLoss(Amount);

--------------------------------------------

A parte lo Stoploss ed il ProfitTarget, il resto della formula funziona correttamente?

P.S: hai un M.P.


Reply With Quote
  #5 (permalink)
4042
ALBUQUERQUE NEW MEXICO
 
Posts: 1 since Sep 2021
Thanks Given: 0
Thanks Received: 0

condition1 = -dailyloss < todaynet and todaynet < dailyprofit;

Instead of -dailyloss use -1*dailyloss.

For generating a buy or sell signal, I didn't have to use "if condition1 then begin;end";
I just insert the condition along with the rest of the buy or sellshort instructions. example: If condition1 and value1>value2 then buy/sellshort next bar market;


Reply With Quote




Last Updated on March 24, 2023


© 2026 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 - Downloads - Top
no new posts