LuckyJ:
Send your full code please.Hi, I tried compiling this code for an EA but kept getting an error. Please help.
here is the error i get.
I suppose you have declared « CTrade trade », and not « CTrade Trade ».
Here, the error tells you you have not declared the CTrade instance called « Trade ».
//+------------------------------------------------------------------+ //| pinbar.mq5 | //| Copyright 2023, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #include <Trade\Trade.mqh> CTrade Trade; // Declare a CTrade object input double stopLossPct = 1.0; input double takeProfitPct = 2.0; input int magicNumber = 12345; // Magic number to identify trades //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { double bodySizePct = MathAbs(iOpen(Symbol(), Period(), 0) - iClose(Symbol(), Period(), 0)) / (iHigh(Symbol(), Period(), 0) - iLow(Symbol(), Period(), 0)) * 100; double candleMiddle = (iHigh(Symbol(), Period(), 0) - iLow(Symbol(), Period(), 0)) / 2; bool aboveMiddle = iOpen(Symbol(), Period(), 0) > candleMiddle && iClose(Symbol(), Period(), 0) > candleMiddle; bool belowMiddle = iOpen(Symbol(), Period(), 0) < candleMiddle && iClose(Symbol(), Period(), 0) < candleMiddle; bool bullishPinbarCondition = bodySizePct < 50 && belowMiddle; bool bearishPinbarCondition = bodySizePct < 50 && aboveMiddle; double bullishPinbarHigh = bullishPinbarCondition ? iHigh(Symbol(), Period(), 0) : 0; double bearishPinbarLow = bearishPinbarCondition ? iLow(Symbol(), Period(), 0) : 0; bool secondCandleAfterBullish = bullishPinbarHigh > 0 && iClose(Symbol(), Period(), 1) > bullishPinbarHigh; bool secondCandleAfterBearish = bearishPinbarLow > 0 && iClose(Symbol(), Period(), 1) < bearishPinbarLow; double stopLoss = PositionGetDouble(POSITION_PRICE_OPEN) * (1 - stopLossPct / 100); double takeProfit = PositionGetDouble(POSITION_PRICE_OPEN) * (1 + takeProfitPct / 100); if (secondCandleAfterBullish) { if (!PositionGetInteger(POSITION_TYPE)) { trade.Buy(magicNumber, 0.1, Ask, 0, 0, 0, "Buy", 0, clrNONE); } } if (secondCandleAfterBearish) { if (!PositionGetInteger(POSITION_TYPE)) { trade.Sell(magicNumber, 0.1, Bid, 0, 0, 0, "Sell", 0, clrNONE); } } if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { trade.PositionModify(PositionGetInteger(POSITION_TICKET), stopLoss, takeProfit); } else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) { trade.PositionModify(PositionGetInteger(POSITION_TICKET), takeProfit, stopLoss); } } //+------------------------------------------------------------------+
Zaky Hamdoun #:
Send your full code please.
Send your full code please.
I suppose you have initialized « CTrade trade », and not « CTrade Trade ».
Here, the error tells you you have not initialized the CTrade instance called « Trade ».
Here's the full code

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, I tried compiling this code for an EA but kept getting an error. Please help.
here is the error i get.