76 lines
1.3 KiB
Text
76 lines
1.3 KiB
Text
#include <Trade/Trade.mqh>
| |||
CTrade trade;
| |||
| |||
// ===== INPUTS =====
| |||
input double LotSize = 0.1;
| |||
| |||
// ===== GLOBALS =====
| |||
int macdHandle;
| |||
double macdHist[3];
| |||
| |||
// ===== INIT =====
| |||
int OnInit()
| |||
{
| |||
macdHandle = iMACD(
| |||
_Symbol,
| |||
_Period,
| |||
12, 26, 9,
| |||
PRICE_CLOSE
| |||
);
| |||
| |||
if(macdHandle == INVALID_HANDLE)
| |||
{
| |||
Print("MACD handle failed");
| |||
return INIT_FAILED;
| |||
}
| |||
| |||
return INIT_SUCCEEDED;
| |||
}
| |||
| |||
// ===== VOLUME DELTA (GREEN) =====
| |||
bool VolumeDeltaGreen()
| |||
{
| |||
long volCurrent = Volume[1];
| |||
long volPrevious = Volume[2];
| |||
| |||
return (volCurrent > volPrevious);
| |||
}
| |||
| |||
// ===== MACD LIGHT RED =====
| |||
bool MACDLightRed()
| |||
{
| |||
if(CopyBuffer(macdHandle, 2, 0, 3, macdHist) <= 0)
| |||
return false;
| |||
| |||
// Red histogram, but weakening
| |||
return (
| |||
macdHist[1] < 0 && // still red
| |||
macdHist[1] > macdHist[2] // lighter red
| |||
);
| |||
}
| |||
| |||
// ===== MAIN LOOP =====
| |||
void OnTick()
| |||
{
| |||
// ---- Run once per candle ----
| |||
static datetime lastBarTime = 0;
| |||
datetime currentBarTime = iTime(_Symbol, _Period, 0);
| |||
| |||
if(currentBarTime == lastBarTime)
| |||
return;
| |||
| |||
lastBarTime = currentBarTime;
| |||
| |||
// ---- One trade only ----
| |||
if(PositionSelect(_Symbol))
| |||
return;
| |||
| |||
// ---- ENTRY CONDITIONS ----
| |||
if(
| |||
VolumeDeltaGreen() &&
| |||
MACDLightRed()
| |||
)
| |||
{
| |||
trade.Buy(LotSize, _Symbol);
| |||
}
| |||
}
|