#include <Trade/Trade.mqh> CTrade trade; int OnInit() { return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick(){ static datetime timestamp; datetime time = iTime(_Symbol,PERIOD_CURRENT,0); if(timestamp != time){ timestamp= time; static int handleSlowMa = iMA(_Symbol,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_CLOSE); double slowMaArray[]; CopyBuffer(handleSlowMa,0,0,1,slowMaArray); ArraySetAsSeries(slowMaArray,true); static int handleFastMa = iMA(_Symbol,PERIOD_CURRENT,17,0,MODE_SMA,PRICE_CLOSE); double fastMaArray[]; CopyBuffer(handleFastMa,0,0,1,fastMaArray); ArraySetAsSeries(fastMaArray,true); if(fastMaArray[0] > slowMaArray[0] && fastMaArray[1] < slowMaArray[1]){ double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK); double sl = ask - 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT); double tp = ask + 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT); trade.Buy(0.02,_Symbol,ask,sl,tp,"This is Buy"); } if(fastMaArray[0] < slowMaArray[0] && fastMaArray[1] > slowMaArray[1]){ double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID); double sl = bid + 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT); double tp = bid - 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT); trade.Sell(0.02,_Symbol,bid,sl,tp,"This is Sell"); } if(fastMaArray[0] > slowMaArray[0] && fastMaArray[1] < slowMaArray[1]){ } } }
i am newbie und learing mql5
Here it is the MA cross but now i do not know how to implement the Indicator Momentum and open orders
-
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.03.08)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020.07.05)
How to call indicators in MQL5 - MQL5 Articles (2010) -
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK); double sl = ask - 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT); double tp = ask + 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at 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).
-
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all
I hope someone can help me to programm this EA:
I would like to programm a EA with following informations.
open buy order if > MA cross (fastMA over slowMA) and Momentum >100.03
close buy order if > ( MA cross (fastMa under slowMA) and Momentum <99.97 ) or SL is open Price ( <10 Pips)
open sell order if > MA cross (fastMA under slowMA) and Momentum > 99.97
close sell order if > ( MA cross (fastMa over slowMA) and Momentum <100.03 ) or SL is open Price ( >10 Pips)
Open orders (buy/sell) until Margin Level is 500%
Thanks for your support