NexusFi: Find Your Edge


Home Menu

 





Differences using "THEN BEGIN ... END;"


Discussion in EasyLanguage Programming

Updated
    1. trending_up 3,538 views
    2. thumb_up 6 thanks given
    3. group 3 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Differences using "THEN BEGIN ... END;"

  #1 (permalink)
djvie11
Chicago, IL
 
Posts: 52 since Jul 2013
Thanks Given: 29
Thanks Received: 1

Hey guys

Just curious is there are any big differences between using "THEN BEGIN...END;" and not using them. Below are the sets of instructions I'm trying to compare. I'd like to figure out what (if any) differences would appear when the code executes (the 1st example does not have "THEN BEGIN," and the 2nd one does).

ex1
 
Code
IF
Condition1 
Then 
BUY ("goLong") THIS BAR ; 
IF Condition2
THEN SELL ("coverLong")   THIS BAR ;  

IF Condition5 AND Condition6
THEN SELL ("Trailing_Long") next bar at market ;

  
IF
Condition3
Then 
SELL SHORT ("goShort")  THIS BAR ;
IF
condition4 
THEN BUY to COVER ("coverShort")  THIS BAR ; 

IF condition5 AND Condition6
THEN BUY TO COVER ("Trailing_Short") next bar at market ;
ex2
 
Code
IF
Condition1 
Then BEGIN
BUY ("goLong") this bar ; 
IF Condition2
THEN SELL ("coverLong")   this bar ;  
IF Condition5 AND Condition6
THEN SELL ("Trailing_Long") NEXT BAR AT MARKET ;
END ;
  
IF
Condition3
Then BEGIN
SELL SHORT ("goShort") this bar ;
IF
condition4 
THEN BUY to COVER ("coverShort")  this bar ; 
IF condition5 AND Condition6
THEN BUY TO COVER ("Trailing_Short") NEXT BAR AT MARKET ;
END ;
Any insight would be greatly appreciated!
-Brandon

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
31 thanks
My NQ Trading Journal
21 thanks
Just another trading journal: PA, Wyckoff & Trends
17 thanks
Tao te Trade: way of the WLD
13 thanks
Daytrading ES & NQ
9 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627


Brandon,

there will be a difference between the codes and the reason simply is that in case you are using a "if ... then begin... end; " everything within the "begin" and "end" can only be executed while the condition you check for is true.

For you example 1 this means that you "goLong" order will trigger when Condition1 is true and your "coverLong" order triggers in case of Condition2 being true.
In your second example the goLong triggers when Condition1 is true, but due to the "begin" your "coverLong" can only trigger while both Condition1 and Condition2 are valid. Which depending on the actual checks for the conditions can be quite different.

You will have the same effect for your other orders as described for goLong and coverLong.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #4 (permalink)
djvie11
Chicago, IL
 
Posts: 52 since Jul 2013
Thanks Given: 29
Thanks Received: 1


ABCTG View Post
Brandon,

there will be a difference between the codes and the reason simply is that in case you are using a "if ... then begin... end; " everything within the "begin" and "end" can only be executed while the condition you check for is true.

For you example 1 this means that you "goLong" order will trigger when Condition1 is true and your "coverLong" order triggers in case of Condition2 being true.
In your second example the goLong triggers when Condition1 is true, but due to the "begin" your "coverLong" can only trigger while both Condition1 and Condition2 are valid. Which depending on the actual checks for the conditions can be quite different.

You will have the same effect for your other orders as described for goLong and coverLong.

Regards,

ABCTG

This is incredibly helpful, thank you ABCTG! Something like this changes how strategies perform a great deal.

I had no idea that when using "THEN BEGIN," All the above conditions had to trigger in order for the others below to trigger as well (ie, not covering a position when needed).

Reply With Quote
  #5 (permalink)
djvie11
Chicago, IL
 
Posts: 52 since Jul 2013
Thanks Given: 29
Thanks Received: 1


ABCTG View Post
Brandon,

there will be a difference between the codes and the reason simply is that in case you are using a "if ... then begin... end; " everything within the "begin" and "end" can only be executed while the condition you check for is true.

For you example 1 this means that you "goLong" order will trigger when Condition1 is true and your "coverLong" order triggers in case of Condition2 being true.
In your second example the goLong triggers when Condition1 is true, but due to the "begin" your "coverLong" can only trigger while both Condition1 and Condition2 are valid. Which depending on the actual checks for the conditions can be quite different.

You will have the same effect for your other orders as described for goLong and coverLong.

Regards,

ABCTG

Also, would something like this make more sense as far as order execution goes? Or is "THEN BEGIN / END;" unnecessary for each condition?


 
Code
// long trades
IF
Condition1 
Then BEGIN
BUY ("goLong") this bar ; 
END;

IF MarketPosition = 1 AND Condition2
THEN BEGIN
SELL ("coverLong")   this bar ;  
END;

IF MarketPosition = 1 AND Condition5 AND Condition6
THEN BEGIN
SELL ("bk_Trailing_Long") NEXT BAR AT MARKET ;
END;


// short trades 
IF
Condition3
Then BEGIN
SELL SHORT ("goShort") this bar ;
END;

IF
MarketPosition = -1 AND condition4 
THEN BEGIN
BUY to COVER ("coverShort")  this bar ; 
END;

IF MarketPosition = -1 AND Condition5 AND Condition6
THEN BEGIN
BUY TO COVER ("bkTrailing_Short") NEXT BAR AT MARKET ;
END;
thanks again for your time!

Reply With Quote
Thanked by:
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

Brandon,

for the above code the result would be the same when you use "if... then" or "if... then begin... end;".
No advantage, but no disadvantage either.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #7 (permalink)
djvie11
Chicago, IL
 
Posts: 52 since Jul 2013
Thanks Given: 29
Thanks Received: 1


ABCTG View Post
Brandon,

for the above code the result would be the same when you use "if... then" or "if... then begin... end;".
No advantage, but no disadvantage either.

Regards,

ABCTG

That makes sense, thanks so much! And one last thing .. what about assigning each condition a "MarketPosition" instead of leaving them without one? Would that matter at all?

example 1, all having a "MarketPosition":

 
Code
//buying conditions
IF Marketposition = 0 AND // (currently flat)
Condition1 
Then
BUY ("goLong") THIS BAR ;

IF Marketposition = 1 AND
Condition12
THEN SELL ("coverLong")   THIS BAR ; 

IF Marketposition = 1 AND
Condition5 AND Condition6
THEN SELL ("Trailing_Long") next bar at market ;

//selling conditions  
IF Marketposition = 0 AND // (currently flat)
Condition3
Then SELL SHORT ("goShort")  THIS BAR ;

IF Marketposition = -1 AND
condition13 
THEN BUY to COVER ("coverShort")  THIS BAR ;

IF Marketposition = -1 AND
condition5 AND Condition6
THEN BUY TO COVER ("Trailing_Short") next bar at market ;
example 2, no "MarketPosition" mentioned

 
Code
//buying conditions
IF Condition1 
Then
BUY ("goLong") THIS BAR ;

IF Condition12
THEN SELL ("coverLong")   THIS BAR ; 

IF Condition5 AND Condition6
THEN SELL ("Trailing_Long") next bar at market ;

 // short conditions 
IF Condition3
Then SELL SHORT ("goShort")  THIS BAR ;

IF Condition13 
THEN BUY to COVER ("coverShort")  THIS BAR ;

IF condition5 AND Condition6
THEN BUY TO COVER ("Trailing_Short") next bar at market ;
Your time is appreciated!
-Brandon

Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

Brandon,

not knowing your conditions I can't really comment on that. However think about what you do, you add another condition that has to be valid in order for the order to trigger. So it can make a huge difference of course.

I would suggest to test it yourself and see if it makes a difference. After all you must have a rational for adding the MarketPosition as condition and don't just add something because you can.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on November 18, 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