Algorithmic Trading Using OANDA API | Mayank Rasu | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Algorithmic Trading Using OANDA API

teacher avatar Mayank Rasu, Experienced Quant Researcher

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

3 Lessons (52m)
    • 1. OANDA Overview

    • 2. OANDA API

    • 3. SMA Crossover Strategy using OANDA API

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

This short course is continuation of my Algorithmic Trading course. This course familiarizes students with OANDA API and helps them build and test their forex trading strategies on OANDA. OANDA is the largest forex broker and this course delves into OANDA's python wrapper library which lets users automate their strategies.

Meet Your Teacher

Teacher Profile Image

Mayank Rasu

Experienced Quant Researcher


Hello, I'm Mayank. 

I have more than a decade of work experience with global investment banks in quantitative analysis/risk management. My work experience has made me a firm believer in taking data driven decisions while always being mindful of the qualitative aspects of my job. 

I did my undergraduate education in engineering and earned MBA and MFE degrees. I see myself as a life long learner and I deeply cherish the opportunity of sharing my knowledge with others.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. OANDA Overview: Hello, Friends. A lot of few have reached out to me saying that FX seem is not available in your country, and that includes US and Hong Kong and major trading nations. So it was imperative that I look at some other brokers which are similar to fxc em, but are available in some other countries where fxc, um doesn't operate. I mean, you can get demo ground off fxc m and believed the FBI and get a hangover it. But if you want to do actual creating, you will need to ah, go with a broker that is permitted toe perform operations in your country. Right? So I looked at a lot of other brokers. I went with FXC, um, because their a p I was the most intuitive and the most easy to implement. Right? But now that a lot if you have come to me saying that you want to get hang off another broker, which is hopefully in your country. So I decided to add Ah, another lecture video. I mean, actually a couple of lecture videos on the broker called Wanda. Right? So Wanda is probably the biggest FX broker in the world on chances are high that if if axiom is not in your country, wander definitely is Okay. So if either fxc a man or a woman lies not in your country, then less a massive bomber. And, uh I mean, I'll see if I can go for some other brokers. I mean, interactive brokers also pretty good, but their a p I requires a very steep learning girl. And I may ah create a new course for interactive broker. But just going to the FBI, I found it very difficult to get my head around it. And the learning curve was pretty steep, so I decided to go with Rwanda, Right? Why? Because it lets you play with its demo account, which is almost as powerful as fxc. Um, on two. It has a fairly good air documentation off its ah FBI python rapper, which I'll show you in this lecture video. So that's what I wanted tojust introduce you also, this is Wanda. So how do you get on? So I am going toe share these important links, right? Ah, the most important. You just need to goto Ah, the developer account rates. So let's start with going to the I think I'm already the developer Cone. So just go to this developer. One daughter Com link. Right. Onda, click on documentation. Okay, on, then, Goto arrest we 20 which is the new ah version biting library. Okay, on here it tells you how to get a freedom or count. So if you click on this link, you will reach here to Ah, and it gets you an option whether you want to open an effect street practice account or in actual life trading account. Great. Go with the pack. Basic owned, right. Select your country, blah, blah. Just put everything on and then you will get ah, practice account. You'll get a demo comb. Right? So once you get a demo account, you will get an option off either installing They're the stop trading application, or you can ah use the web creating terminal applications. So it's it's agree. It's an interface where you will see how yard Theresa performing. Okay, so that's one thing What is? Um yeah, So once you get the Freedom account access ah, you will need to get your ah rest ap access. And this explains fairly well how to get your FBI talking right So just like it mentions here. Just log into your account management portal on select manage FBI access and give you Ah, long alphanumeric key Late. Just like an fxc. Emma. Save it in. Ah, no. Pad and store it somewhere safe. OK, let me now log in to my coming in. Okay, so this is the nominal. Okay, So OK, so it's a practice account, right? What is it? I forgot in mine. Okay, so this is your, um this is your terminal, right? Ah, it doesn't look as good at a fix. IAM but it it's really light. And it's good it gets you all information that you want. Okay, so, uh, you see, it's not available in India, so I had to open a Canadian account. Right. So this is your account I d which you will require, Um, when you are doing a p A trading, so just and show that you know this number, your account ready? Right on. Then they give you $100,000 in whatever country currency you are choosing, right? So you can play with Wonder 1000 daughter of currency and then it gives you account information here, so I you're just playing with just putting some random traits, and I You can see that you can place your orders and all, and I'll show you using a cord how to go about doing it. Okay, so this is ah, the terminal rate. If you want to choose the right now, it's, you know, USD, I'll have to go with us djp right? Because right now it's early morning in India and, you know, used the market would be closed by now. So I think gyp gyp ey market would be open. So I'll change to JP way. Right? So lets go of it. USD jp Why? Yeah, so as you can see, um, So yeah, there is I mean, even this is quite a bit, but again, there is an action, so I think I can use us e j p y to demo. Ah, how toe actually go with. Great, right. So I just play with this terminal. Open your count on DA Get your Ah, you know, I mean, get some basic familiarity, Vitor Terminal. I'll not be using this terminal. I'll be using the fight in court toe make the trade. But this is important because you will see how you are fight and how your trades. Ah, you know, booked through accord are performing here. Right, So this will keep this green to face open. And the next video. I'll, uh, use biting Gord to book crates. Ah, fetch account information. Um, you know, leg, just stream date and things like that. Right? So in the next video, I'll familiarize you with the FBI off the fight an FBI off Rwanda, and we will perform some basic operations on your own demo account. Okay, so I'll see you in the next video. Thanks a lot. 2. OANDA API: Hello, friends. So let's get into the cord. Ah, the first thing you have to do is install the fight and rapper off the FBI. So the library name is Wanda up by B 20 right? You can simply install it using pip install either in the shell using this exclamation mark , or you can do it. Ah, the simple way in Anaconda prompt. Okay, so we have done that. So I'm not going to that There are a bunch of fly breeze that you will lead to a kind of import. I'll get to that step by step. When we perform every single step, I'll show you. How did these libraries I used? Okay. Ah, just like in. Ah, in effect. See, um ah, you will, um, just mention the part, right? And then you will create a connection. Right? Um ah. In FX, CMB used Ah, very logical connection here. We're using something called Client right on. What on this client does is that it needs your token part, which you have hopefully saved somewhere, Um, se freight, and then read it on then in the environment just mentioned practice because this is a demo account that you have, right? So once you run this command, actually, let me on this quickly. So once you run this command, it will create the connection, and then you already to perform other operations. So think of this Command has nothing but actually logging into your dominant. Okay, so the connection is made. Okay. Ah, Before we go into any further, I'll just show you the documentation that is required. Right? So this is the fight on rappers documentation. I already have it. Open hair, right? So again, there's two. There's important distinction between the heightened rapper. Ah, documentation on the actual FDA documentation. So what is a p I So a p I you see, like, these commands, right? So, I mean, most of you will not understand this because this is in Java and Web scripting language girl, if you know about their Great. So this is proper developer language rate. But ah, good thing is that they have created this, um biting rapper, right, but uses these commands, right, but dips it a python interface, which ah, facilitates is off accessing these commands and doing the same operations. Right? So that's waters doing It's simply using these commands and wrapping it in a beytin library so that you will be able to use it easily. Okay, so you see endpoints and definitions, right? So these are two things that are important for you are to understand if you want to use this FBI, right, So endpoint would be the connection that is required to actually perform operations, which is either placing order or getting your count. Somebody are getting your trade information sector arrayed on definitions. I'll come to that later. The definition is nothing but simply the parameters that are required for the command that you're putting in. And you will get to know where it as we proceed. Don't worry about it. Okay, so this is important. So what's the first thing that we want to do Here, let me go to the court. So the first thing is getting historical data, Probably the most important thing. Right, So we want to get historical data. So let's go to the endpoints rate instruments. Okay. In the instrument, it will tell you how to actually go about doing it. Right? So this these on various classes that they have created in the library, and you will have to import this. So you see, if I want to import if you If I want to get the historical price, I will have to import this model dot endpoints dot instruments. Right? You see, in this class So they have created this class like this, right? So I'll have to import. Ah, this instruments like Brady, which I have done here. If you see import wanna between leader in points or into instruments at instrument rates, that is the alias. So once we have this, we can have all the commands associated with this particular class, okay? And then began pretty much do anything that we warned for that particular instrument. OK, so how do we go about doing it? And again, you can see that they have urine sample court here on, um, it's, ah recommended that you go through them to understand what's going on, but I'll quickly tell you what's going on here. Right? So the parameters that you require to get historical data is the number off rules that you need, right? How much back you want to go right on the granularity that do want on to get these information. Right? So these are the parameters that go into some of the commands. Right? So any time you want to know what other parameters that can go into the command go into their definitions, right? The definitions instrument on hair. Ah, you know, candlestick granularity and retail you all the parameters that you that you need to give, uh, in orderto in order for the command to be done. Great. So that's how we use these two of sections. All the documentation, endpoints and definitions you have and pointing definitions in the ah, in your bite bite and rapper documentation as well. Okay, so that's it. Let me run this. So count 1 50 I want five minute candles and I want us djp white. Right? So I passed these parameters which are informed offer dictionary into this into my into my baby. I called rate on. When I run this, you can see that I've got a very nice Jason format off the output grade on DA again. It may be a bit scary looking. It's 1 $50 So it's a great a few, but so it say that it's a usdp y grand large is five minutes. Um, it was able to complete the call. Right? For the first grow, the volume is 15. This is a time stamp on. Then open high, low closes this. Okay, then is the second row and like that? Great. So this is a Jason format. So Jason is nothing but listed dictionary. Some people get a bit intimidated by this, but it's fairly straightforward. And I tell you how you can fairly simply are converted into a data frame rate. So this is how I have converted it into a data frame. Nothing fancy at all I'm doing is that I am saving. Ah, This, um, saving was just on into a dictionary. So let me go to my dictionary. Right. It has won 50 goes on. Then I want to extract the open, high, low, close and I want to extract the volume. And I also want to strike the time which I will use as the index off my radar frame. Right. So how do I do that? All I do is I simply convert ah, this dictionary into a data frame on. This is how the data frame looks. Not something that we want. Right. So we'll have to do some for the mortification. And how do we do that? Um, I apply something called Ah, Bandit. Or to see these function right? And what it does, is that Okay, let me show you step by step. So first of all, is first of all I am looking at, I am taking this med column right on This mid column has our dictionary, l agency, and it has opened high locals. All I want to do is is that I want to split it into other into columns off hope off. Open, high, low and close. Right. And you can do that using this command. All you ever do is apply Donna Tartt CDs. Okay, so let me run this right. And now, if you open this, you have which L c Ah, you have Chelsea as a separate columns in this Ah, data free markets, the MBA Scordia right now. But this is not everything we need to. We need to include Wall Luminal, and we also need to include the time stamps here on these two commands are doing. It's fairly straightforward. I'm not going into that. Um because we have done that before, as well. One thing you have to keep in mind is that all of this is in. This isn't it's not new Medic. It's not florid. This is all string. This is all ah, string format rate. And how do you know that in data frame? And that's because string is if you have new medical floored, you will see colors. Here it will. You'll have colored columns. That's how data frames in pandas work, right? So just looking at this, it tells me that this is text, so I'll have to have this past one command to convert these into numeric rate. So this is the final data frame, right? It has open, high, low, close on. It has volume, and it has time stamps here, Right? So now we're getting into familiar territory that that's how way are used to looking at historical later. So I mean, all you can do is that you let me just add these commands on DA whatever. Ah, FBI call that you make and whatever, commander, to pass, you'll be able to get ah, using these commands, you'll be able to convert the Jason format into ah, fairly understandable data frame. This is your historical data, right? Now, how do we stream later? Right the streaming there, guys, um, you know, if you want dick level data, if you want every second data, you can use it, so they don't I mean, usually. Ah, these libraries are these FBI providers provide a special or provider different kind off a command that helps you stream. But I didn't see that head in Rwanda. So all you have to do is that you'll have to use a loop kind of friend through, um, you know, if you look through ah, your command and then keep using the same, um, keep using. Ah, the same request called pricing in four. Great. So pricing in four will give you the actual price at a given moment of time. Right on. Then, using loop, you can just keep printing out the price after every Milly second around the second or whatever is the frequency in biting rate. So to get the pricing in four the parameters that you need as instrument, that's the only thing right on. Then you also need your account. I d. And how will you get account I d. As I mentioned, if you go to your interface right. You will see your account. I d there. Right. So that's where you get your account ready from rate. And then, Ah, all you have to do is import on endpoint called pricing rate. Let me go back to the endpoint section. But I sing and you will see that I've just used a commander. They have mentioned there nothing fancy. Um, is going on here, right? So eso the pricing model has been imported. And all I'm doing is that I am calling the that more duel, and I'm using the pricing in four. Function off that model. I'm passing the county and parameters, and I am getting the price information. Right. So let me quickly show you if I had wondered ones what happens, right? So to the connection has been made. So if I run this once, right, you will see that I'll get a price here. Right? So I get a price. Ah, I get the total number of beds. Ask what is the close out bread? Where's the clothes? I would ask and all these information, right? So I only warned the bid and ask prices on their time. That's the only thing that's that I find useful in this particular Jason. Right? So that's what I've extracted. So if I run this, let's see what happens. You can see that. I mean, because markets are quiet. I don't expect the the price to change, right, Because I write No, the market has court and down. Ah, but you can see that using this, you can actually stream and see how the prices changing. I recommend you do it at the peak, Correct? Just when the markets open, Um, when I say markets open, I mean, when the actual trading activity start for a given currency, pair on, then you will see that this is changing frequently. Right? So this is about getting historical data on streaming data. The most important things. Ah, when you are using FBI to play straits, Okay, Now what's the next important thing? Next important? 10 years account D days, right. Let's go back to our documentation. Where is the end point? Where is account so that your account, great and account will give you information about how much money you have remaining. What kind of creating what kind of instruments you have and things like that. Great. So for account. The class is endpoints or accounts. Right? So you import that on, then It's very straightforward. All you have to do is and this is gives you information. Like what kind of functional these are enabled. Disabled it sector of what is your account? I d, um, Things like that. The middle data on your account. Okay, um, what's your p NL workers? Your balance and things like that. Okay. Ah, Similarly. Similarly, there's something account. Somebody. This gifts you somebody of the count and tests upset off your account details. Fate, as you can see. So you can either use somebody or details if you want to extract information like BNL and things like that. I don't think unrealized panel is here, but you can get unrealized piano in the summary one. That's why I chose to give you both this. Because if you're trading, you need to understand what you're unrealized being alone. If you want to have a kill switch on DA, that's something that that's something that account somebody can help you with. Okay, So darts account, right? And now to how to place orders, right? So, for orders, let me go to the endpoints orders. So you have, as you can see, the it's called Own up ivy, $20 en pointe. Start orders. Andi, I have imported Ah, this dictionary, This library here. Right, So we have orders. And then within that module, I want oh, create a new order rates. So for that, I will go toe to create, right, And it gives you a sample court. But I have spent some time in order to make it a bit easier for you. And I'll show you how to go about doing that. Right? So the thing that you need to set up the parameters that you need when you are placing a trade, right, and what kind of information is this? So, um, so you need to create Ah, gain adjacent format, right? Lister dictionary. Ah, you have to provide order information. What price? You want to do the trade on? If that if. If it's going to be a stop loss on Phil. Ah, what kind off stop loss place. Ah, you want to give what? The time in force? And this is something back on wants you to provide time and force and different mark miss a market order or limit order would have different time and force. And you can get that from documentation. I'll give you a brief somebody about what? To use it. Right? Then what's the instrument you're trading? How many units off the instrument you want to buy yourself, right? If you want to sell here, just change it to minus 100. So that's how it works, right? Um whether what What type off trade it's going to be. It's going to be market and things like that, right? So market or limit and again, Ah, the details section rates. So definition section will give you information about all these parameters, right? So if I goto order right and then I go toe ah, market order. So it will give you all the information that all the parameters that needs to be there, which is required, which is optional when you're trying to place a market order or ah, limit order or things like that, right. So you'll have to use both these documentations Ah, if you want to extract the most out of this a p A. Okay, so let us quickly create a just book. A trade, right? So this is my This is the parameters that will go in right. So I'll have to use the function order, create, right? I've already imported this morning called Order Straight on. Then within that function, I need to pass in the ground. I d Andi, this information this Ah, Jason here. So if I run this, I'll be I'll buy 100 instruments off for us. Djp. Why? So let me have the green front and let's see how it works. Right? So if I run this if I goto orders, I have an open position here that I just placed. Okay, Andi, that's the position. This order has been filled, so I have a position. I have a long position. OK, so that's how you place an order. But again, this is a fairly cumbersome way off placing an order, and you want more flexibility, right? So I've created ah, small ah, uh, kind of function, which you can use to place market order on you. Just using this, I would encourage you do you know, create other functions that use this Jason format and you can create a function for market order, limit, order, stop order and things like that, right So what have I done in this particular function, right? Ah, what I've done is that I have used Ah, I have used this Justin format. Right? Andi, all I've done is that I have changed or I have changed these hardcore did values in this list of dictionary by the by some variables that I'll pass in this particular function. Right? So I won a function where and I just put in market underscore order. Then I just in the in the back it I give the parameters of what instrument I won't do by how many units I want to buy or sell on. But what's the stop loss level that I want for that particular market order? And that's what dysfunction will do. So Harvard, how dysfunction work, right? So in the proper hamza variable rate, I'll past instrument rate. So this is the instrumental part in the function which will get picked up by this particular parameter rate than account ideas constant. So I'm doing it for my account, so account I d will be concerned here. Eight. Then. Ah, what this is doing is that it's it's getting It's capturing the pricing in for recall the pricing and for function gives you the bid and ask and all the other information pertaining to the price often instrument. So that's what I'm doing here. Right on. What I'm doing here is that I'm saying that if Eunice is good and zero rates, what does units get in and zero mean? It means I'm buying that many units off that particular instrument and if you it is less than zero right, it means that I am selling that many instruments of that particle of that many units of that particular instrument. So I've just created this small FL statement. But I'm saying that if it's a long kind of, if it's if it's if it's a long order, then pick up the ask price. If it's a short our order, pick up the bid price right on. I have also used another variable called stop loss right and I'm doing All I'm saying is that if I'm going to place a market order at the on going market price right then just have the stop loss level as the price minus SL right and I'll provide the stop loss level like how many Pips do I want eight tips on nine pips of six pips based on the ball gritty of that particular instrument. Whatever is a stop loss level here in the form of pips. Um, I'm just going to I'm just going to add that to the price. Also struck that to the price to come up with my stop loss level. Okay, but that's what I'm doing here and then in the data I have just removed some of the hardcore did stuff with with these ah, values did variable that I'm creating, Right? So that's pretty much it that you want to know, right? Ah, one more thing. Here is time and force gave me a lot of problem. Actually, let me show you what kind of problem it gets me. So if I change it toe if OK, actually, let me have it. UTC, let's change time and four, So I'm actually let me. So these are various. Some kind off diamond four scored start. OrNda uses rate. So let me and 80 are I'm using a dislike in the previous example. I'm using it er, to come up with the stop loss level Right on. That's what we I think all if you know this already, because you spend quite a lot of time on this on this foot. Also used in the strategy for FXC. Um, so you know why I use 80 and I use a tr to come up with the stop loss level. Okay, so if I run this, I will get an error. And I want you to undersea that error because that will help you understand what goes on here, right? So I run it sticking slightly longer than it should. And you see, that order has been rejected rate. And what's the reaction reason? Stop loss on free time in force. Invalid rate again for this also, it's very good to go through the documentations if you go to troubleshooting and errors. Right? So then come here. And you can just go to this trouble shooting bay janitor give you information, right? So what? It tells you so based on the documentation, I think Ah ah, the problem is that for thyself, if you're placing a market order time in order, time and force can only be either Fok or GTC rate and stop loss on Phil can only be gtc, right? That's what I figured from the from the recommendation, I encourage you to go through it. And when you're troubleshooting, you will understand what's causing this. Right? So if I run this now, this your work. So I am placing Ah usdp by order off, actually a place the order off 108 100 rate. So let me put minus 100 said I'd be close out the position. So it's us, jp Why? I want to sell 100 positions right on then either stopped lost level that I'm giving us three times 80 out off previous 1 20 instances rate So that's what I am doing here. So if I done this, this should work. I think this work. So if I go to my Gui, you can see that now the pollution has closed. Trade it. I was able to close out the position and then BNL you can see that I lost two cents because of this, right? So that was it. Actually, I should have shown you this last FBI call. Call open trade side right now because we don't have any open traits. You won't get anything, you'll get a blank. Ah, kind off. Ah, Blank. Yes, on. But if you have an open position, if you run this particular command and for that you need the trades and point rate, you need to import this. So if you run this, you will You will get the information about the open positions that you have open crates that you have, right? So this is Ah, thes are the basic functions that he will require to use this Ah, particular FBI. As you can see, it is not very difficult. It's quite intuitive on it. ISS fairly powerful. I have not got any drop connection yet. Some of their some problems very in. Ah, they are very particular about what parameters you need to pass, for example, time, important sector. But you get around that once you start using it on the documentation does a pretty good job off explaining how to troubleshoot this particular errors. Right? So I encourage you to play with it, right? And, um, in the next video, I'll implement a proper strategy using on Warner using these functions. So I'll see you in the next lecture. Thank you. 3. SMA Crossover Strategy using OANDA API: Hello, friends. So in this video, we will implement a strategy on Wanda FBI. Okay, The strategy that I'll be implementing is a fairly straightforward SM a crossover strategy . It's pretty popular and fairly easy to implement. So I'll be using this as a demo off. How we can ah ah use one day p i to pretty much implement I entire strategy. Okay, so I'll be sharing the link to this article which gives you an understanding off. What is Osama crossover? Pull back. Right. So what we are doing in Assam across So where is simply playing with these three technical indicators? The 100 day? Ah, simple moving average. The 200 day simple moving average does they can bpd it. So if I'm using five minute candles so I'll be using 100 five minute beard averages and then 200 period sme. And then there's something called stochastic indicator. I have not explained to goddess in the stochastic indicator, but I'll be sharing the court for it, right? You can just ah, just just search the web. It's a fairly straightforward, simple technical indicator, and you should not really have problem. Ah, you know, understanding what it does. Okay, So what other entry rules by on the first instant that stochastic post up from the over sword area after an upward SME crossover takes place? Quite a mouthful. But what we're doing here is that say, this is the 100. Say the red line is the 100 period. Assimilate the fast moving average and then this, um this blue line is a 200 a period moving average rate. So once the fast moving average cuts the slow moving average from below Right then after this point and whenever the first time, the ah Stochastic crosses a 25 level right. Ah, you. That's a buy signal, right? Likewise, when the opposite happens, right when the slow moving ah cuts the fast moving from from top rate than the first time the stochastic ah cross goes below 75. That's when you go into a sell position. So that's what ah sm across what is again I'll share this selling go through this. Ah, you know, I think I don't just try to understand what it does. Okay, so let's go back to the court now, right? So how are we going to implement it? Let him first import the library's rate. Ben, I am just, you know, a list on the previous lecture. We are creating the client object using the FBI key that you have stored. Right Then you can use whichever currency pairs that you want. So this is how we this is the format off currency pair in Wanda. In effect, CME, I think if I recall, it was ah, forward slash. Let me see. What was it? I think it were. It was so weird. Slash rate in, um, in. Ah, Wanda, it is Underscore. Right. So we have. So I'll be using the spares in the strategy, so I'll be scanning through every single off the spares, right? Looking for a signal. Right then. Position size 2000. Ah, Duck and Janie, Based on your risk appetite, I typically go with smaller position size for each trade that I get. Right. Then I am creating some global variables, right? Ah, that's called up board SME, our directory and downward SME directory. Right? So what? I'll no, sorry. It's dictionary eight. So what I'll be doing in these dictionaries is that I'll be storing, um, at the information whether the cross what has happened or not, right? The upward SME crossover or downward Osama crossover has happened or not for any off these currencies. Okay, so that's pretty much what i'll be doing here. And that's something that I do Is that if you recall from the from the strategy, right, So once this thing happened, so once this ah, crossover happens, right? Then you need to wait until the second technical indicator is also in the you know, it has also kindof created the signal rate. So you need to have a way to store this information that this up upside close of what has happened, right? So that is what we're trying to do here. We're trying to store if the crossover that having an art and this is a global variable. Just, um if you don't know what is global, very well, just look it up in Brighton and I'll tell you how to use these global variables when you're trying to call them inside functions. Right? So this is a simple stochastic implementation again. I'm not going into that. I encourage you to go through the school. It's fairly straightforward. And also look for, you know, just looking the Web. How? What? What the stochastic doing? Okay, if you have any questions regarding what I've done here, feel free to push in the Q and a section it It's fairly straightforward, right? S m m not be already. Have ah seen it a lot of times, right? So I have a fast moving S m and a slow walking sme right then. Ah ah, Candles is the So I'm. I've created ah already call function. Ah, that will pull five minutes. Candles, right? And I'm getting to 50 candles. I have also discussed this in the previous lecture video, so I'm not going to that rate. So this what this ah function will do is that if you give it ah, currency, right. It will, uh let me assure you, it will, uh, have created data frame, but all the can with all the candles. Right? So let's do it for which one and let to use Ah, Euro usti. Right. So let me try this straight, so All right. I think so. So this is how it create rates are open, high, low, close and volume for all these time structure, it has 2 50 candles stuck. Ah, we have put it. Great. Great. So this is fine, then. Ah, me. I also showed you how you can create a function that will use this parameter a la you know , Jason, for format kind off. Make it simpler in a python code to kind of give orders. Right. So, uh, we discussed this market order in the previous lecture video in this. Ah, in this strategy, I have weak dysfunction slightly right. Instead of using stop loss I've used trailing stop loss rate on. Do you know that? In effect, CME. I told you I am a big fan off using this functional legal trailing stop loss. So what changes in this function is that instead, off price? When we go for a simple stop loss, right, be the parameter Was price on we mentioned what's what At what price do we want to stop loss to be triggered in this case, we mentioned distance, rates or distances. Um So what we're distance does is that if you have a trailing stop loss, right, and you have mentioned that I the distances say eight pips, right? So once you enter, trade on the trade starts going into the favorable direction. So this trailing stop loss level a stop loss price will also start moving in the same favorable direction. Right? And when you're create, starts moving in the opposite direction. This will not move. This will get static. Right? So this distance is the minimum. Um, not minimum is the maximum distance that you will have from your actual market price. Right? So it's a fairly ah, like I find it very powerful functionality. And if you are comfortable with it, I would encourage you to use this as a way to create. Great. So this is the only difference that I ah, that is there from the previous lecture where I discussed the market order. Right. So dysfunction Ah is ah, it's for market order, right? It er we already know why we use we use it toe calculate The number of pips are like this distance. What is the average true range? I use that I tend to use a t r a lot. So December 1 of the previous electric videos on Y V use that right. So this function is ah, the most important one here. And I want to tell you what's going on here? It So you see that I'm passing the data frame, right? So I'll pass a data frame in this particular function. And I'll also pass the currency for which car and see, I am trying to find the signal, right? And then within this ah, within dysfunction, you can see that I have called the global um ah, global variables that I created, right. Ah, the upward estimate. Ah, dictionary and the downward sm a dictionary. Eight. Ah. Then I be start. But, you know, I initiate. Ah, this variable signal is blank. Right? And then we'll see if this particular function will return a signal or not. Right. So what is going on here? Right. So what I'm saying here is that if the fast moving average is greater than the slow moving average, the final value right on the second last value is opposite rate. But in the fast moving average is less than the slow moving average rate. Then we say that the cross So what has happened, right? This is something that we have used before Also again. So this is ah, body call. This is how we will hardly showed that the line has cut another line from below, right? This is how I do it. If you have a better way, let me know, right? I'll be all years. So if this thing happens, we will change the corresponding value for whether the s m. A r Upward s a maker. Also, what has happened or not for that particular currency as true, right? Since this is ah, condition for upward cross over this downward crossover will remain as false. Right? So that's what I'm doing here. Uh, I'm simply trying to see I'm simply trying to update whether the crossover upside go. So what are down? Safe? Grow. So what has happened or not? Right. This is what's happening here late then in these conditions. What? I'm saying that if the cross what has happened? Meaning So what has happened in the recent past rate? Andi? Ah, the stochastic is also has also crossed the 25 level, right? What I'm doing here is that so stochastic has two lines as well. I'm saying that both these lines are greater than 25 Onda the previous the penalty dimmer Ah values for K. These two lines is less than unify, meaning it has crossed 25 level from below. Right? So if this thing happens in signal is by if this happens, then signal is cell. Right? So after insuring that are could also information is updated right again, let me remind you, these are global variables. So whatever value we update here get stored. So it's not that after every operation it will get reset. Know whatever ah value We update it gets, Ah, it gets stored in the global variable rate. So if if I'm not running this part again whatever value has bean updated toe this particular value off the dictionary with stick, you know, it will be like a sticky value. Right? So this is what's happening here. You will appreciate what I've done here because I see a lot off you asking me about visualizations so going forward, I've tried toe put individualization. So what these the small snippet court step it is doing is that after every integration, it will show you how these SME line and the stock at stochastic lines are looking after that particular situation so that you so that you can visualize whether the signal is making sense or more. OK, so that's what I'm doing it Even if you remove it, it's fine. It's just that it will help me to explain to you what just happened. Right? And then this function returns. Ah, the signal. OK, then what? As then, the final final function. The main function is where everything comes together right after this. Ah, you have pretty much calculated everything that's required to implement the strategy. So all I'm doing in the main function is it reading to every single, you know, a currency pair that we want to retreat through, right? Ah, just make sure that, you know, uh, we are. What we're doing here is that we are creating Ah, the candles for that particular currency then, Ah, calculating the stochastic values, calculating the slow and the fastest mm values. Once you have all this, we pass the updated data frame in tow. The signal? Ah, into a signal function which will give me my signal with its by yourself. Wanted by yourself accordingly. Take the trade right straight is ah, trading Stop loss. Right. So once it goes, you know beyond what I consider as a special rate, the pollution will close out. Right? So this is pretty much it and you can make this. Ah, you know what I'm doing here? Based on my previous video, right? Ah, so in this Ah, gored. I'm trying to rent for one hour. Right? Um so every five every 300 seconds, meaning every five minutes, the main function will be triggered rate. So we'll keep triggering main function after every five minutes rate. And then we'll see how this thing is. Um is you know how our strategy is proceeding. Right? So this is what the strategy is. Let me quickly show you how the which and see the Actually I have run this. So let me show you how originated Did a frame will look for a given currency after you. You know, after you Ah, run it through the dysfunction So you can see which Elsie on volume are already here. Ah, you have the fast moving, um average slow moving average 100 day 200 day. Then you have the stochastic values capital can capitally Great. So this is pretty much everything we need for our strategy. Ah, so let me now run this entire court and show you how it s personally. But today is Ah, 13 somewhere. And ah, significant event has happened, which has made the market scored watertight. So Ah, British election result game. And it's getting more and more certain that Brexit will happen. Right? So today I saw a lot off action in the market. So I'm not going to run it for the entire one are. Let me show you. Ah, how this thing will run, right? So if I don't the main function it will it rate through all the currency's rate, all these currencies and it will show you what's going on. So the FBI is slightly slow. I've seen that. Maybe it is for the practice account, but I see there is a little sea off around 5 to 6 seconds when you have any p a girl and slower towards like, you know, when the markets are active. Yes. So let it run. So you see, this is for, you know, us knee. So you know, USD You can see that the crossover happened sometime here. So I have You can appreciate the visualization, right? So this Ah, for you know, us did. This is the graph for Ah the close price which is blue, the fast moving SME and the slow moving s emirate. So you can see if I had I started Ah, had I started Ah already got, uh, creating at this particular position. Right? Whatever time was this, the crossover has happened here. Eso the fast has fast has got it from cooperate. So then after this point, I'll be waiting for the level to go beyond below 75 I can see that that has not happened yet. So I until now I have not got the signal. So you can see that I really I mean, if we hard a slightly ah more relaxed special for stochastic We would have what a signal here and would have made some money. So maybe if you think 75 is too high you can revise 75 based on your trading speed, you can make it 60. You are. You know, whatever you feel is a better stochastic indicator that comes from practice, right? So again Ah gbp usd again. Lord of all Really, today you can see I know this I did is no gross orders happen there, right? So no, nothing in Ah, us D c Jeff. Good night. Likewise you the USD. I don't see anything interesting. Operate. So last one is he was the God let let's see how the U. S. D card is looking so again if you see that this situation really helps, you appreciate that whether the signal was correct on art. So that's why I have I've ensured that I'll start using this right here. Also, this is diverging. So there is nothing interesting happening, right? So in this situation, I did not get any signal. But again, we'll keep running this every five minutes and see whether we're getting any signal, not let me show you one more thing. Ah, the upward sm a directory. So this will So right now everything is false at eight upward downward, a semi directory. Also, I think this also everything's fall because we did not see that any off the values cut at at the at the last level. Right? So that's why it's, as expected. All all the signals are false, right? So again. But as he proceed, Hume, a good signal and you may get into trade. So this is ah, one. Ah, you know implementation often. Entire strategy. This is a fairly simple strategy. You may want to add a lot of bells and whistles into your court and make it more complicated. Right. But I would urge you to start with toe demo account and start with something simple on, then get into mawr. You know, fancy strategy, like implementing something like simple crossover are simple. Moving average implementations would be much better when you're starting out. Okay, so that's what I wanted to discuss. Ah, for Wanda, I hope affects IAM at Wanda are kind off completes the coverage for pretty much holder geography. Is that you guys that in on DA If you will live in a jurisdiction that doesn't support either $1 fxc m Let me let me know. I'll be very interested to know. I'll try to see if there is something else that we can hard, So thanks a lot. I hope you like the lecture. Thank you.