Module 1: Starting to Program
Module 2: Indicators and Functions
Module 3: Variables
Module 4: Inputs
Module 5: Exit Techniques
Module 6: Stop Orders and Limit Orders
Module 7 Using Multiple DataStreams in a Strategy
Final Strategy Coding Project
Module 8: Plot Studies and Their Uses
Module 9: Writing to Files
Module 10: How to Code Your Own Indicators and Functions


In this Lesson You'll Learn:


In this lesson we are going to take a practical look at “if statements”. 

By learning these, you will be up and running in no time coding your own entries and exits.

Now, have a look at the code snippet below:


What you just read was an if statement that gives the instruction to buy on the open of the next bar, if the close is greater than the open. 

In other words, the code snippet contained a condition, and an instruction

The condition was Close> open

The instruction was Buy next bar open

An If statement checks if the condition is true or false, and executes the instruction if the condition is true.

Here is another example


Translation: Buy if the close is greater than yesterday’s close.

How to get Started Quickly

The best way to learn if-statements is to start using them yourself!  

In the box below you have a template that comes very handy when you’re just starting out. Just by replacing condition and instruction, you will be up and running quickly, coding different entries and exits!

If condition  then instruction ;

Below follow some different conditions that you could use to replace condition and instructions you could use to replace instruction.

Right now we’re only going to compare the high, low, open and close of the bar to keep it simple. In the coming lessons you’ll be introduced to indicators and functions.


  • Close > Open
  • Close< Open
  • Close> Close[5]
  • Close< Close[5]
  • (H-C) > (H[1]-c)
  • (H-C) < (H[1]-c)


  • Buy next bar open
  • Sell next bar open
  • Sellshort next bar open
  • Buytocover next bar open


Try to build one if-statement for the entry and one for the exit. That way you will get a trading strategy that actually enters and exits a trade.

Remember that you can chain several conditions together. You just separate them with and, like below:




Now you just have to practice combining conditions and instructions yourself until you get the hang of it! In the exercise section below you will find a couple of exercises.

We recommend that you apply the strategy to a chart, and open up the performance report window. 

Then you will see the performance report change as you edit the strategy, which makes it a lot more fun!

Lesson Content
0% Complete 0/1 Steps

Login to Your Account

Signup Here
Lost Password