Need Help With EA, Not Getting Visuals & I'm Finding It Hard To Make A Strategy

 

  • //+------------------------------------------------------------------+
//|                        Momentum Drive.mq4                        | //|          Generated by AldanParris- AkA: SeekerOfLight  |           //|                              2024                                            | //|                   SoL_Coders.Inc Barbados W.I                   | //+------------------------------------------------------------------+ #property strict extern double LotSize = 0.05; extern int MaxLosses = 14; extern double RiskPerTradePercent = 1.0; extern int StopLossPips = 10;  // Adjusted for scalping extern int TakeProfitPips = 20; // Adjusted for scalping extern int MagicNumber = 123456; extern int MaxTrades = 5; // Indicator parameters extern int RSI_Period = 14; extern int Momentum_Period = 14; extern int BB_Period = 20; extern double BB_Deviation = 2.0; int totalTrades = 0; int totalLosses = 0; datetime lastBarTime = 0; // Indicator values double RSI_value, Momentum_value, LowerBB_value, UpperBB_value; //+------------------------------------------------------------------+ //| Expert initialization function                                   | //+------------------------------------------------------------------+ int OnInit() {     // Initialization     Print("Momentum Drive EA initialized.");     lastBarTime = iTime(_Symbol, PERIOD_M15, 0);     return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Expert deinitialization function                                 | //+------------------------------------------------------------------+ void OnDeinit(const int reason) {     // Cleanup     Print("Momentum Drive EA deinitialized."); } //+------------------------------------------------------------------+ //| Expert tick function                                             | //+------------------------------------------------------------------+ void OnTick() {     // Check if a new bar has formed     datetime currentBarTime = iTime(_Symbol, PERIOD_M15, 0);     if (currentBarTime != lastBarTime)     {         lastBarTime = currentBarTime;         OnBarUpdate();     } } //+------------------------------------------------------------------+ //| OnBarUpdate function                                             | //+------------------------------------------------------------------+ void OnBarUpdate() {     // Calibrate the market conditions     CalibrateMarket();     // Check if max losses have been reached or max trades have been opened     if (totalLosses >= MaxLosses)     {         Print("Maximum losses reached. No more trades.");         return;     }     if (totalTrades >= MaxTrades)     {         Print("Maximum trades reached. No more trades.");         return;     }     // Get the latest indicator values     RSI_value = iRSI( _Symbol, PERIOD_M15, RSI_Period, PRICE_CLOSE, 0);     Momentum_value = iMomentum(_Symbol, PERIOD_M15, Momentum_Period, PRICE_CLOSE, 0);     LowerBB_value = iBands(_Symbol, PERIOD_M15, BB_Period, BB_Deviation, 0, PRICE_CLOSE, MODE_LOWER, 0);     UpperBB_value = iBands(_Symbol, PERIOD_M15, BB_Period, BB_Deviation, 0, PRICE_CLOSE, MODE_UPPER, 0);     Print("RSI: ", RSI_value, " Momentum: ", Momentum_value, " Lower BB: ", LowerBB_value, " Upper BB: ", UpperBB_value);     // Check if conditions are met for a trade     if (ShouldEnterTrade())     {         double stopLoss = 0, takeProfit = 0;         int ticket = -1;         double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);         double ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);         double currentLotSize = CalculatePositionSize();         if (RSI_value < 40 && Momentum_value > 100 && bid < LowerBB_value)         {             // Buy trade             stopLoss = bid - StopLossPips * Point;             takeProfit = bid + TakeProfitPips * Point;             ticket = OrderSend(Symbol(), OP_BUY, currentLotSize, ask, 3, stopLoss, takeProfit, "Momentum Drive", MagicNumber, 0, clrNONE);         }         else if (RSI_value > 60 && Momentum_value < 100 && ask > UpperBB_value)         {             // Sell trade             stopLoss = ask + StopLossPips * Point;             takeProfit = ask - TakeProfitPips * Point;             ticket = OrderSend(Symbol(), OP_SELL, currentLotSize, bid, 3, stopLoss, takeProfit, "Momentum Drive", MagicNumber, 0, clrNONE);         }         if (ticket > 0)         {             Print("Order placed successfully! Ticket: ", ticket);             totalTrades++;         }         else         {             Print("Error placing order: ", GetLastError());         }     }     // Manage open trades     ManageTrades(); } //+------------------------------------------------------------------+ //| Check if conditions are met for a trade                          | //+------------------------------------------------------------------+ bool ShouldEnterTrade() {     double bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);     double ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);     // Conditions for a Buy trade     if (RSI_value < 40 && Momentum_value > 100 && bid < LowerBB_value)     {         Print("Buy signal generated.");         return true;  // Signal to enter a Buy trade     }     // Conditions for a Sell trade     if (RSI_value > 60 && Momentum_value < 100 && ask > UpperBB_value)     {         Print("Sell signal generated.");         return true;  // Signal to enter a Sell trade     }     return false;  // No trade signal } //+------------------------------------------------------------------+ //| Manage open trades                                               | //+------------------------------------------------------------------+ void ManageTrades() {     for (int i = OrdersTotal() - 1; i >= 0; i--)     {         if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))         {             if (OrderMagicNumber() == MagicNumber)             {                 // Print details about the selected order                 Print("Managing Order: ", OrderTicket(), " Type: ", OrderType(), " Open Price: ", OrderOpenPrice(), " Stop Loss: ", OrderStopLoss(), " Take Profit: ", OrderTakeProfit());                 bool closeResult = false;                 if (OrderType() == OP_BUY)                 {                     // Check if the trade hit stop loss or take profit                     if (OrderStopLoss() > 0 && SymbolInfoDouble(Symbol(), SYMBOL_BID) <= OrderStopLoss())                     {                         totalLosses++;                         Print("Buy Stop loss hit. Total losses: ", totalLosses);                         closeResult = OrderClose(OrderTicket(), OrderLots(), SymbolInfoDouble(Symbol(), SYMBOL_BID), 3, clrRed);                     }                     else if (OrderTakeProfit() > 0 && SymbolInfoDouble(Symbol(), SYMBOL_BID) >= OrderTakeProfit())                     {                         Print("Buy Take profit hit.");                         closeResult = OrderClose(OrderTicket(), OrderLots(), SymbolInfoDouble(Symbol(), SYMBOL_BID), 3, clrGreen);                     }                 }                 else if (OrderType() == OP_SELL)                 {                     // Check if the trade hit stop loss or take profit                     if (OrderStopLoss() > 0 && SymbolInfoDouble(Symbol(), SYMBOL_ASK) >= OrderStopLoss())                     {                         totalLosses++;                         Print("Sell Stop loss hit. Total losses: ", totalLosses);                         closeResult = OrderClose(OrderTicket(), OrderLots(), SymbolInfoDouble(Symbol(), SYMBOL_ASK), 3, clrRed);                     }                     else if (OrderTakeProfit() > 0 && SymbolInfoDouble(Symbol(), SYMBOL_ASK) <= OrderTakeProfit())                     {                         Print("Sell Take profit hit.");                         closeResult = OrderClose(OrderTicket(), OrderLots(), SymbolInfoDouble(Symbol(), SYMBOL_ASK), 3, clrGreen);                     }                 }                 if (!closeResult)                 {                     Print("Failed to close order: ", OrderTicket(), " Error: ", GetLastError());                 }             }         }     } } //+------------------------------------------------------------------+ //| Calculate position size based on risk per trade                  | //+------------------------------------------------------------------+ double CalculatePositionSize() {     double accountBalance = AccountBalance();     double riskAmount = accountBalance * (RiskPerTradePercent / 100.0);     double positionSize = riskAmount / (StopLossPips * MarketInfo(Symbol(), MODE_POINT));     return MathMin(LotSize, positionSize); } //+------------------------------------------------------------------+ //| Calibrate market conditions                                      | //+------------------------------------------------------------------+ void CalibrateMarket() {     double avgTrueRange = iATR(_Symbol, PERIOD_M15, 14, 0);     double avgVolatility = 0;          for (int i = 0; i < 50; i++)     {         double high = iHigh(_Symbol, PERIOD_M15, i);         double low = iLow(_Symbol, PERIOD_M15, i);         avgVolatility += (high - low);     }     avgVolatility /= 50;     if (avgTrueRange > avgVolatility * 1.2)     {         RSI_Period = 10;         BB_Deviation = 2.5;         Print("Market is highly volatile. Adjusting RSI period to 10 and Bollinger Bands deviation to 2.5.");     }     else if (avgTrueRange < avgVolatility * 0.8)     {         RSI_Period = 20;         BB_Deviation = 1.5;         Print("Market is less volatile. Adjusting RSI period to 20 and Bollinger Bands deviation to 1.5.");     }     else     {         RSI_Period = 14;         BB_Deviation = 2.0;         Print("Market is normal. Keeping default RSI period at 14 and Bollinger Bands deviation at 2.0.");     } } //+------------------------------------------------------------------+ //| Display the spread on the chart                                  | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {     if (id == CHARTEVENT_CLICK || id == CHARTEVENT_OBJECT_CREATE || id == CHARTEVENT_OBJECT_DELETE || id == CHARTEVENT_CHART_CHANGE)     {         double spread = MarketInfo(Symbol(), MODE_SPREAD) * Point;         Comment("Spread: ", spread);     } }
Now this runs, seeing values in journal. However, nothing shows I'm learning still i find it very hard to build value strategy to get it run well & if i do it open trades on every tick. In older versions

 
If you want to learn, you should learn to code yourself. This code was not written by hand. Don't use generators like chat GPT and other generative software. We can only help you if we see that you tried yourself, shown some effort
 
Nardus Van Staden #:
If you want to learn, you should learn to code yourself. This code was not written by hand. Don't use generators like chat GPT and other generative software. We can only help you if we see that you tried yourself, shown some effort

Thanks, fam....

 
Nardus Van Staden #:
If you want to learn, you should learn to code yourself. This code was not written by hand. Don't use generators like chat GPT and other generative software. We can only help you if we see that you tried yourself, shown some effort

You got your pigs in a bag already right, @Nardus who are you? Keep it, fix it and wipe your face with it. I asked for help and you trying to make me smaller than I feel already...

 
Aldan Parris #:

You got your pigs in a bag already right, @Nardus who are you? Keep it, fix it and wipe your face with it. I asked for help and you trying to make me smaller than I feel already...

You stated that you are learning? Right? "" This was the message:

Now this runs, seeing values in journal. However, nothing shows I'm learning still i find it very hard to build value strategy to get it run well & if i do it open trades on every tick. In older versions

What are you learning exactly? Learning to work with EA generators?? Im not quite sure, but what i can tell is that you are surely not learning to write code yourself mate.

Who am i ? Well...look at my bio, and wipe your face with that. ;-)

We are not here to help people that post generated code. Surely somewhere you will need to learn to do it yourself. Don't be angry at me because i caught you out. Any coder on here will tell you that you use generators to do it, its clear that the code is not hand written. I will not tell you how we know, because you will change it and come back to waste our time again.  If you attempt to try coding yourself, we will gladly assist. We will not solve errors made by another program. Your code has many errors in it.

 
Nardus Van Staden #:

You stated that you are learning? Right? "" This was the message:

Now this runs, seeing values in journal. However, nothing shows I'm learning still i find it very hard to build value strategy to get it run well & if i do it open trades on every tick. In older versions

What are you learning exactly? Learning to work with EA generators?? Im not quite sure, but what i can tell is that you are surely not learning to write code yourself mate.

Who am i ? Well...look at my bio, and wipe your face with that. ;-)

We are not here to help people that post generated code. Surely somewhere you will need to learn to do it yourself. Don't be angry at me because i caught you out. Any coder on here will tell you that you use generators to do it, its clear that the code is not hand written. I will not tell you how we know, because you will change it and come back to waste our time again.  If you attempt to try coding yourself, we will gladly assist. We will not solve errors made by another program. Your code has many errors in it.

You done got your money in your bank account, so you surly dont have the time for me. However, thank you and many blessing to you and the green men that dead...