In this lesson we are going to create the scripting rules that will use this indicator to generate the orders for Long and Short trades.  Earlier we mentioned that the Entry Orders script section would execute for each data record in an instrument's file.  This is the perfect place to put our entry rule script because we want each price record to be reviewed without failure to ensure we don't miss a signal and create trade that is too late, or goes missing.

 

Note:

Take a few minutes to understan how  Trading Blox Basic uses its language operations by reviewing the tables on this page:

Operator Reference

 

 

To place our script rules click on the Entry Orders script listing the script window on the center-left side of the editing area.  

 

When the script section appears it will show a blank editing area.  Click any place in the editing area so that section has the keyboards focus.

 

To create an entry signal we have two parts.  The IF statement that determines whether to place the trade, and the BROKER statement which places the order.  We want to say something like, "If the MACD is goes positive then enter LONG on the open. If the MACD goes negative then enter short on the open.

 

This next example show how the above would look if we just need to only provide that information in Blox Basic:

Example:

IF macdIndicator > 0 THEN
  '  When the MACD is above 0,
  '  we enter LONG.
  broker.EnterLongOnOpen
ENDIF
 
If macdIndicator < 0 THEN
  '  When the MACD is below 0,
  '  so enter SHORT.
  broker.EnterShortOnOpen
ENDIF

 

Notice how the use of comments, colored green and preceded by an apostrophe character " ' " help tp make understanding your code rules easier now, and especially later when time has faded some of the details mentioned earlier.

 

When our code runs we don't want to continue adding units every day when the MACD is positive.  To avoid that condition from happening we need to add a little more conditional logic so the rules will know that once we are established in a position, we won't be creating any additional positions in the same direction until that direction changes and the MACD changes again.  This mean we need to put one more piece of logic that requires "If the MACD is positive AND we are not LONG already, THEN Buy on the open".

 

Enter the code in this next example exactly as it appears in this next section into the Entry Orders script section:

Example (don't type this line):

If macdIndicator > 0 AND instrument.position <> LONG THEN
  '  Two conditions must be met - MACD above 0 and
  '  we are not LONG, Then we enter LONG.
  broker.EnterLongOnOpen
ENDIF
 
If macdIndicator < 0 AND instrument.position <> SHORT THEN
  '  Two conditions must be met - MACD below 0 and
  '  we are not SHORT, Then we enter SHORT.
  broker.EnterShortOnOpen
ENDIF

Example - End (don't type this line):

 

What is shown in this last example is all there is to our entry logic. our entry logic.  When we view what we've typed it should look like what is shown in this next image:

Tutorial Entry Orders Code_01

Our block module now has the MACD as an indicator installed along with the parameters needed to control and we also have the rules needed to generate orders entered into the Entry Orders script section.  

 

This closes this lesson and we are ready to assemble the modules we will need to create a system.  Press the OK button so Trading Blox returns us back in the main screen.

 

Links:

Operator Reference

 

This completes this topic with the information we need to move on to the step in this tutorial.


Edit Time: 9/25/2017 09:09:54 AM


Topic ID#: 280

 

Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software