Price action

 

Hi, Community,

I'm very new to coding but have been trading for sometime. My question is can a custom indicator be created that would create a stop loss off the previous candles data?

If so can you pls push me in the right direction.


Thank you EJ

 

You'll need to know how to query all open orders and select the order from the order pool that you want to set the stoploss for. Functons to do this:

OrdersTotal() <- returns the amount of open orders in total. I.E., if there are 5 open orders, it'll return the number 5.
OrderSelect() <- grabs an order from the order pool. It returns True or False depending on whether the order was retrieved successfully.

Once an order is selected, you can use some filters, such as OrderSymbol(), OrderTicket(), or OrderMagicNumber(), using an if statement to see if it's the one you're looking for.

So here's what you'll have so far

for (int x=0; x < OrdersTotal(); x++){
   if (OrderSelect(x, SELECT_BY_POS, MODE_TRADES)){
      if (OrderSymbol() == Symbol()){
         <do stuff>
      }
}

Orders in the order pool start from 0. So if there are 5 orders open, the orders are 0-4, with 0 being the oldest order and 4 being the newest.

^ the above code cycles through all open orders and checks to see if the order is from the market (symbol) that the EA / Script is currently running on.

Once the order that you want is selected, you'll need to modify it. Function to do this:

OrderModify()

OrderModify() requires that you provide the ticket # and entry price of the order. This is already stored in memory once you use OrderSelect(), so all you need to is call it up using:

OrderTicket()
OrderPrice()

To get information from a candle, you'll need to know that the current open candle is 0. The candle before that (the most recently closed candle) is 1. The one before that is 2, and so on and so forth.

So if you want to grab information about a candle, there are two ways to go about this: a candle that's on the chart and timeframe in which the EA / Script is running from or a candle that's on another timeframe or another market from which the EA / Script is running on.

Open[x], High[x], Low[x], Close[x] <-- used in the first scenario
iOpen(...), iHigh(...), iLow(...), iClose(...) <-- use in the second scenario

To learn more about these functions, just put them in MQL editor, click in anywhere between the function name, and press the F1 key.

Documentation on MQL5: Trade Functions / OrderSelect
Documentation on MQL5: Trade Functions / OrderSelect
  • www.mql5.com
Trade Functions / OrderSelect - Reference on algorithmic/automated trading language for MetaTrader 5
 

Since you're new to coding, check out this YouTuber who teaches how to code in MQL: https://www.youtube.com/user/Jimdandy1958/videos

It's almost a complete course on coding in MQL, so scroll down to the very first video of his and work your way up to your level of experience or to what you want to learn about.

Jimdandy1958
Jimdandy1958
  • www.youtube.com
Mql4 programming lessons in English for those that have no programming experience. Go to www.jimdandymql4courses to subscribe to my beginners LEVEL 1 for onl...
 
EJ4: My question is can a custom indicator be created that would create a stop loss off the previous candles data?
You have only three choices: Search for it, learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you. We are willing to help you when you post your attempt (using SRC) and the nature of your problem.


user3822: You'll need to know how to query all open orders and select the order from the order pool that you want to set the stoploss for.
Indicators can not trade.
 

Thanks for the repays everyone it has been very helpful.

cheers EJ

Reason: