Differences using "THEN BEGIN ... END;" - EasyLanguage Programming | futures.io
futures io futures trading


Differences using "THEN BEGIN ... END;"
Started: by djvie11 Views / Replies:185 / 7
Last Reply: Attachments:0

Welcome to futures io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

Differences using "THEN BEGIN ... END;"

  #1 (permalink)
Trading Apprentice
Chicago, IL
 
Futures Experience: Advanced
Platform: Tradestation + Multicharts
Favorite Futures: Forex, Futures
 
Posts: 27 since Jul 2013
Thanks: 14 given, 1 received

Differences using "THEN BEGIN ... END;"

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


Last edited by djvie11; November 16th, 2016 at 01:19 PM.
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
 Vendor: abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,231 since Apr 2013
Thanks: 199 given, 693 received


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

Reply With Quote
The following 3 users say Thank You to ABCTG for this post:
 
  #4 (permalink)
Trading Apprentice
Chicago, IL
 
Futures Experience: Advanced
Platform: Tradestation + Multicharts
Favorite Futures: Forex, Futures
 
Posts: 27 since Jul 2013
Thanks: 14 given, 1 received


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)
Trading Apprentice
Chicago, IL
 
Futures Experience: Advanced
Platform: Tradestation + Multicharts
Favorite Futures: Forex, Futures
 
Posts: 27 since Jul 2013
Thanks: 14 given, 1 received

Futures Edge on FIO

Which time slot for our live webinar events works best for you?

 

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!


Last edited by djvie11; November 16th, 2016 at 06:29 PM.
Reply With Quote
The following user says Thank You to djvie11 for this post:
 
  #6 (permalink)
 Vendor: abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,231 since Apr 2013
Thanks: 199 given, 693 received

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

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #7 (permalink)
Trading Apprentice
Chicago, IL
 
Futures Experience: Advanced
Platform: Tradestation + Multicharts
Favorite Futures: Forex, Futures
 
Posts: 27 since Jul 2013
Thanks: 14 given, 1 received


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)
 Vendor: abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,231 since Apr 2013
Thanks: 199 given, 693 received

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

Reply With Quote
The following user says Thank You to ABCTG for this post:

Reply



futures io > > > > > Differences using "THEN BEGIN ... END;"

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

NinjaTrader 8: Tips and Tricks (part 2)

Mar 2
 

An Afternoon With FIO member @michaelleemoore

Elite only
 

Jigsaw Trading: Keys to successfully trading the open

Mar 9

Macro view: Trump Market Risk w/Piers Curran @ Amplify Trading

Elite only

Reading the Psychology of the Market w/Brett Steenbarger & Trading Technologies

Elite only

Hybrid Machine Learning (R and TradeStation) w/Murray Ruggiero

Elite only

Spring Grains Outlook w/Sean Lusk @ Walsh Trading

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
NinjaTrader Support on EVERY problem: "we are unable to replicate it in our end" little leo NinjaTrader 30 April 15th, 2016 10:16 PM
Is a front end necessary for TWS and if so which is "best" ......... Overview IB Trader Workstation 12 February 2nd, 2014 09:14 AM
Fukushima: "China Syndrome Is Inevitable" ... "Huge Steam Explosions", or "Nuclear Bo Quick Summary News and Current Events 0 November 22nd, 2011 02:50 AM
How to change "Stop Loss" and "Take Profit" in "shElderImpulse" Strategy javed759 NinjaTrader 1 November 1st, 2011 11:44 PM
"mid", "buy", "sell" volumes lokgotkent Traders Hideout 6 September 30th, 2011 02:24 PM


All times are GMT -4. The time now is 03:45 PM.

no new posts
Page generated 2017-02-24 in 0.11 seconds with 19 queries on phoenix via your IP 54.146.184.210