NexusFi: Find Your Edge


Home Menu

 





Future Reference to Past Bar


Discussion in EasyLanguage Programming

Updated
    1. trending_up 10,986 views
    2. thumb_up 16 thanks given
    3. group 3 followers
    1. forum 23 posts
    2. attach_file 11 attachments




 
Search this Thread

Future Reference to Past Bar

  #1 (permalink)
Vientomarsol
Port St. Lucie, FL.
 
Posts: 25 since May 2016
Thanks Given: 17
Thanks Received: 9

I’m building an ES Tick-bar strategy in TradeStation Easy Language.

I have coded a specific bar that will trigger an entry several bars later. The number of bars later will vary.

Question: How can I reference the trigger bar (actually; the High or Low of the Trigger bar) as a value for my exit stop, after my entry has been filled?

Attached example depicts a long trade. Any suggestions?

Attached Thumbnails
Click image for larger version

Name:	Future Reference to a Past Bar.bmp
Views:	293
Size:	1.84 MB
ID:	212212  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
Trade idea based off three indicators.
Traders Hideout
NexusFi Journal Challenge - May 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
70 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
The Program
20 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628


Vientomarsol,

you wrote "I have coded a specific bar that will trigger an entry several bars later. ". Just save the values you need from that trigger bar into variables at the moment you detect the trigger bar.

In other words you will have conditions for what makes your trigger bar and every time these are met, you can also store the values you need to use later.

By the way you can show your appreciation for a post on futures.io by clicking the "Thanks" button next to it.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
Vientomarsol
Port St. Lucie, FL.
 
Posts: 25 since May 2016
Thanks Given: 17
Thanks Received: 9

I don’t know how to Store the values for later. Please elaborate.

My Trigger Code is:

//Long Entry Trigger
If Condition2[1] and Condition3 and (Condition7 or condition8) and not Condition10 then begin Buy ( "LE" ) next bar at market;
MP = 1;
End;


I need to add something to my code that will mark the Low of my trigger bar (not my entry bar) as my stop; if and when, my order is triggered”.

How do I code this?

Thanks in advance for your input :-)

Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

Vientomarsol,

you are welcome. It appears your code snippet is for the bar that actually triggers the entry. Storing the values of that bar would be too late as you want the trigger bar values (at least this is my impression from what you wrote).

Not knowing what your conditions for the trigger bar are and what values you actually want to store, I am afraid but I can't be of much help besides providing you with an pseudo code example that you'd have to adapt to fit your needs.

 
Code
Variables:
bool isTriggerBar ( false ),
double triggerBarHigh ( 0 ),
double triggerBarLow ( 0 );

//reset flag
isTriggerBar = false ;

isTriggerBar = isTriggerBar or ( All your checks for the trigger bar would have to go in here ) ;

//trigger bar detected, store values
if isTriggerBar then
begin 
    triggerBarHigh = High ;
    triggerBarLow = Low ;
end ;
This would store the high and low of each trigger bar, but it would also overwrite the values with each new trigger bar. This might be something you need to deal with - for example by not allowing the code to overwrite (you'd need to code that) the values while you are waiting to go long and then storing these values in a second variables at the moment you send the order. Please keep in mind that these are just ideas and depending on what exactly you need the code to do will not accomplish that, but it's a good start that you can adapt to your needs.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #6 (permalink)
Vientomarsol
Port St. Lucie, FL.
 
Posts: 25 since May 2016
Thanks Given: 17
Thanks Received: 9

As before, Thanks so much for your prompt reply.

Sorry for the confusion. Yes, my code below is for 'next bar' entry, but my question could apply to a second bar or third bar (I probably would not go past three bars) beyond the trigger bar where I would want to use a pre-established value (based on my Trigger Bar) as an exit.

So; to clarify:

For a Long Position, I want to store the Low of my Trigger Bar. I plan to use the "TriggerLow" value to:

a) Automatically set an exit order for a Long Position, based on the low of a previous bar

b) Automatically exit the Long position on the first tick (of the first instance) that the “TriggerLow” value is broken to the down side.

and

c) Allow the process to start fresh when I again receive my next ‘TriggerBar’.


In my feeble attempt to to code this function, I have created a variable called “triggerLow(0);” and inserted it in my Long Entry code as follows:

If Condition XX then begin Buy ( "LE" ) next bar at market;
MP = 1;
TriggerLow=Low;
End;

And, I have set-up the Long Exit code as follows:

If MarketPosition > 0 and L< (TriggerLow=Low) then begin Sell next bar at Market.
MP=0;
End;

Comments or suggestions?? I can use all the help I can get

Thanks so much. (

Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628


Vientomarsol View Post
Comments or suggestions??

Vientomarsol,

you are welcome.
Does the code give you the desired result? Then my comment would be good job, well done.

To suggest anything I would need to know where the code derives from what you want it to do and what it should do instead.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #8 (permalink)
Vientomarsol
Port St. Lucie, FL.
 
Posts: 25 since May 2016
Thanks Given: 17
Thanks Received: 9

ABCTG,

My apologies for not getting back to you in a timely manner.

I have been working on this exit code for over a week, and I decided to take a break and study-up on Variables before importing your code.

In you last post you stated: "This {your code} would store the high and low of each trigger bar, but it would also overwrite the values with each new trigger bar. " That is exactly what I'm looking for.

I'll set-it-up tomorrow and report back on the results.

Thanks again for your prompt response, and my apologies for not getting right on it.

I'll let you know how it shakes-out.

Respectfully,

Reply With Quote
Thanked by:
  #9 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

Vientomarsol,

my post above was meant in regards to your post #6 in this thread as you asked for comments and suggestions in that.
One suggestion I have is that you probably would get more help from other users if you'd post actually working code. By that I don't mean reveal your exact logic, but you could for example create demonstration code that shows the same behavior that you are having trouble with or want corrected. This will not only make things a lot clearer as someone trying to help you can see exactly what you see it will also make it easier for others to help you.

Regards,

ABCTG




Vientomarsol View Post
ABCTG,

My apologies for not getting back to you in a timely manner.

I have been working on this exit code for over a week, and I decided to take a break and study-up on Variables before importing your code.

In you last post you stated: "This {your code} would store the high and low of each trigger bar, but it would also overwrite the values with each new trigger bar. " That is exactly what I'm looking for.

I'll set-it-up tomorrow and report back on the results.

Thanks again for your prompt response, and my apologies for not getting right on it.

I'll let you know how it shakes-out.

Respectfully,


Follow me on Twitter Reply With Quote
Thanked by:
  #10 (permalink)
Vientomarsol
Port St. Lucie, FL.
 
Posts: 25 since May 2016
Thanks Given: 17
Thanks Received: 9


Hello ABCTG,

Good News !!!!! I merged your code with mine, and it worked much better than anything I have tried thus far, but there are issues (details below) that I hope you can help me with.

My code (merged with yours) is as follows:

Variables:
MP(0),//MP = marketposition
bool isTriggerBar ( false ),
double triggerBarHigh ( 0 ),
double triggerBarLow ( 0 );

//reset flag
isTriggerBar = false ;

isTriggerBar = isTriggerBar or (Condition2 and not Condition10 ) ;

//trigger bar detected, store values
if isTriggerBar then
begin
triggerBarHigh = High ;
triggerBarLow = Low ;
end ;

//Values
Value1 = Proprietary;
Value2 = Proprietary;

//Entry Conditions

Condition2 = Value1 < -.1;
Condition3 = High > High[1];
Condition7 = Low > Low[1];
Condition8 = Low = Low[1];
Condition10=Value2>+100;

//Plots

//Long Entry
If Condition2[1] and Condition3 and (Condition7 or condition8) and not Condition10 then begin Plot1(Low, "LE",red);
MP = 1;
End;

//Long Exit on Break of Trigger Bar bottom
If MP=1 and L < triggerBarLow then begin Plot2 (Low, "LX", Cyan);
MP = 0;
End;


Description of Issues:

For the most part, the function is operating properly. The function is:
1) capturing a specific value
2) Implementing the value (as an Exit) only if MP=+1
3) Re-setting the value after each trigger bar, if MP=0

My Issues Are:
1) My exits are being made on <Entry Bar Low, not < Trigger bar Low.
2) There are instances where the exit criteria are met, but no exit was made.
3) In at least one case, an exit was made on a subsequent trigger Bar Low.
4) Late Exit.
5) Exits in places they should not be.

I have attached screen-prints of each issue (numbered per above Issue-Numbers).
• Trigger Bars on attached screen-prints are Magenta.
• Long Entries taken (on the basis of trigger bars) are marked by Red Dots.
• Long Exits taken (on the basis of trigger bars) are marked by Cyan Dots.

I'm assuming I did not input your code properly. Please review and provide comments, or suggestions.
As always, I want to thank you in advance for you time and expertise.
Respectfully,

Attached Thumbnails
Click image for larger version

Name:	Issues 1 and 2.bmp
Views:	272
Size:	2.47 MB
ID:	212360   Click image for larger version

Name:	Issue 3.bmp
Views:	249
Size:	2.47 MB
ID:	212361   Click image for larger version

Name:	Issues 1 and 4.bmp
Views:	236
Size:	2.47 MB
ID:	212362   Click image for larger version

Name:	Issue 5.bmp
Views:	219
Size:	2.47 MB
ID:	212363  
Reply With Quote




Last Updated on August 2, 2016


© 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