76 lines
2.5 KiB
Text
76 lines
2.5 KiB
Text
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| MA3_MA20_1H.mq5 |
|
||
|
|
//| Strategi: MA3 potong MA20 - 1 Jam - Dupoin MT5 |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
#property copyright "Dola Trading"
|
||
|
|
#property version "1.00"
|
||
|
|
#property strict
|
||
|
|
|
||
|
|
input int MA3_Periode = 3;
|
||
|
|
input int MA20_Periode = 20;
|
||
|
|
input double Lot = 0.01;
|
||
|
|
input int StopLoss_Poin = 50;
|
||
|
|
input int TakeProfit_Poin = 80;
|
||
|
|
input ENUM_MA_METHOD Metode_MA = MODE_SMA;
|
||
|
|
input ENUM_APPLIED_PRICE Harga_Pakai = PRICE_CLOSE;
|
||
|
|
|
||
|
|
int handle_ma3, handle_ma20;
|
||
|
|
|
||
|
|
int OnInit()
|
||
|
|
{
|
||
|
|
handle_ma3 = iMA(_Symbol, _Period, MA3_Periode, 0, Metode_MA, Harga_Pakai);
|
||
|
|
handle_ma20 = iMA(_Symbol, _Period, MA20_Periode, 0, Metode_MA, Harga_Pakai);
|
||
|
|
return(INIT_SUCCEEDED);
|
||
|
|
}
|
||
|
|
|
||
|
|
void OnTick()
|
||
|
|
{
|
||
|
|
double ma3[2], ma20[2];
|
||
|
|
if(CopyBuffer(handle_ma3, 0, 0, 2, ma3) < 2 ||
|
||
|
|
CopyBuffer(handle_ma20, 0, 0, 2, ma20) < 2)
|
||
|
|
return;
|
||
|
|
|
||
|
|
TutupSemuaPosisi();
|
||
|
|
|
||
|
|
if(ma3[1] < ma20[1] && ma3[0] > ma20[0]) BukaPosisi(OP_BUY);
|
||
|
|
if(ma3[1] > ma20[1] && ma3[0] < ma20[0]) BukaPosisi(OP_SELL);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BukaPosisi(ENUM_ORDER_TYPE tipe)
|
||
|
|
{
|
||
|
|
double harga = (tipe == OP_BUY) ? Ask : Bid;
|
||
|
|
double poin = Point();
|
||
|
|
double sl = 0, tp = 0;
|
||
|
|
if(StopLoss_Poin > 0)
|
||
|
|
sl = (tipe == OP_BUY) ? harga - StopLoss_Poin * poin : harga + StopLoss_Poin * poin;
|
||
|
|
if(TakeProfit_Poin > 0)
|
||
|
|
tp = (tipe == OP_BUY) ? harga + TakeProfit_Poin * poin : harga - TakeProfit_Poin * poin;
|
||
|
|
|
||
|
|
MqlTradeRequest req={0}; MqlTradeResult res={0};
|
||
|
|
req.action=TRADE_ACTION_DEAL; req.symbol=_Symbol; req.volume=Lot;
|
||
|
|
req.type=tipe; req.price=harga; req.sl=sl; req.tp=tp;
|
||
|
|
req.deviation=5; req.magic=202606; req.comment="MA3-MA20 1H";
|
||
|
|
OrderSend(req,res);
|
||
|
|
}
|
||
|
|
|
||
|
|
void TutupSemuaPosisi()
|
||
|
|
{
|
||
|
|
for(int i=PositionsTotal()-1; i>=0; i--)
|
||
|
|
{
|
||
|
|
if(PositionGetSymbol(i)==_Symbol && PositionGetInteger(POSITION_MAGIC)==202606)
|
||
|
|
{
|
||
|
|
MqlTradeRequest req={0}; MqlTradeResult res={0};
|
||
|
|
req.action=TRADE_ACTION_DEAL; req.symbol=_Symbol;
|
||
|
|
req.volume=PositionGetDouble(POSITION_VOLUME);
|
||
|
|
req.type=(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)?OP_SELL:OP_BUY;
|
||
|
|
req.price=(req.type==OP_BUY)?Ask:Bid; req.deviation=5; req.magic=202606;
|
||
|
|
OrderSend(req,res);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void OnDeinit(const int reason)
|
||
|
|
{
|
||
|
|
IndicatorRelease(handle_ma3);
|
||
|
|
IndicatorRelease(handle_ma20);
|
||
|
|
}
|