Created
May 8, 2025 11:56
-
-
Save shingsan/24f34f61e2363468e6c24c436b0a9836 to your computer and use it in GitHub Desktop.
EA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+------------------------------------------------------------------+ | |
//| USDJPY SafePro EA - MTF + MACD + RSI + トレール対応 | | |
//+------------------------------------------------------------------+ | |
#property strict | |
extern double BaseLot = 0.01; | |
extern bool UseCompound = true; | |
extern int MaxTrades = 1; | |
extern int StopLossPips = 30; | |
extern int TakeProfitPips = 50; | |
extern int TrailStart = 20; | |
extern int TrailStep = 10; | |
double GetLot() { | |
if (!UseCompound) return BaseLot; | |
return NormalizeDouble(BaseLot * (AccountBalance() / 50000.0), 2); | |
} | |
bool IsTrendUp() { | |
return iMA(NULL, PERIOD_D1, 50, 0, MODE_SMA, PRICE_CLOSE, 0) > | |
iMA(NULL, PERIOD_D1, 200, 0, MODE_SMA, PRICE_CLOSE, 0) && | |
iMA(NULL, PERIOD_H4, 20, 0, MODE_SMA, PRICE_CLOSE, 0) > | |
iMA(NULL, PERIOD_H4, 50, 0, MODE_SMA, PRICE_CLOSE, 0); | |
} | |
bool IsTrendDown() { | |
return iMA(NULL, PERIOD_D1, 50, 0, MODE_SMA, PRICE_CLOSE, 0) < | |
iMA(NULL, PERIOD_D1, 200, 0, MODE_SMA, PRICE_CLOSE, 0) && | |
iMA(NULL, PERIOD_H4, 20, 0, MODE_SMA, PRICE_CLOSE, 0) < | |
iMA(NULL, PERIOD_H4, 50, 0, MODE_SMA, PRICE_CLOSE, 0); | |
} | |
void OnTick() { | |
if (OrdersTotal() >= MaxTrades) return; | |
double ma5 = iMA(NULL, PERIOD_M15, 5, 0, MODE_SMA, PRICE_CLOSE, 1); | |
double ma10 = iMA(NULL, PERIOD_M15, 10, 0, MODE_SMA, PRICE_CLOSE, 1); | |
double rsi = iRSI(NULL, PERIOD_M15, 14, PRICE_CLOSE, 1); | |
double macd = iMACD(NULL, PERIOD_M15, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1); | |
double signal = iMACD(NULL, PERIOD_M15, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1); | |
double lot = GetLot(); | |
if (IsTrendUp() && ma5 > ma10 && rsi < 60 && macd > signal) | |
OrderSend(Symbol(), OP_BUY, lot, Ask, 3, Ask - StopLossPips * Point, Ask + TakeProfitPips * Point, "SafeBuy", 0, 0, clrGreen); | |
if (IsTrendDown() && ma5 < ma10 && rsi > 40 && macd < signal) | |
OrderSend(Symbol(), OP_SELL, lot, Bid, 3, Bid + StopLossPips * Point, Bid - TakeProfitPips * Point, "SafeSell", 0, 0, clrOrange); | |
} | |
// トレーリングストップ(簡易) ※ポジション保持時に毎ティック調整 | |
void TrailStops() { | |
for (int i = 0; i < OrdersTotal(); i++) { | |
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol()) { | |
if (OrderType() == OP_BUY) { | |
double newStop = Bid - TrailStep * Point; | |
if (Bid - OrderOpenPrice() > TrailStart * Point && newStop > OrderStopLoss()) | |
OrderModify(OrderTicket(), OrderOpenPrice(), newStop, OrderTakeProfit(), 0, clrGreen); | |
} | |
if (OrderType() == OP_SELL) { | |
double newStop = Ask + TrailStep * Point; | |
if (OrderOpenPrice() - Ask > TrailStart * Point && newStop < OrderStopLoss()) | |
OrderModify(OrderTicket(), OrderOpenPrice(), newStop, OrderTakeProfit(), 0, clrOrange); | |
} | |
} | |
} | |
} | |
int start() { | |
OnTick(); | |
TrailStops(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment