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)
Help making strategy run
Updated February 26, 2019
Top Posters
looks_one
barabas
with 5 posts (1 thanks)
looks_two
ABCTG
with 4 posts (5 thanks)
looks_3
xplorer
with 2 posts (0 thanks)
looks_4
Quick Summary
with 1 posts (0 thanks)
trending_up
2,549 views
thumb_up
6 thanks given
group
2 followers
forum
11 posts
attach_file
2 attachments
Help making strategy run
February 24th, 2019, 01:26 PM
Chicago IL USA
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation
Trading: ES,NQ, CL
Posts: 111 since Feb 2019
Thanks Given: 105
Thanks Received: 173
Hello All!
I am a new elite member and hopefully I don't mess this up by posting this in the wrong topic.
I need help with this strategy I got the strategy from someone but when putting in a profit target or end of day exit the strategy does not repeat it will only do one trade then exit at profit and never come back. Please help i am looking to add exit at end of day and profit target.
Thank you
Quoting
{ Modified
ATR Trailing Stop }
inputs:
TrailType ( 2), { enter 1 for modified version, any
other number for unmodified version }
ATR_Period( 2.67),
ATR_Factor( 2.65),
Quantity( 1),
InitialMonth( 1),
InitialDay( 1),
InitialYear( 400),
FirstTrade( 1) ; { enter 1 for long, any other
number for short }
variables:
Loss( 0 ),
HiLo( 0 ),
HRef( 0 ),
LRef( 0 ),
HiLoHRefMax( 0 ),
HiLoHRefMaxLRefMax( 0 ),
ATRMod( 0 ),
WaitingForEntry( true ),
Trail( 0 ),
LineNum( 0 ),
ReturnVal( 0 ) ;
if TrailType <> 1 then
Loss = ATR_Factor * AvgTrueRange( ATR_Period )
else
begin
HiLo = iff( High - Low < 1.5 * Average( High - Low,
ATR_Period ), High - Low, 1.5 * Average( High -
Low, ATR_Period ) ) ;
HRef = iff( Low <= High[1], High - Close[1],( High -
Close[1] ) - 0.5 * ( Low - High[1] ) ) ;
LRef = iff( High >= Low[1], Close[1] - Low,
( Close[1] - Low ) - 0.5 * ( Low[1] - High ) ) ;
HiLoHRefMax = Maxlist( HiLo, HRef ) ;
HiLoHRefMaxLRefMax = Maxlist( HiLoHRefMax, LRef ) ;
ATRMod = XAverage( HiLoHRefMaxLRefMax, 2 *
ATR_Period - 1 ) ;
Loss = ATR_Factor * ATRMod ;
end ;
if WaitingForEntry
and Year( Date ) + 1900 >= InitialYear
and Month( Date ) >= InitialMonth
and DayOfMonth( Date ) >= InitialDay
then
begin
if FirstTrade = 1 then
begin
Buy Quantity shares this bar Close ;
WaitingForEntry = false ;
Trail = Close - Loss ;
end
else
begin
Sell short Quantity shares this bar at Close ;
WaitingForEntry = false ;
Trail = Close + Loss ;
end ;
end
else if WaitingForEntry[1] = false then
begin
if Close > Trail[1] and Close[1] > Trail[2] then
{ continued long }
Trail = MaxList( Trail[1], Close - Loss )
else if Close < Trail[1] and Close[1] < Trail[2]
then
{ continued short }
Trail = MinList( Trail[1], Close + Loss )
else if Close > Trail[1] then
{ close is above trail }
Trail = Close - Loss
else
Trail = Close + Loss ;
if MarketPosition = -1 and Close > Trail and
Trail > 0 then
begin
Buy Quantity shares this bar Close ;
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail[1] ) ;
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
end
else if MarketPosition = 1 and Close < Trail then
begin
Sell short Quantity shares this bar at Close ;
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail[1] ) ;
ReturnVal = TL_SetColor( LineNum, Magenta ) ;
end
else if Trail[1] > 0 then
begin
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail ) ;
if Close > Trail then
ReturnVal = TL_SetColor( LineNum, Magenta )
else
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
end ;
end ;
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
February 24th, 2019, 01:32 PM
London UK
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 5,991 since Sep 2015
Thanks Given: 15,527
Thanks Received: 15,490
Hi @barabas and welcome to the forum.
Is this strategy for TradeStation?
If so I will move the thread to the TradeStation section, you may get better responses there.
February 24th, 2019, 01:58 PM
Chicago IL USA
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation
Trading: ES,NQ, CL
Posts: 111 since Feb 2019
Thanks Given: 105
Thanks Received: 173
xplorer
Hi @
barabas and welcome to the forum.
Is this strategy for TradeStation?
If so I will move the thread to the TradeStation section, you may get better responses there.
Yes it is. Thank you
February 24th, 2019, 04:58 PM
London UK
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 5,991 since Sep 2015
Thanks Given: 15,527
Thanks Received: 15,490
barabas
Thread moved.
February 25th, 2019, 05:09 AM
Posts: 2,436 since Apr 2013
Thanks Given: 484
Thanks Received: 1,629
Hi barabas,
the strategy code you posted appears to be designed to only take one entry. After your entry conditions are present the code sets the variable WaitingForEntry to false, which will effectively prevent it from entering again.
You could simply set WaitingForEntry to true after you are flat again (or not set it to false at all), but the way the entry conditions are written i.e. using date only as condition it could simply enter right away after being flat again.
Regards,
ABCTG
February 25th, 2019, 11:54 AM
Chicago IL USA
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation
Trading: ES,NQ, CL
Posts: 111 since Feb 2019
Thanks Given: 105
Thanks Received: 173
ABCTG
Hi barabas,
the strategy code you posted appears to be designed to only take one entry. After your entry conditions are present the code sets the variable WaitingForEntry to false, which will effectively prevent it from entering again.
You could simply set WaitingForEntry to true after you are
flat again (or not set it to false at all), but the way the entry conditions are written i.e. using date only as condition it could simply enter right away after being flat again.
Regards,
ABCTG
Hi ABCTG,
Thank you for responding! I tried that and I then set a basic Profit target code {SetProfitTarget( Amount );}and it did one trade and then didn't enter a new trade again.
Any ideas?
February 25th, 2019, 11:56 AM
Posts: 2,436 since Apr 2013
Thanks Given: 484
Thanks Received: 1,629
barabas,
without seeing the code with the modifications you did, I am afraid it's hard to tell.
Regards,
ABCTG
barabas
Hi ABCTG,
Thank you for responding! I tried that and I then set a basic Profit target code {SetProfitTarget( Amount );}and it did one trade and then didn't enter a new trade again.
Any ideas?
February 25th, 2019, 12:11 PM
Chicago IL USA
Experience: Intermediate
Platform: Tradestation
Broker: Tradestation
Trading: ES,NQ, CL
Posts: 111 since Feb 2019
Thanks Given: 105
Thanks Received: 173
ABCTG
barabas,
without seeing the code with the modifications you did, I am afraid it's hard to tell.
Regards,
ABCTG
{ M
Quoting
odified
ATR Trailing Stop }
inputs:
TrailType ( 2), { enter 1 for modified version, any
other number for unmodified version }
ATR_Period( 18.0),
ATR_Factor( 2.65),
Quantity( 1),
InitialMonth( 1),
InitialDay( 1),
InitialYear( 400),
FirstTrade( 1) ; { enter 1 for long, any other
number for short }
variables:
Loss( 0 ),
HiLo( 0 ),
HRef( 0 ),
LRef( 0 ),
HiLoHRefMax( 0 ),
HiLoHRefMaxLRefMax( 0 ),
ATRMod( 0 ),
WaitingForEntry( true ),
Trail( 0 ),
LineNum( 0 ),
ReturnVal( 0 ) ;
SetProfitTarget( 100 );
if TrailType <> 1 then
Loss = ATR_Factor * AvgTrueRange( ATR_Period )
else
begin
HiLo = iff( High - Low < 1.5 * Average( High - Low,
ATR_Period ), High - Low, 1.5 * Average( High -
Low, ATR_Period ) ) ;
HRef = iff( Low <= High[1], High - Close[1],( High -
Close[1] ) - 0.5 * ( Low - High[1] ) ) ;
LRef = iff( High >= Low[1], Close[1] - Low,
( Close[1] - Low ) - 0.5 * ( Low[1] - High ) ) ;
HiLoHRefMax = Maxlist( HiLo, HRef ) ;
HiLoHRefMaxLRefMax = Maxlist( HiLoHRefMax, LRef ) ;
ATRMod = XAverage( HiLoHRefMaxLRefMax, 2 *
ATR_Period - 1 ) ;
Loss = ATR_Factor * ATRMod ;
end ;
if WaitingForEntry
and Year( Date ) + 1900 >= InitialYear
and Month( Date ) >= InitialMonth
and DayOfMonth( Date ) >= InitialDay
then
begin
if FirstTrade = 1 then
begin
Buy Quantity shares this bar Close ;
WaitingForEntry = false ;
Trail = Close - Loss ;
end
else
begin
Sell short Quantity shares this bar at Close ;
WaitingForEntry = false ;
Trail = Close + Loss ;
end ;
end
else if WaitingForEntry[1] = True then
begin
if Close > Trail[1] and Close[1] > Trail[2] then
{ continued long }
Trail = MaxList( Trail[1], Close - Loss )
else if Close < Trail[1] and Close[1] < Trail[2]
then
{ continued short }
Trail = MinList( Trail[1], Close + Loss )
else if Close > Trail[1] then
{ close is above trail }
Trail = Close - Loss
else
Trail = Close + Loss ;
if MarketPosition = -1 and Close > Trail and
Trail > 0 then
begin
Buy Quantity shares this bar Close ;
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail[1] ) ;
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
end
else if MarketPosition = 1 and Close < Trail then
begin
Sell short Quantity shares this bar at Close ;
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail[1] ) ;
ReturnVal = TL_SetColor( LineNum, Magenta ) ;
end
else if Trail[1] > 0 then
begin
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail ) ;
if Close > Trail then
ReturnVal = TL_SetColor( LineNum, Magenta )
else
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
end ;
end ;
Right after the variables you can see that i added [SetProfitTarget( 100 );] and then i also changed the waiting entry to true.
February 25th, 2019, 12:17 PM
Posts: 2,436 since Apr 2013
Thanks Given: 484
Thanks Received: 1,629
barabas,
your code evaluates the value of the WaitingForEntry variable, but the bold part doesn't set the value for the variable. In fact this might have an adverse effect here as this changes the way the trailing stop works.
You will have to actually set the value of WaitingForEntry to true. Although I have not tested this for your strategy, but something along the lines of
Code
if MarketPosition = 0 and WaitingForEntry = false then
WaitingForEntry = true ;
would set WaitingForEntry back to true when you are not in a position.
Regards,
ABCTG
barabas
{ M
Right after the variables you can see that i added [SetProfitTarget( 100 );] and then i also changed the waiting entry to true.
Last Updated on February 26, 2019