-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a97968
commit 4dcd09e
Showing
16 changed files
with
1,560 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
mql5 | ||
//+------------------------------------------------------------------+ | ||
//| Auto3M Lite MT5 | | ||
//| Copyright 2024, Forex Robot EASY Team | | ||
//| https://forexroboteasy.com/ | | ||
//+------------------------------------------------------------------+ | ||
#include <Trade\Trade.mqh> | ||
|
||
// Create a trade object | ||
CTrade trade; | ||
|
||
// Input parameters | ||
input double SL = 50; // Stop Loss in pips | ||
input double TP = 100; // Take Profit in pips | ||
input double TrailingStop = 30; // Trailing Stop in pips | ||
input ENUM_TIMEFRAMES Timeframe = PERIOD_M5; // Timeframe for indicators | ||
|
||
// Bollinger Bands Parameters | ||
input int BB_Period = 20; | ||
input double BB_Deviation = 2.0; | ||
|
||
// Stochastic Oscillator Parameters | ||
input int KPeriod = 5; | ||
input int DPeriod = 3; | ||
input int Slowing = 3; | ||
|
||
//+------------------------------------------------------------------+ | ||
//| Expert initialization function | | ||
//+------------------------------------------------------------------+ | ||
int OnInit() | ||
{ | ||
// Initialization of global variables, indicators, etc. | ||
Print('Auto3M Lite MT5 initialized'); | ||
return(INIT_SUCCEEDED); | ||
} | ||
|
||
//+------------------------------------------------------------------+ | ||
//| Expert deinitialization function | | ||
//+------------------------------------------------------------------+ | ||
void OnDeinit(const int reason) | ||
{ | ||
// Cleanup any resources if necessary | ||
Print('Auto3M Lite MT5 deinitialized'); | ||
} | ||
|
||
//+------------------------------------------------------------------+ | ||
//| Expert tick function | | ||
//+------------------------------------------------------------------+ | ||
void OnTick() | ||
{ | ||
ManagePositions(); | ||
ManagePendingOrders(); | ||
} | ||
|
||
//+------------------------------------------------------------------+ | ||
//| Manage Open Positions | | ||
//+------------------------------------------------------------------+ | ||
void ManagePositions() | ||
{ | ||
for(int i=PositionsTotal()-1; i>=0; i--) | ||
{ | ||
ulong ticket = PositionGetTicket(i); | ||
double positionPrice = PositionGetDouble(POSITION_PRICE_OPEN); | ||
double currentPrice = PositionGetDouble(POSITION_TYPE)==POSITION_TYPE_BUY ? SymbolInfoDouble(_Symbol, SYMBOL_BID) : SymbolInfoDouble(_Symbol, SYMBOL_ASK); | ||
double stopLevel = positionPrice + PositionGetDouble(POSITION_TYPE)==POSITION_TYPE_BUY ? -TrailingStop*Point : TrailingStop*Point; | ||
|
||
// Trailing Stop Logic | ||
if((PositionGetDouble(POSITION_TYPE) == POSITION_TYPE_BUY && currentPrice >= stopLevel) || | ||
(PositionGetDouble(POSITION_TYPE) == POSITION_TYPE_SELL && currentPrice <= stopLevel)) | ||
{ | ||
trade.PositionModify(ticket, stopLevel, PositionGetDouble(POSITION_TP)); | ||
Print('Trailing stop adjusted for position: ', ticket); | ||
} | ||
} | ||
} | ||
|
||
//+------------------------------------------------------------------+ | ||
//| Manage Pending Orders | | ||
//+------------------------------------------------------------------+ | ||
void ManagePendingOrders() | ||
{ | ||
for(int i=OrdersTotal()-1; i>=0; i--) | ||
{ | ||
if(OrderSelect(i, SELECT_BY_POS, MODE_PENDING)) | ||
{ | ||
datetime expiration = OrderGetInteger(ORDER_EXPIRATION); | ||
if(expiration != 0 && TimeCurrent() >= expiration) | ||
{ | ||
trade.OrderDelete(OrderGetTicket()); | ||
Print('Pending order deleted: ', OrderGetTicket()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
//+------------------------------------------------------------------+ | ||
//| Indicator Calculation and Trading Logic | | ||
//+------------------------------------------------------------------+ | ||
void ExecuteTrades() | ||
{ | ||
double upperBand[], lowerBand[], middleBand[]; | ||
double stochMain[], stochSignal[]; | ||
|
||
if(CalculateBBAndStoch(upperBand, middleBand, lowerBand, stochMain, stochSignal)) | ||
{ | ||
double currentAsk = SymbolInfoDouble(_Symbol, SYMBOL_ASK); | ||
double currentBid = SymbolInfoDouble(_Symbol, SYMBOL_BID); | ||
|
||
// Buy Signal | ||
if(currentBid < lowerBand[0] && stochMain[1] < 20 && stochSignal[1] < 20) | ||
{ | ||
double sl = currentBid - SL * _Point; | ||
double tp = currentBid + TP * _Point; | ||
trade.Buy(0.1, _Symbol, currentBid, sl, tp, 'Auto3M Lite Buy'); | ||
} | ||
|
||
// Sell Signal | ||
if(currentAsk > upperBand[0] && stochMain[1] > 80 && stochSignal[1] > 80) | ||
{ | ||
double sl = currentAsk + SL * _Point; | ||
double tp = currentAsk - TP * _Point; | ||
trade.Sell(0.1, _Symbol, currentAsk, sl, tp, 'Auto3M Lite Sell'); | ||
} | ||
} | ||
} | ||
|
||
//+------------------------------------------------------------------+ | ||
//| Calculate Bollinger Bands and Stochastic Oscillator | | ||
//+------------------------------------------------------------------+ | ||
bool CalculateBBAndStoch(double &upperBand[], double &middleBand[], double &lowerBand[], double &stochMain[], double &stochSignal[]) | ||
{ | ||
ArraySetAsSeries(upperBand, true); | ||
ArraySetAsSeries(middleBand, true); | ||
ArraySetAsSeries(lowerBand, true); | ||
ArraySetAsSeries(stochMain, true); | ||
ArraySetAsSeries(stochSignal, true); | ||
|
||
int bars = iBars(_Symbol, Timeframe); | ||
if(bars >= BB_Period && bars >= KPeriod + DPeriod + Slowing) | ||
{ | ||
if(iBands(_Symbol, Timeframe, BB_Period, 0, BB_Deviation, PRICE_CLOSE, upperBand, middleBand, lowerBand) != INVALID_HANDLE && | ||
iStochastic(_Symbol, Timeframe, KPeriod, DPeriod, Slowing, MODE_SMA, PRICE_CLOSE, stochMain, stochSignal) != INVALID_HANDLE) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
//+------------------------------------------------------------------+ | ||
//| Expert advisor configuration input parameters | | ||
//+------------------------------------------------------------------+ | ||
input datetime TimeToDeletePendingOrders = D'2024.01.01 00:00'; | ||
//+------------------------------------------------------------------+ | ||
//| Check for pending order deletion | | ||
//+------------------------------------------------------------------+ | ||
void CheckDeletePendingOrders() | ||
{ | ||
if(TimeToDeletePendingOrders != 0 && TimeCurrent() >= TimeToDeletePendingOrders) | ||
{ | ||
for(int i = OrdersTotal() - 1; i >= 0; i--) | ||
{ | ||
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) | ||
{ | ||
if(OrderType() == ORDER_TYPE_BUY_STOP || OrderType() == ORDER_TYPE_SELL_STOP) | ||
{ | ||
trade.OrderDelete(OrderGetTicket()); | ||
Print('Pending order deleted at specified time: ', OrderGetTicket()); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
cpp | ||
//+------------------------------------------------------------------+ | ||
//| Bongo AUDCHF| | ||
//| Copyright 2024, Forex Robot EASY Team | | ||
//| Website: https://forexroboteasy.com/ | | ||
//+------------------------------------------------------------------+ | ||
#property strict | ||
|
||
// Input parameters for users | ||
input double RiskPercentage = 2.0; // Risk percentage per trade | ||
input double TakeProfit = 50; // Take profit in pips | ||
input double StopLoss = 30; // Stop loss in pips | ||
input double TrailingStop = 20; // Trailing stop in pips | ||
input int MovingAveragePeriod = 14; // Period for moving average | ||
input int RSIPeriod = 14; // Period for RSI | ||
|
||
// Global variables | ||
double lotSize; | ||
int magicNumber = 12345; // Unique identifier for this EA's trades | ||
|
||
// Event handler for initialization | ||
int OnInit() | ||
{ | ||
// Check if EA is attached to the correct symbol | ||
if (_Symbol != 'AUDCHF') | ||
{ | ||
Alert('Bongo AUDCHF must be attached to an AUDCHF chart.'); | ||
return(INIT_FAILED); | ||
} | ||
|
||
// Perform broker and account type detection (for demonstration purposes) | ||
if (StringFind(AccountCompany(), 'IC Markets') != -1 || StringFind(AccountCompany(), 'Tickmill') != -1 || StringFind(AccountCompany(), 'Pepperstone') != -1) | ||
{ | ||
Print('Broker compatible.'); | ||
} | ||
else | ||
{ | ||
Alert('This EA might not work properly with your broker. Compatible brokers: IC Markets, Tickmill, Pepperstone.'); | ||
} | ||
|
||
// Calculate lot size based on risk percentage and account balance | ||
lotSize = CalculateLotSize(RiskPercentage); | ||
|
||
// Initialization was successful | ||
return(INIT_SUCCEEDED); | ||
} | ||
|
||
// Event handler for deinitialization | ||
void OnDeinit(const int reason) | ||
{ | ||
// Clean up resources if necessary | ||
} | ||
|
||
// Event handler for new tick | ||
void OnTick() | ||
{ | ||
// Get necessary indicators | ||
double ma = iMA(_Symbol, 0, MovingAveragePeriod, 0, MODE_SMA, PRICE_CLOSE, 0); | ||
double rsi = iRSI(_Symbol, 0, RSIPeriod, PRICE_CLOSE, 0); | ||
|
||
// Custom Market Movement Strategy logic | ||
Strategy(ma, rsi); | ||
} | ||
|
||
// Market Movement Strategy tailored for AUDCHF | ||
void Strategy(double ma, double rsi) | ||
{ | ||
// Example logic for entering trades | ||
if (OrdersTotal() == 0) | ||
{ | ||
if (rsi < 30 && Close[1] > ma && Close[0] < ma) // Example buy condition | ||
{ | ||
OpenTrade(ORDER_TYPE_BUY, lotSize, StopLoss, TakeProfit, TrailingStop); | ||
} | ||
else if (rsi > 70 && Close[1] < ma && Close[0] > ma) // Example sell condition | ||
{ | ||
OpenTrade(ORDER_TYPE_SELL, lotSize, StopLoss, TakeProfit, TrailingStop); | ||
} | ||
} | ||
} | ||
|
||
// Function to open a trade | ||
void OpenTrade(int type, double lots, double sl, double tp, double ts) | ||
{ | ||
double slPrice, tpPrice; | ||
|
||
if (type == ORDER_TYPE_BUY) | ||
{ | ||
slPrice = NormalizeDouble(Bid - sl * _Point, _Digits); | ||
tpPrice = NormalizeDouble(Bid + tp * _Point, _Digits); | ||
} | ||
else | ||
{ | ||
slPrice = NormalizeDouble(Ask + sl * _Point, _Digits); | ||
tpPrice = NormalizeDouble(Ask - tp * _Point, _Digits); | ||
} | ||
|
||
int ticket = OrderSend(_Symbol, type, lots, NormalizeDouble(type == ORDER_TYPE_BUY ? Ask : Bid, _Digits), 0, slPrice, tpPrice, 'Bongo AUDCHF', magicNumber, 0, clrGreen); | ||
|
||
if (ticket < 0) | ||
{ | ||
Print('OrderSend failed with error #', GetLastError()); | ||
} | ||
else if (ts > 0) | ||
{ | ||
OrderModify(ticket, OrderOpenPrice(), OrderStopLoss(), OrderTakeProfit(), 0, clrGreen); | ||
} | ||
} | ||
|
||
// Function to calculate lot size based on risk percentage | ||
double CalculateLotSize(double riskPercent) | ||
{ | ||
double lotSize = 0.1; // Default lot size | ||
|
||
// Custom lot size calculation logic | ||
// Placeholder logic: can be enhanced for actual risk management | ||
double risk = AccountBalance() * (riskPercent / 100); | ||
double sl = StopLoss * _Point; | ||
lotSize = risk / sl; | ||
|
||
return (MathFloor(lotSize / MarketInfo(_Symbol, MODE_LOTSIZE)) * MarketInfo(_Symbol, MODE_LOTSIZE)); | ||
} |
Oops, something went wrong.