-
void OnTick() { // Get the current price double price = SymbolInfoDouble(_Symbol, SYMBOL_BID); // Calculate EMAs double fastMA = iMA(_Symbol, PERIOD_CURRENT, fastEMA, 0, MODE_EMA, PRICE_CLOSE);
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010) -
bool isBuyPosition = PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY; bool isSellPosition = PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL;
No positions selected, bogus calls
-
Stop using ChatGPT.
Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)
- 2023.04.26
- www.mql5.com
-
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010) -
No positions selected, bogus calls
-
Stop using ChatGPT.
Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)
Help with your code can only be provided if you show all relevant code and explain the issue in detail. Otherwise, you will have to hire a freelance coder to do it for you.
Help with your code can only be provided if you show all relevant code and explain the issue in detail. Otherwise, you will have to hire a freelance coder to do it for you.
#include <Trade\Trade.mqh> input double LotSize = 0.1; // Adjustable lot size input double Multiplier = 20; // Input multiplier for positive tick movement CTrade trade; int barsCount = 0; double entryLow = 0.0; // Stores the low of the entry candle void OnTick() { // Check if the bar count has increased, indicating a new candle int currentBarsCount = Bars(_Symbol, PERIOD_CURRENT); if (barsCount != currentBarsCount) { barsCount = currentBarsCount; // Print message on every new bar count Print("New bar detected. Checking conditions for Buy Bot."); // Ensure enough bars exist to reference if (barsCount < 2) return; // Fetch the high of the previous candle and close of the current candle double prevHigh = iHigh(_Symbol, PERIOD_CURRENT, 1); double currClose = iClose(_Symbol, PERIOD_CURRENT, 0); // Buy condition: bullish candle closes above the previous candle's high if (currClose > prevHigh) { // Check if there are no open positions if (PositionsTotal() == 0) { trade.Buy(LotSize, _Symbol); entryLow = iLow(_Symbol, PERIOD_CURRENT, 1); // Store the low of the entry candle Print("Buy trade opened."); } } } // Check close condition if a buy trade is open on every new bar if (PositionSelect(_Symbol) && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { double entryPrice = PositionGetDouble(POSITION_PRICE_OPEN); // Condition 1: Close if one candlestick closes below entry candle low if (iClose(_Symbol, PERIOD_CURRENT, 1) < entryLow) { trade.PositionClose(_Symbol); Print("Buy trade closed due to close below entry candle low."); } // Condition 2: Close if price has moved 20 ticks (or Multiplier) above entry price else if (iClose(_Symbol, PERIOD_CURRENT, 0) >= entryPrice + Multiplier * Point()) { trade.PositionClose(_Symbol); Print("Buy trade closed due to positive price movement."); } } }
So this is my code above Fernando, what I mean is all is working fine, except it could take a trade signal on initialization, close that trade, skip one or 2 signals and then take the next trade on and on. Pls I would greatly appreciate your help
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I'm relatively new to coding, but can someone take a look at this code and tell my if there's a reason the trades aren't triggering in back testing? I'm getting no errors back from MetaEditor, and the defined variables are how I'd like them. Just not getting any trades lighting up in MT5 when back testing. Any clues would be greatly appreciated.
Merci!