-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
void OnTick() { ⋮ int movingAverageDefinition1 = iMA (_Symbol,_Period,20,0,MODE_EMA,PRICE_CLOSE);
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010) -
) ( entry="buy" );
Brackets are not the same as parentheses. You terminate a statement with a semi-colon; not brackets.
Some simple fixes:
1. You need to declare the object "trade" after including the mqh file
#include<Trade\Trade.mqh>
CTrade trade;
2. The buy and sell methods need to spelt correctly (capitalised 1st letters)
// sell 0.001 lot if(entry == "Sell" && PositionsTotal() < 1) trade.Sell(0.001,NULL,Bid,0,(Bid - 150 * _Point),NULL); // Buy 0.001 Lot if(entry == "Buy" && PositionsTotal() < 1) trade.Buy(0.001,NULL,Ask,0,(Ask - 150 * _Point),NULL); }
Now it compiles for me - give that a try.
Also when pasting code use "Alt+S" or click the "Code" button on the toolbar
trade.Sell(0.001,NULL,Bid,0,(Bid - 150 * _Point),NULL); ⋮ trade.Buy(0.001,NULL,Ask,0,(Ask - 150 * _Point),NULL);
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using 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 close to 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 spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using 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 close to 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 spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).
Yes, well observed - I was just aiming to make it compile rather than look deeper into it, but this will help the OP for sure
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i am fairly new to coding. its been two days since i have been working on this. compiling it brings 2 errors, i have checked the trade mqh file for help. but made more errors on the way.
here is the code.
-----------------------------------------------------------------------------------------------------------------------------------------------------
}
----------------------------------------------------------------------------------------------------------