Thanks for the response Daniel. I added some debugging code to check your suggestion - shame it didnt print to the journal!!
// If true, Calculate the highest closing price of the last `candleCount` candles double highPrice = NormalizeDouble(High[iHighest(Symbol(), shortTimeFrame, MODE_HIGH, candleCount, 1)]+ pipsOffset * bPoint,Digits); Comment("highPrice: ", highPrice); Comment("Current price: ", MarketInfo(Symbol(), MODE_ASK)); if(highPrice > MarketInfo(Symbol(), MODE_ASK)){ //entry price is above current price, which is what is expected Comment("Entry price is above current price"); } else { // Something is wrong Comment("Something is wrong as entry price is not higher than current price!!"); }
I tried both comment and print.
I am still working on it, as I feel you may be onto something. I asked my broker if they had minimums for Take Profit and Stop Loss in case that was my issue as well. They are to get back to me. I have tried the EA on another broker and the same errors occur (doesnt tell me a lot as they may also have minimums.
I'll report back once I can get some valid error info
G
-
double highPrice = NormalizeDouble(High[iHighest(Symbol(), shortTimeFrame, MODE_HIGH, candleCount, 1)]+ pipsOffset * bPoint,Digits);
The predefined arrays are the current chart. Your iHighest is using the shortTimeFrame. You are mixing apples and oranges.
-
ticket = OrderSend(Symbol(), OP_BUYSTOP, Lotsize, highPrice, slippage * bPoint, 0, 0, EAname, magicNumber, 0, Green);
Perhaps you should read the manual. The slippage parameter is specified in points, not in PIP distance.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
-
The predefined arrays are the current chart. Your iHighest is using the shortTimeFrame. You are mixing apples and oranges.
-
Perhaps you should read the manual. The slippage parameter is specified in points, not in PIP distance.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
Thank you for the feedback William Roeder. I have changed the iHighest array to set timeframe to 0 and the slippage value has been changed as well. I am still getting an Error: Invalid Trade Paramenters are set. OrderSend error 3.
Updated code:
// Check for a Signal Candle to be true from long term chart if (IsSignalCandle() == true){ Print("Signal Candle is true"); // If true, Calculate the highest closing price of the last `candleCount` candles double highPrice = NormalizeDouble(High[iHighest(Symbol(),0, MODE_HIGH, candleCount, 1)]+ pipsOffset * bPoint,Digits); Print("highPrice: ", highPrice); // Validate stop loss values double minStopLoss = NormalizeDouble(MarketInfo(Symbol(), MODE_STOPLEVEL) * bPoint,Digits); Print("minStopLoss: ", minStopLoss); double stopLossLong = NormalizeDouble(iLow(Symbol(), 0, candleCount) - pipsOffset * bPoint, Digits); Print("stopLossLong: ", stopLossLong); if(stopLossLong >= minStopLoss) { // The stop loss is valid Print("Stop loss is valid"); } else { // The stop loss is not valid, print an error message Print("Error: Invalid stop loss value. Stop loss must be greater than or equal to ", minStopLoss); } int ticketLong = OrderSend(NULL, OP_BUYSTOP, Lotsize, highPrice, slippage, 0, 0, EAname, magicNumber, 3600, clrLimeGreen); // Debugging code Comment("Symbol: ", Symbol()); Print("Order type: ", "OP_BUYSTOP"); Print("Lot size: ", Lotsize); Print("highPrice: ", highPrice); Print("Slippage: ", slippage); Print("Stop loss: ", 0); Print("Take profit: ", 0); Print("EAname: ", EAname); Print("magicNumber: ", magicNumber); Print("Order expiration time: ", 3600); Print("Order color: ", "clrGreen"); Print("ticket: ", ticketLong); Print("Order open result: ", PrintError(GetLastError())); // Check the return value if(ticketLong < 0) { // Print the error code and message Print("Error placing buy stop order: ", GetLastError());
I am still working on it, as I feel you may be onto something. I asked my broker if they had minimums for Take Profit and Stop Loss in case that was my issue as well. They are to get back to me. I have tried the EA on another broker and the same errors occur (doesnt tell me a lot as they may also have minimums.
To avoid that, you should check you stops against that
SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL)
You should print Current price toghether with your "highprice" to confirm
int ticketLong = OrderSend(NULL, OP_BUYSTOP, Lotsize, highPrice, slippage, 0, 0, EAname, magicNumber, 3600, clrLimeGreen);
Be careful with NULL.
- On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
- MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
- Cloud Protector Bug? - MQL4 programming forum (2020)
Thank you both for helping me make my code better, I have solved the ordersend error, it was with my time to expiry variable.
int ticketLong = OrderSend(Symbol(), OP_BUYSTOP, Lotsize, highPrice, slippage, 0, 0, EAname, magicNumber, TimeCurrent() + Secstoexp, clrLimeGreen);
I needed to add the TimeCurrent() to allow MT4 to get a time reference, added a global variable to add the seconds to that.
Thanks again for the suggestions, all of this makes the learning easier.
Now, onto my ordermodify error 130 :)
GMc
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
and here is the results of my debugging:
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Error placing sell stop order: Invalid trade parameters are set
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: OrderSend error 3
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Error: Invalid stop loss value. Stop loss must be greater than or equal to 0.0
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Error placing buy stop order: 0
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Order open result: Invalid trade parameters are set
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: ticket: -1
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Order color: clrGreen
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Order expiration time: 3600
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: magicNumber: 123456
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: EAname: Zorro V1.0
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Take profit: 0
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Stop loss: 0
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Slippage: 0.0003
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: highPrice: 0.70678
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Lot size: 0.01
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Order type: OP_BUYSTOP
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: OrderSend error 3
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Stop loss is valid
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: stopLossLong: 0.70567
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: minStopLoss: 0.0
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: highPrice: 0.70678
2023.02.08 17:15:13.844 2023.01.31 03:53:50 sxcalp AUDUSD.a,M1: Signal Candle is true
I am a total newbie with coding and have been back and forth with Int's and doubles. I thought it was slippage causing an issue, then I thought it was stoploss. See additional code in the above that isnt necessary, but there to attempt to ensure a valid stop loss value.
Any assistance is appreciated.
Regards
GMC