Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger at a specific Bid price, add the average spread. MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.) Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.
Anything to do with MT4 should be posted in the MQL4 and Metatrader 4 section.
Oh I am sorry, I shall post in that section from now on. Could you explain why is the bottom part of code independant of the top part? Everywhere I've seen this code it has been written the same way? Like on this page: https://www.mql5.com/en/forum/139592 Also what is the styler?
The styler quickly brings a source code design in line with the recommended standard. This makes the code look professional and easy to read. A well-designed code is much easier to analyze in the future both for its author and for other users. To launch Styler, click Styler in the Tools menu or press Ctrl+,. General Spaces and blank lines...
henrygeer: Could you explain why is the bottom part of code independant of the top part? Everywhere I've seen this code it has been written the same way?
Do not just copy examples of code without understanding what it is doing.
if(Close[0]>Open[1])
if(OrdersTotal()==0)
ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*Pips),Ask+(TakeProfit*Pips),NULL,MagicNumber,0,Green);
if(ticket<0) //This is not indented so is a different block of code not related to the above ifs
{
Print("OrderSend failed with error #",GetLastError());
}
elsePrint("OrderSend placed successfully");
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
You buy at the Ask and sell at the Bid.
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.
I'm so sorry I thought I posted it in the expert advisors section! Won't happen again I promise
Which is the wrong section.
Anything to do with MT4 should be posted in the MQL4 and Metatrader 4 section.
Which is the wrong section.
Anything to do with MT4 should be posted in the MQL4 and Metatrader 4 section.
Also what is the styler?
https://www.metatrader5.com/en/metaeditor/help/development/styler
Could you explain why is the bottom part of code independant of the top part? Everywhere I've seen this code it has been written the same way?
Do not just copy examples of code without understanding what it is doing.
Your earlier code....
Now use the styler
Change your code using a pair of { }
and use the styler
now you can see that the complete block of code within the { } is executed only if the if condition is satisfied.