Similar Threads
I will code your pivot EAs for no charge 24 replies
I will code your scalping EAs for no charge 163 replies
Oanda MT4 - Indicators and EAs not showing 2 replies
EAs and indicators relating to moutaki... 22 replies
InterbankFX has loaded its MT4 platform with custom EAs, indicators and scripts 1 reply
- Post #59,561
- Quote
- Mar 23, 2023 4:50am Mar 23, 2023 4:50am
- Joined Nov 2009 | Status: Member | 783 Posts
- Post #59,562
- Quote
- Mar 23, 2023 5:47am Mar 23, 2023 5:47am
- Joined Oct 2014 | Status: Cooking | 440 Posts
Disliked{quote} Here you go! Now it won't signal for sells unless RSI level is greater than the over bought level (and vice versa for sells) {file} {file}Ignored
- Post #59,563
- Quote
- Mar 23, 2023 6:03am Mar 23, 2023 6:03am
Dislikedsharing this source code with anyone who wishes to trade in this manner have fun {file} {image}Ignored
[
//+------------------------------------------------------------------+
//| HERCULES.mq5 |
//| Copyright 2023, Sailas Temwa |
//| https://www.HERAHERAHERA.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Sailas Temwa"
#property link "https://www.HERAHERAHERA.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| INCLUDES AND DEFINES |
//+------------------------------------------------------------------+
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Indicators\Trend\ADX.mqh>
#include <Indicators\Oscillators\RSI.mqh>
#include <Indicators\Trend\Ichimoku.mqh>
#include <Indicators\Trend\HeikenAshi.mqh>
#include <Indicators\WaddahAttarExplosion.mqh>
#include <Indicators\DynamicGains.mqh>
#include <Indicators\KijunSen.mqh>
#define MA1_BUFFER 0
#define MA2_BUFFER 1
//+------------------------------------------------------------------+
//| EXPERT ADVISOR SETTINGS |
//+------------------------------------------------------------------+
// Input parameters
input double Lots = 0.1;
input double StopLoss = 50;
input double TakeProfit = 100;
input double TrailingStop = 30;
//+------------------------------------------------------------------+
//| GLOBAL VARIABLES AND INDICATOR HANDLES |
//+------------------------------------------------------------------+
// Moving Average
double ma_buffer_1[];
double ma_buffer_2[];
CIndicatorMA ma_1, ma_2;
// iADX
double adx_buffer[];
CIndicatorADX adx;
// iRSI
double rsi_buffer[];
CIndicatorRSI rsi;
// Heiken Ashi
double ha_buffer_1[], ha_buffer_2[];
CIndicatorHeikenAshi ha_1, ha_2;
// Waddah Attar Explosion
double wae_buffer[];
CIndicatorWaddahAttarExplosion wae;
// Dynamic Gains
double dg_buffer[];
CIndicatorDynamicGains dg;
// Kijun Sen
double ks_buffer[];
CIndicatorKijunSen ks;
// Ichimoku Cloud
double ic_tenkan_buffer[], ic_kijun_buffer[], ic_senkou_span_a_buffer[], ic_senkou_span_b_buffer[], ic_chikou_span_buffer[];
CIndicatorIchimoku ic;
//+------------------------------------------------------------------+
//| EXPERT ADVISOR INITIALIZATION |
//+------------------------------------------------------------------+
int OnInit()
{
//--- initialize indicator buffers
ArrayResize(ma_buffer_1, 0);
ArrayResize(ma_buffer_2, 0);
ArrayResize(adx_buffer, 0);
ArrayResize(rsi_buffer, 0);
ArrayResize(macd_buffer, 0);
ArrayResize(signal_buffer, 0);
ArrayResize(hist_buffer, 0);
//--- create the indicators
if(!iMA(_Symbol, _Period, ma_period_1, 0, MODE_EMA, PRICE_CLOSE, ma_buffer_1))
return(ERR_INDICATOR_CREATE);
if(!iMA(_Symbol, _Period, ma_period_2, 0, MODE_EMA, PRICE_CLOSE, ma_buffer_2))
return(ERR_INDICATOR_CREATE);
if(!iADX(_Symbol, _Period, adx_period, PRICE_CLOSE, adx_buffer))
return(ERR_INDICATOR_CREATE);
if(!iRSI(_Symbol, _Period, rsi_period, PRICE_CLOSE, rsi_buffer))
return(ERR_INDICATOR_CREATE);
if(!iMACD(_Symbol, _Period, macd_fast_period, macd_slow_period, macd_signal_period, PRICE_CLOSE, macd_buffer))
return(ERR_INDICATOR_CREATE);
ArraySetAsSeries(macd_buffer, true);
ArraySetAsSeries(signal_buffer, true);
ArraySetAsSeries(hist_buffer, true);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR START |
//+------------------------------------------------------------------+
void OnTick()
{
double ma_1 = iMA(_Symbol, _Period, ma_period_1, 0, MODE_EMA, PRICE_CLOSE, ma_buffer_1, 1);
double ma_2 = iMA(_Symbol, _Period, ma_period_2, 0, MODE_EMA, PRICE_CLOSE, ma_buffer_2, 1);
double adx = iADX(_Symbol, _Period, adx_period, PRICE_CLOSE, adx_buffer, 1);
double rsi = iRSI(_Symbol, _Period, rsi_period, PRICE_CLOSE, rsi_buffer, 1);
double macd = iMACD(_Symbol, _Period, macd_fast_period, macd_slow_period, macd_signal_period, PRICE_CLOSE, macd_buffer, signal_buffer, hist_buffer, 1);
if(ma_1 > ma_2 && adx > adx_threshold && rsi > rsi_upper_threshold && macd > signal)
{
//--- open a long position
double lot_size = NormalizeDouble(AccountBalance() * risk_per_trade / 100 / (StopLossDistance() * _Point), 2);
if(lot_size > 0)
OrderSend(_Symbol, OP_BUY, lot_size, Ask, slippage, Bid - StopLossDistance() * _Point, Bid + TakeProfitDistance() * _Point, "Long position", MagicNumber, 0, Green);
}
else if(ma_1 < ma_2 && adx > adx_threshold && rsi < rsi_lower_threshold && macd < -signal)
{
//--- open a short position
double lot_size = NormalizeDouble(AccountBalance() * risk_per_trade / 100 / (StopLossDistance() * _Point), 2);
if(lot_size > 0)
OrderSend(_Symbol, OP_SELL, lot_size, Bid, slippage, Ask + StopLossDistance() * _Point, Ask - TakeProfitDistance() * _Point, "Short position", MagicNumber, 0, clrRed);
if (ticket > 0) {
OrderModify(ticket, OrderOpenPrice(), Ask + StopLossDistance() * _Point, Ask - TakeProfitDistance() * _Point, 0, clrRed);
Print("Short position opened with ticket #", ticket);
}
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR DE-INITIALIZATION |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Print("Expert advisor de-initialized with reason: ", reason);
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR TICK FUNCTION |
//+------------------------------------------------------------------+
void OnTick()
{
//--- calculate indicators
CalculateMA();
CalculateADX();
CalculateRSI();
//--- check if any open positions exist
if (OrdersTotal() > 0) {
for (int i = 0; i < OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderType() == OP_BUY) {
//--- check if stop loss or take profit levels have been hit
if (Bid - OrderOpenPrice() >= TakeProfitDistance() * _Point || OrderOpenPrice() - Bid >= StopLossDistance() * _Point) {
OrderClose(OrderTicket(), OrderLots(), Bid, slippage, clrGreen);
Print("Buy position closed with ticket #", OrderTicket());
}
}
else if (OrderType() == OP_SELL) {
//--- check if stop loss or take profit levels have been hit
if (OrderOpenPrice() - Ask >= TakeProfitDistance() * _Point || Ask - OrderOpenPrice() >= StopLossDistance() * _Point) {
OrderClose(OrderTicket(), OrderLots(), Ask, slippage, clrGreen);
Print("Sell position closed with ticket #", OrderTicket());
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| CUSTOM INDICATOR FUNCTIONS |
//+------------------------------------------------------------------+
//--- calculate Moving Average with specified period and applied price
double MA(string symbol, int period, int shift, int applied_price)
{
double ma = iMA(symbol, 0, period, shift, MODE_SMA, applied_price, 0);
return ma;
}
//--- calculate Average Directional Movement Index with specified period
double ADX(string symbol, int period, int shift)
{
double adx = iADX(symbol, 0, period, shift);
return adx;
}
//--- calculate Relative Strength Index with specified period and applied price
double RSI(string symbol, int period, int shift, int applied_price)
{
double rsi = iRSI(symbol, 0, period, applied_price, shift);
return rsi;
}
//+------------------------------------------------------------------+
//| CUSTOM TRADING FUNCTIONS |
//+------------------------------------------------------------------+
//--- open a long position
void OpenLongPosition(double risk_per_trade, int slippage, int MagicNumber)
{
//--- calculate lot size based on risk per trade and stop loss distance
double lot_size = NormalizeDouble(AccountBalance() * risk_per_trade / 100 / (StopLossDistance() * _Point), 2);
//--- check if lot size is greater than zero
if(lot_size > 0)
{
//--- send buy order with calculated lot size
bool order_send = OrderSend(_Symbol, OP_BUY, lot_size, Ask, slippage, Bid - StopLossDistance() * _Point, Bid + TakeProfitDistance() * _Point, "Long position", MagicNumber, 0, Green);
//--- check if order was sent successfully
if(!order_send)
{
//--- print error message if order failed
Print("Error opening long position: ", ErrorDescription(GetLastError()));
}
}
}
//--- open a short position
void OpenShortPosition(double risk_per_trade, int slippage, int MagicNumber)
{
//--- calculate lot size based on risk per trade and stop loss distance
double lot_size = NormalizeDouble(AccountBalance() * risk_per_trade / 100 / (StopLossDistance() * _Point), 2);
//--- check if lot size is greater than zero
if(lot_size > 0)
{
//--- send sell order with calculated lot size
bool order_send = OrderSend(_Symbol, OP_SELL, lot_size, Bid, slippage, Ask + StopLossDistance() * _Point, Ask - TakeProfitDistance() * _Point, "Short position", MagicNumber, 0, Red);
//--- check if order was sent successfully
if(!order_send)
{
//--- print error message if order failed
Print("Error opening short position: ", ErrorDescription(GetLastError()));
}
}
}
//--- close all positions
void CloseAllPositions()
{
//--- get number of open positions
int positions = OrdersTotal();
//--- loop through all open positions
for(int i = positions - 1; i >= 0; i--)
{
//--- select position by index
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
//--- close position
bool order_close = OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red);
//--- check if position was closed successfully
if(!order_close)
{
//--- print error message if position failed to close
Print("Error closing position: ", ErrorDescription(Get LastError()));
}
}
}
//+------------------------------------------------------------------+
//| CUSTOM FUNCTION DEFINITIONS |
//+------------------------------------------------------------------+
//--- function to calculate moving average
double MovingAverage(int ma_period, int ma_shift, int ma_method, double ma_price[], int ma_count)
{
double ma_value = 0;
double ma_sum = 0;
//--- loop through specified period and calculate sum
for(int i = 0; i < ma_period; i++)
{
ma_sum += ma_price[ma_shift + i];
}
//--- calculate moving average based on specified method
if(ma_method == MODE_SMA)
{
ma_value = ma_sum / ma_period;
}
else if(ma_method == MODE_EMA)
{
ma_value = iMA(NULL, 0, ma_period, ma_shift, ma_method, PRICE_CLOSE, ma_count);
}
else if(ma_method == MODE_LWMA)
{
ma_value = iMA(NULL, 0, ma_period, ma_shift, ma_method, PRICE_CLOSE, ma_count);
}
else if(ma_method == MODE_SMMA)
{
ma_value = ma_sum / ma_period;
}
return ma_value;
}
//--- function to calculate average directional index
double AverageDirectionalIndex(int adx_period, int adx_count)
{
double adx_value = iADX(NULL, 0, adx_period, PRICE_CLOSE, MODE_MAIN, 0);
return adx_value;
}
//--- function to calculate relative strength index
double RelativeStrengthIndex(int rsi_period, int rsi_shift, double rsi_price[], int rsi_count)
{
double rsi_value = iRSI(NULL, 0, rsi_period, PRICE_CLOSE, rsi_shift);
return rsi_value;
}
//--- function to calculate stop loss distance
double StopLossDistance()
{
double stop_loss = iATR(NULL, 0, atr_period, 0);
return stop_loss;
}
//--- function to calculate take profit distance
double TakeProfitDistance()
{
double take_profit = iATR(NULL, 0, atr_period, 0) * tp_multiplier;
return take_profit;
}
//--- function to calculate lot size based on risk per trade
double LotSize(double risk_per_trade)
{
double lot_size = NormalizeDouble(AccountBalance() * risk_per_trade / 100 / (StopLossDistance() * _Point), 2);
return lot_size;
}
//--- function to calculate maximum number of open positions based on account balance and risk per trade
int MaxPositions(double risk_per_trade, double max_drawdown)
{
int max_positions = (int)(AccountBalance() * risk_per_trade / 100 / (StopLossDistance() * _Point * max_drawdown));
return max_positions;
}
//--- function to check if market is open
bool IsMarketOpen()
{
datetime now = TimeLocal();
int day_of_week = TimeDayOfWeek(now);
int hour = TimeHour(now);
//--- check if current time is within market hours
if(day_of_week >= 1 && day_of_week <= 5 && hour >= 8 && hour < 20)
return true;
return false;
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR INITIALIZATION |
//+------------------------------------------------------------------+
int OnInit()
{
//--- initialize indicator buffers
ArrayResize(ma_buffer_1, 0);
ArrayResize(ma_buffer_2, 0);
ArrayResize(adx_buffer, 0);
ArrayResize(rsi_buffer, 0);
//--- set up indicator chart
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, ma_buffer_1);
SetIndexLabel(0, "MA 1");
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, ma_buffer_2);
SetIndexLabel(1, "MA 2");
SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(2, adx_buffer);
SetIndexLabel(2, "ADX");
SetIndexStyle(3, DRAW_LINE);
SetIndexBuffer(3, rsi_buffer);
SetIndexLabel(3, "RSI");
//--- set up expert advisor parameters
SetParameter("MA_Period_1", 10);
SetParameter("MA_Period_2", 20);
SetParameter("ADX_Period", 14);
SetParameter("RSI_Period", 14);
SetParameter("Risk_Per_Trade", 2.0);
SetParameter("Max_Drawdown", 0.1);
SetParameter("Slippage", 3);
SetParameter("Stop_Loss_Distance", 50);
SetParameter("Take_Profit_Distance", 100);
SetParameter("Magic_Number", 123456);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR START |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check if market is open
if(!IsMarketOpen())
return;
//--- check if expert advisor is allowed to trade
if(!IsTradeAllowed())
return;
//--- check if there are any open positions
int positions = OrdersTotal();
if(positions <= 0)
{
//--- calculate lot size and maximum number of open positions
double lot_size = LotSize(GetParameter("Risk_Per_Trade"));
int max_positions = MaxPositions(GetParameter("Risk_Per_Trade"), GetParameter("Max_Drawdown"));
//--- open a long position
if(CrossedUp())
{
int buy_positions = CountPositions(OP_BUY);
if(buy_positions < max_positions)
OrderSend(_Symbol, OP_BUY, lot_size, Ask, GetParameter("Slippage"), Bid - GetParameter("Stop_Loss_Distance") * _Point, Bid + GetParameter("Take_Profit_Distance") * _Point, "Long position", GetParameter("Magic_Number"), 0, Green);
}
//--- open a short position
if(CrossedDown())
{
int sell_positions = CountPositions(OP_SELL);
if(sell_positions < max_positions)
OrderSend(_Symbol, OP_SELL, lot_size, Bid, GetParameter("Slippage"), Ask + GetParameter("Stop_Loss_Distance") * _Point, Ask - GetParameter("Take_Profit_Distance") * _Point, "Short position", GetParameter("Magic_Number"), 0, Red);
}
}
//+------------------------------------------------------------------+
//| FUNCTION TO COUNT OPEN POSITIONS BY TYPE |
//+------------------------------------------------------------------+
int CountPositions(int type)
{
int count = 0;
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderType() == type && OrderSymbol() == _Symbol && OrderMagicNumber() == GetParameter("Magic_Number") && OrderCloseTime() == 0)
count++;
}
}
return count;
}
//+------------------------------------------------------------------+
//| FUNCTION TO GET INDICATOR VALUE BY NAME |
//+------------------------------------------------------------------+
double GetIndicatorValue(string name)
{
for(int i = 0; i < IndicatorCount(); i++)
{
if(StringSubstr(IndicatorName(i), 0, StringLen(name)) == name)
{
return NormalizeDouble(iCustom(_Symbol, 0, IndicatorName(i), GetParameter(name + "_Period"), 0, 0), _Digits);
}
}
return 0;
}
//+------------------------------------------------------------------+
//| FUNCTION TO GET EXPERT ADVISOR PARAMETER VALUE BY NAME |
//+------------------------------------------------------------------+
double GetParameter(string name)
{
for(int i = 0; i < ParametersTotal(); i++)
{
if(StringSubstr(ParameterName(i), 0, StringLen(name)) == name)
{
return ParameterGet(name);
}
}
return 0;
}
//+------------------------------------------------------------------+
//| FUNCTION TO GET EXPERT ADVISOR PARAMETER VALUE BY NAME |
//+------------------------------------------------------------------+
double GetParameter(string name)
{
for(int i = 0; i < ParametersTotal(); i++)
{
if(StringSubstr(ParameterName(i), 0, StringLen(name)) == name)
{
return ParameterGet(name);
}
}
return 0.0;
}
//+------------------------------------------------------------------+
//| FUNCTION TO COUNT THE NUMBER OF OPEN POSITIONS OF A CERTAIN TYPE |
//+------------------------------------------------------------------+
int CountPositions(int type)
{
int count = 0;
for(int i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderType() == type && !OrderCloseTime())
{
count++;
}
}
return count;
}
//+------------------------------------------------------------------+
//| FUNCTION TO CLOSE ALL OPEN POSITIONS OF A CERTAIN TYPE |
//+------------------------------------------------------------------+
bool ClosePositions(int type)
{
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderType() == type && !OrderCloseTime())
{
bool order_close = OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red);
if(!order_close)
{
Print("Error closing position: ", ErrorDescription(GetLastError()));
return false;
}
}
}
return true;
}
//+------------------------------------------------------------------+
//| FUNCTION TO CLOSE ALL OPEN POSITIONS |
//+------------------------------------------------------------------+
bool CloseAllPositions()
{
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && !OrderCloseTime())
{
bool order_close = OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red);
if(!order_close)
{
Print("Error closing position: ", ErrorDescription(GetLastError()));
return false;
}
}
}
return true;
}
//+------------------------------------------------------------------+
//| ON TICK FUNCTION |
//+------------------------------------------------------------------+
void OnTick()
{
//--- calculate lot size based on risk per trade
double lot_size = LotSize(GetParameter("Risk_Per_Trade"));
//--- calculate maximum number of open positions based on account balance and risk per trade
int max_positions = MaxPositions(GetParameter("Risk_Per_Trade"), GetParameter("Max_Drawdown"));
//--- close all positions if emergency stop loss is hit
if(Ask < GetParameter("Emergency_Stop_Loss"))
{
CloseAllPositions();
Print("Emergency stop loss hit. All positions closed.");
return;
}
//--- open a long position
if(CrossedUp())
{
int buy_positions = CountPositions(OP_BUY);
if(buy_positions < max_positions)
OrderSend(_Symbol, OP_BUY, lot_size, Ask, GetParameter("Slippage"), Bid - GetParameter("Stop_Loss_Distance") * _Point, Bid + GetParameter("Take_Profit_Distance") * _Point, "Long position", GetParameter("Magic_Number"), 0, Green);
}
//--- open a short position
if(CrossedDown())
{
int sell_positions = CountPositions(OP_SELL);
if(sell_positions < max_positions)
OrderSend(_Symbol, OP_SELL, lot_size, Bid, GetParameter("Slippage"), Ask + GetParameter("Stop_Loss_Distance") * _Point, Ask - GetParameter("Take_Profit_Distance") * _Point, "Short position", GetParameter("Magic_Number"), 0, Red);
}
}
//+------------------------------------------------------------------+
//| ON INIT FUNCTION |
//+------------------------------------------------------------------+
int OnInit()
{
//--- initialize indicator buffers
ArrayResize(ma_buffer_1, 0);
ArrayResize(ma_buffer_2, 0);
ArrayResize(adx_buffer, 0);
ArrayResize(rsi_buffer, 0);
//--- set expert advisor parameters
SetParameter("MA_Period_1", 50);
SetParameter("MA_Period_2", 200);
SetParameter("ADX_Period", 14);
SetParameter("RSI_Period", 14);
SetParameter("Slippage", 3);
SetParameter("Stop_Loss_Distance", 100);
SetParameter("Take_Profit_Distance", 100);
SetParameter("Risk_Per_Trade", 2.0);
SetParameter("Max_Drawdown", 0.2);
SetParameter("Magic_Number", 123456);
//--- calculate lot size and maximum number of positions based on account balance and expert advisor parameters
double lot_size = LotSize(GetParameter("Risk_Per_Trade"));
int max_positions = MaxPositions(GetParameter("Risk_Per_Trade"), GetParameter("Max_Drawdown"));
//--- print expert advisor parameters and calculated values to log file
Print("MA_Period_1: ", GetParameter("MA_Period_1"));
Print("MA_Period_2: ", GetParameter("MA_Period_2"));
Print("ADX_Period: ", GetParameter("ADX_Period"));
Print("RSI_Period: ", GetParameter("RSI_Period"));
Print("Slippage: ", GetParameter("Slippage"));
Print("Stop_Loss_Distance: ", GetParameter("Stop_Loss_Distance"));
Print("Take_Profit_Distance: ", GetParameter("Take_Profit_Distance"));
Print("Risk_Per_Trade: ", GetParameter("Risk_Per_Trade"));
Print("Max_Drawdown: ", GetParameter("Max_Drawdown"));
Print("Magic_Number: ", GetParameter("Magic_Number"));
Print("Lot Size: ", lot_size);
Print("Max Positions: ", max_positions);
//--- initialize cross indicator
int cross_handle = iCustom(NULL, 0, "CrossOver", GetParameter("MA_Period_1"), GetParameter("MA_Period_2"), GetParameter("ADX_Period"), GetParameter("RSI_Period"));
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR TICK FUNCTION |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check if the cross indicator has been initialized
if(cross_handle == INVALID_HANDLE)
return;
//--- get the current cross value
double current_cross = iCustom(NULL, 0, "CrossOver", GetParameter("MA_Period_1"), GetParameter("MA_Period_2"), GetParameter("ADX_Period"), GetParameter("RSI_Period"), 0);
//--- open a long position
if(CrossedUp())
{
int buy_positions = CountPositions(OP_BUY);
if(buy_positions < max_positions)
OrderSend(_Symbol, OP_BUY, lot_size, Ask, GetParameter("Slippage"), Bid - GetParameter("Stop_Loss_Distance") * _Point, Bid + GetParameter("Take_Profit_Distance") * _Point, "Long position", GetParameter("Magic_Number"), 0, Green);
}
//--- open a short position
if(CrossedDown())
{
int sell_positions = CountPositions(OP_SELL);
if(sell_positions < max_positions)
OrderSend(_Symbol, OP_SELL, lot_size, Bid, GetParameter("Slippage"), Ask + GetParameter("Stop_Loss_Distance") * _Point, Ask - GetParameter("Take_Profit_Distance") * _Point, "Short position", GetParameter("Magic_Number"), 0, Red);
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR DEINITIALIZATION |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- close all open positions
ClosePositions(OP_BUY);
ClosePositions(OP_SELL);
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR TICK FUNCTION |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for new bar
if(Crossed())
{
//--- calculate lot size
double lot_size = LotSize(GetParameter("Risk_Per_Trade"));
//--- calculate maximum number of open positions
int max_positions = MaxPositions(GetParameter("Risk_Per_Trade"), GetParameter("Max_Drawdown"));
//--- open a long position
if(CrossedUp())
{
int buy_positions = CountPositions(OP_BUY);
if(buy_positions < max_positions)
OrderSend(_Symbol, OP_BUY, lot_size, Ask, GetParameter("Slippage"), Bid - GetParameter("Stop_Loss_Distance") * _Point, Bid + GetParameter("Take_Profit_Distance") * _Point, "Long position", GetParameter("Magic_Number"), 0, Green);
}
//--- open a short position
if(CrossedDown())
{
int sell_positions = CountPositions(OP_SELL);
if(sell_positions < max_positions)
OrderSend(_Symbol, OP_SELL, lot_size, Bid, GetParameter("Slippage"), Ask + GetParameter("Stop_Loss_Distance") * _Point, Ask - GetParameter("Take_Profit_Distance") * _Point, "Short position", GetParameter("Magic_Number"), 0, Red);
}
}
}
//+------------------------------------------------------------------+
//| FUNCTION TO CHECK FOR CROSSING OF INDICATORS |
//+------------------------------------------------------------------+
bool CrossedUp()
{
//--- check if indicator buffers have been initialized
if(ma_buffer_1 == NULL || ma_buffer_2 == NULL || adx_buffer == NULL || rsi_buffer == NULL)
return false;
//--- check if MA1 has crossed above MA2 and ADX is above threshold
if(ma_buffer_1[1] < ma_buffer_2[1] && ma_buffer_1[0] > ma_buffer_2[0] && adx_buffer[0] > GetParameter("ADX_Threshold"))
{
//--- check if RSI is above threshold
if(rsi_buffer[0] > GetParameter("RSI_Threshold"))
return true;
}
return false;
}
bool CrossedDown()
{
//--- check if indicator buffers have been initialized
if(ma_buffer_1 == NULL || ma_buffer_2 == NULL || adx_buffer == NULL || rsi_buffer == NULL)
return false;
//--- check if MA1 has crossed below MA2 and ADX is above threshold
if(ma_buffer_1[1] > ma_buffer_2[1] && ma_buffer_1[0] < ma_buffer_2[0] && adx_buffer[0] > GetParameter("ADX_Threshold"))
{
//--- check if RSI is below threshold
if(rsi_buffer[0] < GetParameter("RSI_Threshold"))
return true;
}
return false;
}
//+------------------------------------------------------------------+
//| FUNCTION TO COUNT OPEN POSITIONS OF A CERTAIN TYPE |
//+------------------------------------------------------------------+
int CountPositions(int type)
{
int positions = 0;
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderType() == type && !OrderCloseTime())
positions++;
}
return positions;
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR START FUNCTION |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for crossing of indicators
if(CrossedUp())
{
int buy_positions = CountPositions(OP_BUY);
if(buy_positions < max_positions)
OrderSend(_Symbol, OP_BUY, lot_size, Ask, GetParameter("Slippage"), Bid - GetParameter("Stop_Loss_Distance") * _Point, Bid + GetParameter("Take_Profit_Distance") * _Point, "Long position", GetParameter("Magic_Number"), 0, Green);
}
if(CrossedDown())
{
int sell_positions = CountPositions(OP_SELL);
if(sell_positions < max_positions)
OrderSend(_Symbol, OP_SELL, lot_size, Bid, GetParameter("Slippage"), Ask + GetParameter("Stop_Loss_Distance") * _Point, Ask - GetParameter("Take_Profit_Distance") * _Point, "Short position", GetParameter("Magic_Number"), 0, Red);
}
}
//+------------------------------------------------------------------+
//| EXPERT ADVISOR DEINITIALIZATION |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- close all open positions
ClosePositions(OP_BUY);
ClosePositions(OP_SELL);
}
//+------------------------------------------------------------------+
]
Posting free if anybody wants to use it as well. Can you help me make this into the full EA, but try to edit because i think i haven’t input my strategy well.
The basis was gotten from an inspiration from here:
Timeframe for trade: m15
+ Heiken_AshiH_sw_mtf 1 : TF 30m
+ Heiken_AshiH_sw_mtf 2 : TF H1
+ waddah-attar-explosion-mtf 1 : TF m15
+ waddah-attar-explosion-mtf 2 : TF h1
- Rule Sell :
+DYNAMIC GAINS 1 orange arrow turn on and the price closed of this candle under Kijun-sen+ line
+Heiken bar is red
+Heiken_AshiH_sw_mtf m30 h1 is red
+waddah-attar-explosion-mtf 2 : h1 and m15 is red
-Stoploss above arrow Dynamic Gains 1
-Take profit when turn on DYNAMIC GAINS (no need to price closed)
- Rule Buy
+DYNAMIC GAINS 1 blue arrow turn on and the price closed of this candle above Kijun-sen+ line
+Heiken bar is blue
+Heiken_AshiH_sw_mtf m30 h1 is blue
+waddah-attar-explosion-mtf 2 : h1 and m15 is green
-Stoploss under arrow Dynamic Gains 1
-Take profit when turn on DYNAMIC GAINS (non need price closed)
The strategy uses multiple timeframes, which include Heiken_AshiH_sw_mtf 1 and 2 on 30m and H1 timeframes respectively, and Waddah-Attar-Explosion-mtf 1 and 2 on m15 and H1 timeframes respectively. These timeframes allow traders to analyze the market trends over a specified period and identify potential entry and exit points for trades.
For the Sell Rule, there are a few conditions that must be met before making a trade. Firstly, the Dynamic Gains 1 orange arrow must turn on, and the price of the candle must close below the Kijun-sen+ line. Additionally, the Heiken bar must be red, and the Heiken_AshiH_sw_mtf on m30 and H1 timeframes must also be red. Finally, the Waddah-Attar-Explosion-mtf 2 on H1 and m15 timeframes must also be red. The stop loss is placed above the arrow Dynamic Gains 1, while the take profit is taken when the Dynamic Gains turn on, without the need for the price to close.
For the Buy Rule, the Dynamic Gains 1 blue arrow must turn on, and the price of the candle must close above the Kijun-sen+ line. The Heiken bar must be blue, and the Heiken_AshiH_sw_mtf on m30 and H1 timeframes must also be blue. Finally, the Waddah-Attar-Explosion-mtf 2 on H1 and m15 timeframes must be green. The stop loss is placed below the arrow Dynamic Gains 1, while the take profit is taken when the Dynamic Gains turn on, without the need for the price to close.
Here is another code I wanna make into an EA try to check it out
:
//+------------------------------------------------------------------+
//| HERCULES.mq5 |
//| Copyright 2023, |
//| https://www.HERAHERAHERA.com|
//+------------------------------------------------------------------+
#property copyright "Copyright 2023,"
#property link "https://www.HERAHERAHERA.com"
#property version "1.00"
#property strict
// DECLARATIONS
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
#define MA1_BUFFER 0
#define MA2_BUFFER 1
// Moving Average
double ma_handle;
// Buffers for moving averages
double ma_buffer_1[];
double ma_buffer_2[];
double iADX(
string symbol, // symbol
ENUM_TIMEFRAMES period, // period
int period_adx // ADX period
int applied_price // applied price
);
#property indicator_buffers 6
#property indicator_plots 1
#define IC_TENKAN_BUFFER 0
#define IC_KIJUN_BUFFER 1
#define IC_SENKOUSPANA_BUFFER 2
#define IC_SENKOUSPANB_BUFFER 3
#define IC_CHIKOUSPAN_BUFFER 4
#define IC_CLOUD_BUFFER 5
// Ichimoku Cloud
double ichimoku_handle;
// Buffers for ichimoku cloud
double ic_tenkan_buffer[];
double ic_kijun_buffer[];
double ic_senkou_span_a_buffer[];
double ic_senkou_span_b_buffer[];
double ic_chikou_span_buffer[];
double ic_cloud_buffer[];
#property indicator_buffers 2
#property indicator_plots 1
#define BULLS_POWER_BUFFER 0
#define BEARS_POWER_BUFFER 1
// Bulls Power and Bears Power
double bulls_power_handle;
double bears_power_handle;
// Buffers for Bulls Power
double bulls_buffer_1[];
double bulls_buffer_2[];
// Buffers for Bears Power
double bears_buffer_1[];
double bears_buffer_2[];
#property indicator_buffers 2
#property indicator_plots 1
#define RSI_BUFFER 0
// Relative Strength Index (RSI)
double rsi_handle;
// Buffers for RSI
double rsi_buffer_1[];
double rsi_buffer_2[];
// END OF DECLARATIONS
// input parameters
input double Lots = 0.1;
input double StopLoss = 50;
input double TakeProfit = 100;
input double TrailingStop = 30;
// indicator handles
int ichimoku_mtf1_handle = INVALID_HANDLE;
int ichimoku_mtf2_handle = INVALID_HANDLE;
int adx_mtf1_handle = INVALID_HANDLE;
int adx_mtf2_handle = INVALID_HANDLE;
// indicator buffers
double ichimoku_mtf1[];
double ichimoku_mtf2[];
double adx_mtf1[];
double adx_mtf2[];
double rsi_mtf1[];
double rsi_mtf2[];
double bulls_mtf1[];
double bulls_mtf2[];
double bears_mtf1[];
double bears_mtf2[];
//
// HERCULES DASHBOARD
//+------------------------------------------------------------------+
//| HERCULES |
//| Copyright 2023, Forex Trader |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, ACLIDES"
#property link "ACLIDES"
#property version "1.00"
#property strict
// Indicator settings
input int fast_ma_period = 12;
input int slow_ma_period = 26;
input int signal_period = 9;
input int adx_period = 14;
input int bears_mtf1_period = 12;
input int bears_mtf2_period = 24;
input int rsi_period = 14;
input double rsi_oversold = 30;
input double rsi_overbought = 70;
// Dashboard objects
int profit_label, account_balance_label, stop_loss_label, take_profit_label, risk_label, auto_trading_switch, trade_history_grid;
int trade_history_clear_button, buy_button, sell_button;
// Trade history struct
struct trade_info {
int ticket;
string type;
double volume;
double open_price;
double close_price;
double profit;
string comment;
};
trade_info trade_history[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void OnTick()
{
// Calculate indicators
double fast_ma = iMA(_Symbol, PERIOD_H1, fast_ma_period, 0, MODE_EMA, PRICE_CLOSE, 0);
double slow_ma = iMA(_Symbol, PERIOD_H1, slow_ma_period, 0, MODE_EMA, PRICE_CLOSE, 0);
double signal = iMA(_Symbol, PERIOD_H1, signal_period, 0, MODE_EMA, PRICE_CLOSE, 0);
double adx_value = iADX(_Symbol, PERIOD_H1, adx_period, PRICE_CLOSE, MODE_MAIN, 0);
double bears_mtf1_value = iBearsPower(_Symbol, PERIOD_H1, bears_mtf1_period, 0);
double bears_mtf2_value = iBearsPower(_Symbol, PERIOD_H1, bears_mtf2_period, 0);
double rsi_value = iRSI(_Symbol, PERIOD_H1, rsi_period, PRICE_CLOSE, 0);
// Check if Bears Power MTF indicators have been calculated
if (bears_mtf1_value == 0 || bears_mtf2_value == 0) {
Print("Bears Power MTF indicators could not be calculated");
return;
}
// Calculate dashboard values
double account_balance = AccountBalance();
double profit = 0;
for (int i = 0; i < ArraySize(trade_history); i++) {
if (trade_history[i].ticket == 0) continue; // skip empty rows
profit += trade_history[i].profit;
}
// Update dashboard labels
ObjectSetText(buy_sell_switch_label, "Buy/Sell Switch: " + buy_sell_switch_value, 10, "Arial", Lime);
ObjectSetText(bulls_power_mtf1_label, "Bulls Power MTF1: " + DoubleToString(bulls_mtf1_value, 2), 10, "Arial", Lime);
ObjectSetText(bulls_power_mtf2_label, "Bulls Power MTF2: " + DoubleToString(bulls_mtf2_value, 2), 10, "Arial", Lime);
ObjectSetText(bears_power_mtf1_label, "Bears Power MTF1: " + DoubleToString(bears_mtf1_value, 2), 10, "Arial", Lime);
ObjectSetText(bears_power_mtf2_label, "Bears Power MTF2: " + DoubleToString(bears_mtf2_value, 2), 10, "Arial", Lime);
ObjectSetText(stop_loss_label, "Stop Loss: " + DoubleToString(stop_loss_value, 5), 10, "Arial", Lime);
ObjectSetText(account_balance_label, "Account Balance: " + DoubleToString(AccountBalance(), 2), 10, "Arial", Lime);
// Update trade history grid
int row = 0;
for (int i = 0; i < ArraySize(trade_history); i++) {
if (trade_history[i].ticket == 0) continue; // skip empty rows
row++;
ObjectSetText(trade_history_grid_tickets[row], IntegerToString(trade_history[i].ticket), 10, "Arial", Lime);
ObjectSetText(trade_history_grid_types[row], trade_history[i].type, 10, "Arial", Lime);
ObjectSetText(trade_history_grid_volumes[row], DoubleToString(trade_history[i].volume, 2), 10, "Arial", Lime);
ObjectSetText(trade_history_grid_open_prices[row], DoubleToString(trade_history[i].open_price, 5), 10, "Arial", Lime);
ObjectSetText(trade_history_grid_close_prices[row], DoubleToString(trade_history[i].close_price, 5), 10, "Arial", Lime);
ObjectSetText(trade_history_grid_profits[row], DoubleToString(trade_history[i].profit, 2), 10, "Arial", Lime);
}
// Check for new trade signals and execute trades
CheckForNewSignals();
// Check for open trades and manage them
ManageTrades();
open_trade_count = OrdersTotal();
for (int i = 0; i < open_trade_count; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
int order_type = OrderType();
double order_lot_size = OrderLots();
double order_open_price = OrderOpenPrice();
double order_stop_loss = OrderStopLoss();
double order_take_profit = OrderTakeProfit();
double order_profit = OrderProfit();
// Update trade labels with new information
if (order_type == OP_BUY) {
ObjectSetText(buy_order_label_lot_size, DoubleToString(order_lot_size, 2), 10, "Arial", Lime);
ObjectSetText(buy_order_label_open_price, DoubleToString(order_open_price, 5), 10, "Arial", Lime);
ObjectSetText(buy_order_label_stop_loss, DoubleToString(order_stop_loss, 5), 10, "Arial", Lime);
ObjectSetText(buy_order_label_take_profit, DoubleToString(order_take_profit, 5), 10, "Arial", Lime);
ObjectSetText(buy_order_label_profit, DoubleToString(order_profit, 2), 10, "Arial", Lime);
} else if (order_type == OP_SELL) {
ObjectSetText(sell_order_label_lot_size, DoubleToString(order_lot_size, 2), 10, "Arial", Red);
ObjectSetText(sell_order_label_open_price, DoubleToString(order_open_price, 5), 10, "Arial", Red);
ObjectSetText(sell_order_label_stop_loss, DoubleToString(order_stop_loss, 5), 10, "Arial", Red);
ObjectSetText(sell_order_label_take_profit, DoubleToString(order_take_profit, 5), 10, "Arial", Red);
ObjectSetText(sell_order_label_profit, DoubleToString(order_profit, 2), 10, "Arial", Red);
}
// Check for stop loss or take profit hits
if (order_type == OP_BUY) {
if (Bid <= order_stop_loss) {
OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red);
trade_history[trade_history_row].ticket = OrderTicket();
trade_history[trade_history_row].type = "Sell";
trade_history[trade_history_row].volume = OrderLots();
trade_history[trade_history_row].open_price = order_open_price;
trade_history[trade_history_row].close_price = Bid;
trade_history[trade_history_row].profit = (Bid - order_open_price) * order_lot_size;
trade_history_row++;
} else if (Bid >= order_take_profit) {
OrderClose(OrderTicket(), OrderLots(), Bid, 3, Lime);
trade_history[trade_history_row].ticket = OrderTicket();
trade_history[trade_history_row].type = "Sell";
trade_history[trade_history_row].volume = OrderLots();
trade_history[trade_history_row].open_price = order_open_price;
trade_history[trade_history_row].close_price = Bid;
trade_history[trade_history_row].profit = (Bid - order_open_price) * order_lot_size;
trade_history_row++;
}
} else if (order_type == OP_SELL) {
if (Ask >= order_stop_loss) {
OrderClose(OrderTicket(), OrderLots(), Ask, 3, Lime);
trade_history[trade_history_row].ticket = OrderTicket();
trade_history[trade_history_row].type = "Buy";
trade_history[trade_history_row].volume = OrderLots();
trade_history[trade_history_row].open_price = order_open_price;
trade_history[trade_history_row].close_price = Ask;
trade_history[trade_history_row].profit = (trade_history[trade_history_row].close_price - trade_history[trade_history_row].open_price) * trade_history[trade_history_row].volume;
trade_history_row++;
// Clear expired trade history
if (trade_history_row >= MAX_TRADE_HISTORY_ROWS) {
for (int i = 0; i < MAX_TRADE_HISTORY_ROWS; i++) {
trade_history[i].ticket = 0;
trade_history[i].type = "";
trade_history[i].volume = 0;
trade_history[i].open_price = 0;
trade_history[i].close_price = 0;
trade_history[i].profit = 0;
}
trade_history_row = 0;
}
// Update dashboard labels
ObjectSetText(current_trade_label, "Current Trade: None", 10, "Arial", White);
ObjectSetText(profit_loss_label, "Profit/Loss: " + DoubleToString(profit_loss, 2), 10, "Arial", White);
ObjectSetText(account_balance_label, "Account Balance: " + DoubleToString(AccountBalance(), 2), 10, "Arial", White);
ObjectSetText(lot_size_label, "Lot Size: " + DoubleToString(lot_size, 2), 10, "Arial", White);
// Update trade history grid
for (int i = 0; i < ArraySize(trade_history); i++) {
if (trade_history[i].ticket == 0) continue; // skip empty rows
ObjectSetText(trade_history_grid_rows[i][0], IntegerToString(trade_history[i].ticket), 10, "Arial", White);
ObjectSetText(trade_history_grid_rows[i][1], trade_history[i].type, 10, "Arial", White);
ObjectSetText(trade_history_grid_rows[i][2], DoubleToString(trade_history[i].volume, 2), 10, "Arial", White);
ObjectSetText(trade_history_grid_rows[i][3], DoubleToString(trade_history[i].open_price, Digits), 10, "Arial", White);
ObjectSetText(trade_history_grid_rows[i][4], DoubleToString(trade_history[i].close_price, Digits), 10, "Arial", White);
ObjectSetText(trade_history_grid_rows[i][5], DoubleToString(trade_history[i].profit, 2), 10, "Arial", (trade_history[i].profit >= 0) ? Lime : Red);
}
// Check for new trade signals and execute trades
CheckForNewSignals();
// Check for open trades and manage the stop loss and take profit levels
ManageOpenTrades();
// Check for open trades and manage the stop loss and take profit levels
ManageOpenTrades();
// Update dashboard trade history
UpdateTradeHistory();
// Check for closed trades and update trade history
CheckForClosedTrades();
}
//+------------------------------------------------------------------+
// Check for new trade signals
void CheckForNewSignals()
{
// Check for buy signal
if (buy_signal && !buy_trade_opened && MarketInfo(Symbol(), MODE_BID) > 0)
{
double lot_size = CalculateLotSize();
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
ticket = OrderSend(Symbol(), OP_BUY, lot_size, MarketInfo(Symbol(), MODE_BID), 3, stop_loss, take_profit, "Buy", MAGIC_NUMBER, 0, Green);
if (ticket > 0) {
buy_trade_opened = true;
buy_signal = false;
trade_history_row++;
trade_history[trade_history_row].ticket = ticket;
trade_history[trade_history_row].type = "Buy";
trade_history[trade_history_row].volume = lot_size;
trade_history[trade_history_row].open_price = MarketInfo(Symbol(), MODE_BID);
}
else {
Print("Error opening buy trade: ", GetLastError());
}
}
// Check for sell signal
if (sell_signal && !sell_trade_opened && MarketInfo(Symbol(), MODE_ASK) > 0)
{
double lot_size = CalculateLotSize();
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
ticket = OrderSend(Symbol(), OP_SELL, lot_size, MarketInfo(Symbol(), MODE_ASK), 3, stop_loss, take_profit, "Sell", MAGIC_NUMBER, 0, Red);
if (ticket > 0) {
sell_trade_opened = true;
sell_signal = false;
trade_history_row++;
trade_history[trade_history_row].ticket = ticket;
trade_history[trade_history_row].type = "Sell";
trade_history[trade_history_row].volume = lot_size;
trade_history[trade_history_row].open_price = MarketInfo(Symbol(), MODE_ASK);
}
else {
Print("Error opening sell trade: ", GetLastError());
}
}
}
//+------------------------------------------------------------------+
// Manage open trades
void ManageOpenTrades()
{
for (int i = 0; i < ArraySize(trade_history); i++) {
if (trade_history[i].ticket == 0) continue; // skip empty rows
double current_price;
if (trade_history[i].type == "Buy") {
current_price = MarketInfo(Symbol(), MODE_ASK);
}
else {
current_price = MarketInfo(Symbol(), MODE_BID);
}
// Update stop loss and take profit levels
if (trade_history[i].stop_loss == 0 || trade_history[i].take_profit == 0) {
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
bool result = OrderModify(trade_history[i].ticket, 0, stop_loss, take_profit, 0, Green);
if (result) {
trade_history[i].stop_loss = stop_loss;
trade_history[i].take_profit = take_profit;
}
else {
Print("Error modifying order: ", GetLastError());
}
}
// Update dashboard stop loss and take profit labels
if (trade_history[i].type == "Buy") {
ObjectSetText(buy_stop_loss_label, "Stop Loss: " + DoubleToString(trade_history[i].stop_loss, _Digits), 10, "Arial", Lime);
ObjectSetText(buy_take_profit_label, "Take Profit: " + DoubleToString(trade_history[i].take_profit, _Digits), 10, "Arial", Lime);
}
else {
ObjectSetText(sell_stop_loss_label, "Stop Loss: "
- DoubleToString(trade_history[i].stop_loss, _Digits), 10, "Arial", Lime);
- ObjectSetText(sell_take_profit_label, "Take Profit: " + DoubleToString(trade_history[i].take_profit, _Digits), 10, "Arial", Lime);
- }
- }
// Update account balance label
double account_balance = AccountBalance();
ObjectSetText(account_balance_label, "Account Balance: $" + DoubleToString(account_balance, 2), 10, "Arial", Lime);
// Update trade history grid
for (int i = 0; i < ArraySize(trade_history); i++) {
if (trade_history[i].ticket == 0) continue; // skip empty rows
if (trade_history[i].close_time == 0) continue; // skip open trades
ObjectSetText(trade_history_grid_cells[i][0], IntegerToString(trade_history[i].ticket), 10, "Arial", White);
ObjectSetText(trade_history_grid_cells[i][1], trade_history[i].type, 10, "Arial", White);
ObjectSetText(trade_history_grid_cells[i][2], DoubleToString(trade_history[i].volume, 2), 10, "Arial", White);
ObjectSetText(trade_history_grid_cells[i][3], DoubleToString(trade_history[i].open_price, _Digits), 10, "Arial", White);
ObjectSetText(trade_history_grid_cells[i][4], DoubleToString(trade_history[i].close_price, _Digits), 10, "Arial", White);
ObjectSetText(trade_history_grid_cells[i][5], DoubleToString(trade_history[i].profit, 2), 10, "Arial", White);
}
// Refresh chart
ChartRedraw(0);
// Sleep for 1 second
Sleep(1000);
}
}
void CheckForNewSignals() {
// Check for buy signal
if (iCustom(NULL, 0, "HERCULES", 0, 0) > 0) {
double price = Ask;
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
int ticket = OrderSend(Symbol(), OP_BUY, lot_size, price, 0, stop_loss, take_profit, "Buy", magic_number, 0, Green);
if (ticket > 0) {
// Add trade to trade history
AddTradeToHistory(ticket, "Buy", lot_size, price, stop_loss, take_profit);
}
else {
Print("Error opening buy order: ", GetLastError());
}
}
// Check for sell signal
if (iCustom(NULL, 0, "HERCULES", 0, 1) > 0) {
double price = Bid;
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
int ticket = OrderSend(Symbol(), OP_SELL, lot_size, price, 0, stop_loss, take_profit, "Sell", magic_number, 0, Red);
if (ticket > 0) {
// Add trade to trade history
AddTradeToHistory(ticket, "Sell", lot_size, price, stop_loss, take_profit);
}
else {
Print("Error opening sell order: ", GetLastError());
}
}
}
void ManageOpenTrades() {
for (int i = 0; i < ArraySize(trade_history); i++) {
if (trade_history[i].ticket == 0) continue; // skip empty rows
if (trade_history[i].close_time != 0) continue; // skip closed trades
// Manage stop loss and take profit levels
if (trade_history[i].type == "Buy") {
// Check if current price is greater than take profit level
if (Ask >= trade_history[i].take_profit) {
bool result = OrderClose(trade_history[i].ticket, trade_history[i].volume, Bid, 0, Lime);
if (result) {
trade_history[i].close_price = Bid;
trade_history[i].profit = (trade_history[i].close_price - trade_history[i].open_price) * trade_history[i].volume * 10;
ObjectSetText(buy_profit_label, "Profit: " + DoubleToString(trade_history[i].profit, 2), 10, "Arial", Lime);
}
else {
Print("Error closing order: ", GetLastError());
}
}
// Check if current price is lower than stop loss level
else if (Ask <= trade_history[i].stop_loss) {
bool result = OrderClose(trade_history[i].ticket, trade_history[i].volume, Bid, 0, Red);
if (result) {
trade_history[i].close_price = Bid;
trade_history[i].profit = (trade_history[i].close_price - trade_history[i].open_price) * trade_history[i].volume * 10;
ObjectSetText(buy_profit_label, "Profit: " + DoubleToString(trade_history[i].profit, 2), 10, "Arial", Lime);
}
else {
Print("Error closing order: ", GetLastError());
}
}
}
else {
// Check if current price is lower than take profit level
if (Bid <= trade_history[i].take_profit) {
bool result = OrderClose(trade_history[i].ticket, trade_history[i].volume, Ask, 0, Lime);
if (result) {
trade_history[i].close_price = Ask;
trade_history[i].profit = (trade_history[i].open_price - trade_history[i].close_price) * trade_history[i].volume * 10;
ObjectSetText(sell_profit_label, "Profit: " + DoubleToString(trade_history[i].profit, 2), 10, "Arial", Lime);
}
else {
Print("Error closing order: ", GetLastError());
}
}
// Check if current price is greater than stop loss level
else if (Bid >= trade_history[i].stop_loss) {
bool result = OrderClose(trade_history[i].ticket, trade_history[i].volume, Ask, 0, Red);
if (result) {
trade_history[i].close_price = Ask;
trade_history[i].profit = (trade_history[i].open_price - trade_history[i].close_price) * trade_history[i].volume * 10;
ObjectSetText(sell_profit_label, "Profit: " + DoubleToString(trade_history[i].profit, 2), 10, "Arial", Lime);
}
else {
Print("Error closing order: ", GetLastError());
}
}
}
}
}
void ManageOpenTrades() {
for (int i = 0; i < ArraySize(trade_history); i++) {
if (trade_history[i].ticket == 0) continue; // skip empty rows
// Calculate stop loss and take profit levels
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
// If stop loss or take profit levels have changed, modify the order
if (trade_history[i].stop_loss != stop_loss || trade_history[i].take_profit != take_profit) {
bool result = OrderModify(trade_history[i].ticket, 0, stop_loss, take_profit, 0, Green);
if (result) {
trade_history[i].stop_loss = stop_loss;
trade_history[i].take_profit = take_profit;
}
else {
Print("Error modifying order: ", GetLastError());
}
}
// Update dashboard stop loss and take profit labels
if (trade_history[i].type == "Buy") {
ObjectSetText(buy_stop_loss_label, "Stop Loss: " + DoubleToString(trade_history[i].stop_loss, _Digits), 10, "Arial", Lime);
ObjectSetText(buy_take_profit_label, "Take Profit: " + DoubleToString(trade_history[i].take_profit, _Digits), 10, "Arial", Lime);
}
else {
ObjectSetText(sell_stop_loss_label, "Stop Loss: " + DoubleToString(trade_history[i].stop_loss, _Digits), 10, "Arial", Lime);
ObjectSetText(sell_take_profit_label, "Take Profit: " + DoubleToString(trade_history[i].take_profit, _Digits), 10, "Arial", Lime);
}
}
}
// Update dashboard account balance label
ObjectSetText(account_balance_label, "Account Balance: " + DoubleToString(AccountBalance(), 2), 10, "Arial", Lime);
// Check for closed trades
CheckForClosedTrades();
// Update dashboard trade history grid
UpdateTradeHistoryGrid();
// Refresh dashboard
ChartRedraw(0);
// Sleep for 1 second
Sleep(1000);
}
//+------------------------------------------------------------------+
//| Function to calculate stop loss level |
//+------------------------------------------------------------------+
double CalculateStopLoss()
{
double stop_loss = 0;
if (MarketInfo(Symbol(), MODE_DIGITS) == 5) { // 5 digit broker
if (trade_history[trade_history_row].type == "Buy") {
stop_loss = Bid - (stop_loss_pips * 0.0001);
}
else {
stop_loss = Ask + (stop_loss_pips * 0.0001);
}
}
else { // 4 digit broker
if (trade_history[trade_history_row].type == "Buy") {
stop_loss = Bid - (stop_loss_pips * 0.01);
}
else {
stop_loss = Ask + (stop_loss_pips * 0.01);
}
}
return(stop_loss);
}
//+------------------------------------------------------------------+
//| Function to calculate take profit level |
//+------------------------------------------------------------------+
double CalculateTakeProfit()
{
double take_profit = 0;
if (MarketInfo(Symbol(), MODE_DIGITS) == 5) { // 5 digit broker
if (trade_history[trade_history_row].type == "Buy") {
take_profit = Bid + (take_profit_pips * 0.0001);
}
else {
take_profit = Ask - (take_profit_pips * 0.0001);
}
}
else { // 4 digit broker
if (trade_history[trade_history_row].type == "Buy") {
take_profit = Bid + (take_profit_pips * 0.01);
}
else {
take_profit = Ask - (take_profit_pips * 0.01);
}
}
return(take_profit);
}
//+------------------------------------------------------------------+
//| Function to check for new trade signals and execute trades |
//+------------------------------------------------------------------+
void CheckForNewSignals() {
double buy_signal = iCustom(NULL, 0, "HERCULES", 1, 0);
double sell_signal = iCustom(NULL, 0, "HERCULES", 2, 0);
// Check for buy signal
if (buy_signal > 0) {
double lot_size = CalculateLotSize();
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
// Open buy order
int ticket = OrderSend(NULL, OP_BUY, lot_size, Ask, 3, stop_loss, take_profit, "HERCULES Buy", MagicNumber, 0, Green);
if (ticket > 0) {
trade_history_row++;
trade_history[trade_history_row].ticket = ticket;
trade_history[trade_history_row].type = "Buy";
trade_history[trade_history_row].open_price = Ask;
trade_history[trade_history_row].lot_size = lot_size;
trade_history[trade_history_row].stop_loss = stop_loss;
trade_history[trade_history_row].take_profit = take_profit;
trade_history[trade_history_row].open_time = TimeCurrent();
trade_history[trade_history_row].comment = "HERCULES Buy";
// Update dashboard buy labels
ObjectSetText(buy_signal_label, "Buy Signal: " + DoubleToString(buy_signal, _Digits), 10, "Arial", Lime);
ObjectSetText(buy_lot_size_label, "Lot Size: " + DoubleToString(lot_size, 2), 10, "Arial", Lime);
ObjectSetText(buy_open_price_label, "Open Price: " + DoubleToString(Ask, _Digits), 10, "Arial", Lime);
ObjectSetText(buy_stop_loss_label, "Stop Loss: " + DoubleToString(stop_loss, _Digits), 10, "Arial", Lime);
ObjectSetText(buy_take_profit_label, "Take Profit: " + DoubleToString(take_profit, _Digits), 10, "Arial", Lime);
}
else {
Print("Error opening buy order: ", GetLastError());
}
}
// Check for sell signal
if (sell_signal > 0) {
double lot_size = CalculateLotSize();
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
// Open sell order
int ticket = OrderSend(NULL, OP_SELL, lot_size, Bid, 3, stop_loss, take_profit, "HERCULES Sell", MagicNumber, 0, Red);
if (ticket > 0) {
trade_history_row++;
trade_history[trade_history_row].ticket = ticket;
trade_history[trade_history_row].type = "Sell";
trade_history[trade_history_row].open_time = TimeCurrent();
trade_history[trade_history_row].open_price = Bid;
trade_history[trade_history_row].stop_loss = stop_loss;
trade_history[trade_history_row].take_profit = take_profit;
ObjectSetText(sell_ticket_label, "Ticket: " + IntegerToString(ticket), 10, "Arial", Lime);
ObjectSetText(sell_open_price_label, "Open Price: " + DoubleToString(Bid, _Digits), 10, "Arial", Lime);
ObjectSetText(sell_stop_loss_label, "Stop Loss: " + DoubleToString(stop_loss, _Digits), 10, "Arial", Lime);
ObjectSetText(sell_take_profit_label, "Take Profit: " + DoubleToString(take_profit, _Digits), 10, "Arial", Lime);
Print("Sell order placed. Ticket: ", ticket);
} else {
Print("Error placing sell order: ", GetLastError());
}
}
//+------------------------------------------------------------------+
//| Function to manage open trades and update the trade history |
//+------------------------------------------------------------------+
void ManageOpenTrades() {
for (int i = 0; i < ArraySize(trade_history); i++) {
if (trade_history[i].ticket == 0) continue; // skip empty rows
if (OrderSelect(trade_history[i].ticket, SELECT_BY_TICKET)) {
if (OrderCloseTime() != 0) {
// Order has been closed, update trade history
double profit = OrderProfit();
trade_history[i].close_time = OrderCloseTime();
trade_history[i].close_price = OrderClosePrice();
trade_history[i].profit = profit;
ObjectSetText(trade_history_grid[i+1][5], DoubleToString(profit, 2), 10, "Arial", Lime);
} else {
// Order is still open, manage stop loss and take profit levels
ManageStopLossAndTakeProfit(trade_history[i]);
}
} else {
Print("Error selecting order: ", GetLastError());
}
}
}
//+------------------------------------------------------------------+
//| Function to manage stop loss and take profit levels |
//+------------------------------------------------------------------+
void ManageStopLossAndTakeProfit(TradeHistory trade) {
// Calculate stop loss and take profit levels
double stop_loss = CalculateStopLoss();
double take_profit = CalculateTakeProfit();
// Update dashboard stop loss and take profit labels
if (trade.type == "Buy") {
ObjectSetText(buy_stop_loss_label, "Stop Loss: " + DoubleToString(trade.stop_loss, _Digits), 10, "Arial", Lime);
ObjectSetText(buy_take_profit_label, "Take Profit: " + DoubleToString(trade.take_profit, _Digits), 10, "Arial", Lime);
} else {
ObjectSetText(sell_stop_loss_label, "Stop Loss: " + DoubleToString(trade.stop_loss, _Digits), 10, "Arial", Lime);
ObjectSetText(sell_take_profit_label, "Take Profit: " + DoubleToString(trade.take_profit, _Digits), 10, "Arial", Lime);
}
// If stop loss or take profit levels have changed, modify the order
if (trade.stop_loss != stop_loss || trade.take_profit != take_profit) {
bool result = OrderModify(trade.ticket, 0, stop_loss, take_profit, 0, Green);
if (result) {
trade.stop_loss = stop_loss;
trade.take_profit = take_profit;
} else {
Print("Error modifying order: ", GetLastError());
}
}
}
//+------------------------------------------------------------------+
//| Function to calculate the lot size for a trade |
//+------------------------------------------------------------------+
double CalculateLotSize() {
double balance = AccountBalance();
double risk = balance * risk_percentage / 100;
double stop_loss_pips = (Ask - stop_loss) / _Point;
double pip_value = MarketInfo(Symbol(), MODE_TICKVALUE);
double lot_size = risk / (stop_loss_pips * pip_value);
return NormalizeDouble(lot_size, 2);
}
//+------------------------------------------------------------------+
//| Function to calculate stop loss for a trade |
//+------------------------------------------------------------------+
double CalculateStopLoss() {
if (MarketInfo(Symbol(), MODE_DIGITS) == 3 || MarketInfo(Symbol(), MODE_DIGITS) == 5) {
return NormalizeDouble(Bid + stop_loss * _Point, MarketInfo(Symbol(), MODE_DIGITS) + 1);
} else {
return NormalizeDouble(Bid + stop_loss * _Point, MarketInfo(Symbol(), MODE_DIGITS));
}
}
//+------------------------------------------------------------------+
//| Function to calculate take profit for a trade |
//+------------------------------------------------------------------+
double CalculateTakeProfit() {
if (MarketInfo(Symbol(), MODE_DIGITS) == 3 || MarketInfo(Symbol(), MODE_DIGITS) == 5) {
return NormalizeDouble(Bid - take_profit * _Point, MarketInfo(Symbol(), MODE_DIGITS) + 1);
} else {
return NormalizeDouble(Bid - take_profit * _Point, MarketInfo(Symbol(), MODE_DIGITS));
}
}
// HERCULES SEMI-AUTO AUTO BUTTON
bool isSemiAuto = true; // Set to true for semi-auto mode, false for auto mode
bool isTradingEnabled = false; // Trading is initially disabled
// Define function to enable trading
void EnableTrading() {
isTradingEnabled = true;
Print("Trading is now enabled");
}
// Define function to disable trading
void DisableTrading() {
isTradingEnabled = false;
Print("Trading is now disabled");
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Other code goes here
if (isSemiAuto) {
// Create button objects for semi-auto mode
semi_auto_button = CreateButton("Enable Trading", 20, 120, 120, 30, LimeGreen);
ObjectSetInteger(semi_auto_button, OBJPROP_ALIGN, TA_CENTER);
ObjectSetInteger(semi_auto_button, OBJPROP_FONTSIZE, 10);
}
// Other code goes here
return(INIT_SUCCEEDED);
}
+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- initialize indicator buffers
ArrayResize(ichimoku_mtf1, 0);
ArrayResize(ichimoku_mtf2, 0);
ArrayResize(adx_mtf1, 0);
ArrayResize(adx_mtf2, 0);
ArrayResize(rsi_mtf1, 0);
ArrayResize(rsi_mtf2, 0);
ArrayResize(bulls_mtf1, 0);
ArrayResize(bulls_mtf2, 0);
ArrayResize(bears_mtf1, 0);
ArrayResize(bears_mtf2, 0);
//--- calculate ichimoku MTF
ichimoku_mtf1_handle = iCustom(_Symbol, PERIOD_M15, "Ichimoku", 9, 26, 52, 1, 1, 0);
ichimoku_mtf2_handle = iCustom(_Symbol, PERIOD_M30, "Ichimoku", 9, 26, 52, 1, 1, 0);
//--- calculate ADX MTF
adx_mtf1_handle = iCustom(_Symbol, PERIOD_M15, "ADX", 14);
adx_mtf2_handle = iCustom(_Symbol, PERIOD_M30, "ADX", 14);
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check if ichimoku MTF indicators have been calculated
if (ichimoku_mtf1_handle == INVALID_HANDLE || ichimoku_mtf2_handle == INVALID_HANDLE) {
ichimoku_mtf1_handle = iCustom(NULL, PERIOD_H1, "Ichimoku", 9, 26, 52, 0, 0, 0, 1);
ichimoku_mtf2_handle = iCustom(NULL, PERIOD_H4, "Ichimoku", 9, 26, 52, 0, 0, 0, 1);
if (ichimoku_mtf1_handle == INVALID_HANDLE || ichimoku_mtf2_handle == INVALID_HANDLE) {
Print("Ichimoku MTF indicators could not be calculated");
return;
}
}
//--- calculate RSI MTF
ArraySetAsSeries(rsi_mtf1, true);
ArraySetAsSeries(rsi_mtf2, true);
double rsi_mtf1_value = iRSI(_Symbol, PERIOD_M15, 14, PRICE_CLOSE, 0);
double rsi_mtf2_value = iRSI(_Symbol, PERIOD_H1, 14, PRICE_CLOSE, 0);
if (rsi_mtf1_value == 0 || rsi_mtf2_value == 0) {
Print("RSI MTF indicators could not be calculated");
return;
}
// calculate Bears Power MTF
ArraySetAsSeries(bears_mtf1, true);
ArraySetAsSeries(bears_mtf2, true);
double bears_mtf1_value = iBearsPower(_Symbol, PERIOD_M15, bears_mtf1_parameters[0], bears_mtf1_parameters[1], bears_mtf1_parameters[2], bears_mtf1_parameters[3], bears_mtf1_parameters[4], bears_mtf1_parameters[5], bears_mtf1_parameters[6], bears_mtf1_parameters[7], bears_mtf1_parameters[8], bears_mtf1_parameters[9], bears_mtf1_parameters[10], bears_mtf1_parameters[11], bears_mtf1_parameters[12], bears_mtf1_parameters[13], bears_mtf1_parameters[14], bears_mtf1_parameters[15], bears_mtf1_parameters[16], bears_mtf1_parameters[17], bears_mtf1_parameters[18], bears_mtf1_parameters[19], bears_mtf1_parameters[20], bears_mtf1_parameters[21], bears_mtf1_parameters[22], bears_mtf1_parameters[23], bears_mtf1_parameters[24], bears_mtf1_parameters[25], bears_mtf1_parameters[26], bears_mtf1_parameters[27], bears_mtf1_parameters[28], bears_mtf1_parameters[29]);
double bears_mtf2_value = iBearsPower(_Symbol, PERIOD_H1, bears_mtf2_parameters[0], bears_mtf2_parameters[1], bears_mtf2_parameters[2], bears_mtf2_parameters[3], bears_mtf2_parameters[4], bears_mtf2_parameters[5], bears_mtf2_parameters[6], bears_mtf2_parameters[7], bears_mtf2_parameters[8], bears_mtf2_parameters[9], bears_mtf2_parameters[10], bears_mtf2_parameters[11], bears_mtf2_parameters[12], bears_mtf2_parameters[13], bears_mtf2_parameters[14], bears_mtf2_parameters[15], bears_mtf2_parameters[16], bears_mtf2_parameters[17], bears_mtf2_parameters[18], bears_mtf2_parameters[19], bears_mtf2_parameters[20], bears_mtf2_parameters[21], bears_mtf2_parameters[22], bears_mtf2_parameters[23], bears_mtf2_parameters[24], bears_mtf2_parameters[25], bears_mtf2_parameters[26], bears_mtf2_parameters[27], bears_mtf2_parameters[28], bears_mtf2_parameters[29]);
// check if ADX MTF indicators have been calculated
if (adx_mtf1_value == 0 || adx_mtf2_value == 0) {
Print("ADX MTF indicators could not be calculated");
return;
}
// check if RSI MTF indicators have been calculated
if (rsi_mtf1_value == 0 || rsi_mtf2_value == 0) {
Print("RSI MTF indicators could not be calculated");
return;
}
// check if Bulls Power MTF indicators have been calculated
if (bulls_mtf1_value == 0 || bulls_mtf2_value == 0) {
Print("Bulls Power MTF indicators could not be calculated");
return;
}
// check if Bears Power MTF indicators have been calculated
if (bears_mtf1_value == 0 || bears_mtf2_value == 0) {
Print("Bears Power MTF indicators could not be calculated");
return;
}
// calculate ADX MTF
ArraySetAsSeries(adx_mtf1, true);
ArraySetAsSeries(adx_mtf2, true);
double adx_mtf1_value = iADX(_Symbol, PERIOD_M15, 14, PRICE_CLOSE, MODE_MAIN, 0);
double adx_mtf2_value = iADX(_Symbol, PERIOD_H1, 14, PRICE_CLOSE, MODE_MAIN, 0);
// check if ADX MTF indicators have been calculated
if (adx_mtf1_value == 0 || adx_mtf2_value == 0) {
Print("ADX MTF indicators could not be calculated");
return;
}
// calculate RSI MTF
ArraySetAsSeries(rsi_mtf1, true);
ArraySetAsSeries(rsi_mtf2, true);
double rsi_mtf1_value = iRSI(_Symbol, PERIOD_M15, 14, PRICE_CLOSE, 0);
double rsi_mtf2_value = iRSI(_Symbol, PERIOD_H1, 14, PRICE_CLOSE, 0);
// check if RSI MTF indicators have been calculated
if (rsi_mtf1_value == 0 || rsi_mtf2_value == 0) {
Print("RSI MTF indicators could not be calculated");
return;
}
// determine signal based on indicators
bool ichimoku_signal = (ichimoku_mtf1[0] > ichimoku_mtf2[0]) && (ichimoku_mtf1[1] < ichimoku_mtf2[1]);
bool bulls_signal = (bulls_mtf1[0] > bulls_mtf2[0]) && (bulls_mtf1[1] < bulls_mtf2[1]);
bool bears_signal = (bears_mtf1[0] < bears_mtf2[0]) && (bears_mtf1[1] > bears_mtf2[1]);
bool adx_signal = (adx_mtf1_value > adx_mtf2_value) && (adx_mtf1_value >= 25);
bool rsi_signal = (rsi_mtf1_value > 70) && (rsi_mtf2_value < 70);
// check if all signals are true
if (ichimoku_signal && bulls_signal && bears_signal && adx_signal && rsi_signal) {
// open buy order
double price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double stop_loss = price - (stop_loss_pips * SymbolInfoDouble(_Symbol, SYMBOL_POINT));
double take_profit = price + (take_profit_pips * SymbolInfoDouble(_Symbol, SYMBOL_POINT));
bool order_placed = OrderSend(_Symbol, OP_BUY, lot_size, price, 3, stop_loss, take_profit, "HERCULES", 0, 0, Green);
if (order_placed) {
// order placed successfully
Print("Buy order placed at ", price);
trailing_stop_active = true;
trailing_stop_start_price = price;
trailing_stop_price = stop_loss + (trailing_stop_pips * SymbolInfoDouble(_Symbol, SYMBOL_POINT));
} else {
// order failed to place
Print("Failed to place order: ", ErrorDescription(GetLastError()));
}
}
- Post #59,564
- Quote
- Mar 23, 2023 6:17am Mar 23, 2023 6:17am
Dislikedsharing this source code with anyone who wishes to trade in this manner have fun {file} {image}Ignored
- Post #59,565
- Quote
- Mar 23, 2023 6:23am Mar 23, 2023 6:23am
- Joined Oct 2014 | Status: Cooking | 440 Posts
Disliked{quote} Here you go! Now it won't signal for sells unless RSI level is greater than the over bought level (and vice versa for sells) {file} {file}Ignored
Are you able to fix this? The original indicator didn't repaint at all.
Thanks man!
- Post #59,566
- Quote
- Mar 23, 2023 7:19am Mar 23, 2023 7:19am
- Joined Nov 2009 | Status: Member | 783 Posts
Source code is already available posted by PatienceFx
- Post #59,567
- Quote
- Mar 23, 2023 7:47am Mar 23, 2023 7:47am
Disliked{quote} I've been trying it out and it works but it's repainting the signals when the next candle after the signal candle is moving around. Are you able to fix this? The original indicator didn't repaint at all. Thanks man!Ignored
- Post #59,568
- Quote
- Mar 23, 2023 7:48am Mar 23, 2023 7:48am
- Post #59,569
- Quote
- Mar 23, 2023 7:51am Mar 23, 2023 7:51am
Disliked{quote} Interesting method, rading on the retracement I think But trial on EU M1, M15, H1 on the strategy tester, it does not take any trade could you check why, I ran with default settingIgnored
- Post #59,570
- Quote
- Mar 23, 2023 7:52am Mar 23, 2023 7:52am
Disliked{quote} Hi Jblanked, would it be possible if you can add signal sells and buys for RSI settings 14 and overbought/oversold levels at 95 and 14? would be great if so.. RegardsIgnored
- Post #59,571
- Quote
- Mar 23, 2023 7:53am Mar 23, 2023 7:53am
DislikedI'm having problems turning a optimized results (settings) to a set file. I know there is a simple step, I am missing. Any help appreciated. thanksIgnored
- Post #59,572
- Quote
- Mar 23, 2023 8:04am Mar 23, 2023 8:04am
- Joined Oct 2014 | Status: Cooking | 440 Posts
Disliked{quote} You’re welcome!! And Hmmmm I’m not exactly sure why it would repaint. The only thing I added was the reverse. It probably has something to do with the second part not being reversed?Ignored
Overall it is great as it doesnt produce so many signals now but I have to just be a bit careful if its not possible to stop it from repainting the arrow.
I may actually see if I can use both indicators and change the colour of yours for extreme entry
- Post #59,573
- Quote
- Mar 23, 2023 8:15am Mar 23, 2023 8:15am
- Joined Dec 2018 | Status: Member | 1,255 Posts
Disliked{quote} I don’t think you could back test this (especially not with default settings). There’s only input for price trigger and the buy stop price. I assumed the intention with this EA was for live tradingIgnored
Could we pls have the source amended so we can get confirmation THAT there is a break of structure BOS before we then enter the trade at the end of the retracement. Enter 50% sometimes still face big DD when price retrace to 76%, 88.6% or even +100% in a V,A shape move
Ah I just see the src, SL 10pips wont be DD then. What happens if price continue going down, would it trades again or not? I rather it would make check @50%, 61.8% and 75%, 75% 88.6% that new high price started forming, then confirmed by a BOS then would be perfect
- Post #59,574
- Quote
- Mar 23, 2023 8:32am Mar 23, 2023 8:32am
can anyone code fractals indicator counter.
If lower fractal is lower then previous lower fractal then number is 2, if another lower fractal is lower then previous fractal then number is 3 and so on. If lower fractal is higher then previous lower fractal then number is 1 again.
Have a look at the picture to see what I mean.
Thank you!
- Post #59,575
- Quote
- Mar 23, 2023 9:00am Mar 23, 2023 9:00am
- Post #59,576
- Quote
- Mar 23, 2023 9:00am Mar 23, 2023 9:00am
I'm trying to find a Fibonacci Retracement Tool that co-exists alongside the existing Fibonacci Retracement Tool, that is independent of it on MT4.
So that there are two Fibonacci Retracement Tools both in isolation of each other with levels that can be selected independent of the other.
The closest I have found is, "Multicolor Fibonacci Retracement Tool", on this page: https://www.forexfactory.com/thread/...1#post13330851
and attached here:
Thank you for any help or advice it is appreciated.
- Post #59,577
- Quote
- Mar 23, 2023 9:30am Mar 23, 2023 9:30am
Disliked{quote} in live trading also in M1, M15, H1 cant see no trade taken. I like to test the concept, Could we pls have the source amended so we can get confirmation THAT there is a break of structure BOS before we then enter the trade at the end of the retracement. Enter 50% sometimes still face big DD when price retrace to 76%, 88.6% or even +100% in a V,A shape move Ah I just see the src, SL 10pips wont be DD then. What happens if price continue going down, would it trades again or not? I rather it would make check @50%, 61.8% and 75%, 75% 88.6% that...Ignored
Read the original post about how it works: https://www.forexfactory.com/thread/...3#post14369413
I dont think any pair is currently at 1.1, definitely not GU or EU
- Post #59,578
- Quote
- Mar 23, 2023 9:33am Mar 23, 2023 9:33am
Disliked{quote} What do you mean by a free license? Source code is already available posted by PatienceFxIgnored
- Post #59,579
- Quote
- Mar 23, 2023 9:43am Mar 23, 2023 9:43am
- | Commercial Member | Joined Aug 2022 | 52 Posts
Disliked{quote} Screenshot what settings you're using. Default settings definitely won't work, as that was just the example given for coding it. You will need to change the price trigger and entry to fit your needs. Doesn't matter the timeframe you put it on.. Read the original post about how it works: https://www.forexfactory.com/thread/...3#post14369413 I dont think any pair is currently at 1.1, definitely not GU or EUIgnored
- Post #59,580
- Quote
- Mar 23, 2023 10:04am Mar 23, 2023 10:04am
Disliked{quote}sir please help I asked you to convert my indicator to mt5 please sirIgnored