NexusFi: Find Your Edge


Home Menu

 





Help making strategy run


Discussion in TradeStation

Updated
      Top Posters
    1. looks_one barabas with 5 posts (1 thanks)
    2. looks_two ABCTG with 4 posts (5 thanks)
    3. looks_3 xplorer with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,106 views
    2. thumb_up 6 thanks given
    3. group 2 followers
    1. forum 11 posts
    2. attach_file 2 attachments




 
Search this Thread
  #1 (permalink)
 
barabas's Avatar
 barabas 
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 ;


Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
Warsh Drops Easing Bias, December Hike Now Above 50% -- …
Prediction Markets & Event Contracts
June 15 Peace Odds Surge From 3.6% to 12.25% After Trump …
Prediction Markets & Event Contracts
Irans Answer Due Today: Peace Surges to 33.5%, Invasion …
Prediction Markets & Event Contracts
Hormuz Completely Closed: US Strikes Day 2, Iran Shoots …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
16 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #3 (permalink)
 
xplorer's Avatar
 xplorer 
London UK
Site Moderator
 
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 6,270 since Sep 2015
Thanks Given: 15,955
Thanks Received: 16,194


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.


Reply With Quote
  #4 (permalink)
 
barabas's Avatar
 barabas 
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 View Post
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


Started this thread Reply With Quote
  #5 (permalink)
 
xplorer's Avatar
 xplorer 
London UK
Site Moderator
 
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 6,270 since Sep 2015
Thanks Given: 15,955
Thanks Received: 16,194


barabas View Post
Yes it is. Thank you

Thread moved.


Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

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


Follow me on X Reply With Quote
Thanked by:
  #7 (permalink)
 
barabas's Avatar
 barabas 
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 View Post
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?


Started this thread Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

barabas,

without seeing the code with the modifications you did, I am afraid it's hard to tell.

Regards,

ABCTG


barabas View Post
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?


Follow me on X Reply With Quote
  #9 (permalink)
 
barabas's Avatar
 barabas 
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 View Post
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.


Started this thread Reply With Quote
  #10 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643


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 View Post
{ M

Right after the variables you can see that i added [SetProfitTarget( 100 );] and then i also changed the waiting entry to true.


Follow me on X Reply With Quote
Thanked by:




Last Updated on February 26, 2019


© 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