Duration: ~1 hour | Instructor: Dr. Raymond S. T. Lee
Learn how to design and implement automated trading programs (Expert Advisors) in MQL5 — the foundation for Quantum Trading strategies.
#include <Trade\Trade.mqh>
CTrade trade;
void OnTick()
{
if(PositionsTotal() == 0)
{
trade.Buy(0.1, _Symbol, 0, 0, 0, "QF Buy");
}
}
// Check open positions
for(int i = PositionsTotal()-1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(PositionSelectByTicket(ticket))
{
double profit = PositionGetDouble(POSITION_PROFIT);
if(profit > 50.0)
trade.PositionClose(ticket);
}
}
// Set Stop Loss / Take Profit
trade.Buy(0.1, _Symbol, 0,
SymbolInfoDouble(_Symbol, SYMBOL_BID) - 50*_Point,
SymbolInfoDouble(_Symbol, SYMBOL_ASK) + 100*_Point);
#include <Trade\Trade.mqh>
CTrade trade;
int ma_fast, ma_slow;
int OnInit()
{
ma_fast = iMA(_Symbol, PERIOD_H1, 10, 0, MODE_SMA, PRICE_CLOSE);
ma_slow = iMA(_Symbol, PERIOD_H1, 20, 0, MODE_SMA, PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
void OnTick()
{
double fast[], slow[];
ArraySetAsSeries(fast, true);
ArraySetAsSeries(slow, true);
CopyBuffer(ma_fast, 0, 0, 2, fast);
CopyBuffer(ma_slow, 0, 0, 2, slow);
if(fast[1] <= slow[1] && fast[0] > slow[0] && PositionsTotal()==0)
trade.Buy(0.1, _Symbol);
if(fast[1] >= slow[1] && fast[0] < slow[0] && PositionsTotal()>0)
trade.PositionClose(_Symbol);
}
trade.Buy() and a pending Buy Limit order. When would you use each in a quantum trading strategy?PositionGetDouble(POSITION_PROFIT) return? How can it be used for dynamic exit based on Quantum Price Levels?QF Workshop #6 – Programming Trading with MT5/MQL5 | Dr. Raymond S. T. Lee