You wrote the code so you should know what it is supposed to do.
When it doesn't execute as you expect, check your code carefully.
As I said before...
Keith Watford:
Then, as a coder you should be asking yourself "Why doesn't it print the error??"
The obvious answer is because there was no error!
If there was no error, then it can only be because there was no attempt to close any trade (or because a trade was closed).
What are the possible reasons for there being no attempt to close any trade?
Only possible answers.......
There was not a trade open with the symbol.
The OrderSelect() failed.
The function was not called.
Add prints in your code to find the correct answer.
Did you check all the above?
if (GetTotalOpenTrades() < MaxTrades) {
//
}
elseif (GetTotalOpenTrades() < MaxTrades) {
//No code within these braces will be executed!
}
I have removed the actual code from the above and an error is obvious.
Now lets take a look at the first block...
if (GetTotalOpenTrades() < MaxTrades) { //What if Open trades does = MaxTrades?? None of the block will be executedif ( (TimeCurrent() - LastTradePlacedTimeStamp) < TradeDelayTimeSeconds ) return;
if ((LastFastEMA < LastSlowEMA)
&&(FastEMA > SlowEMA)) {
LongSetup = True; //LongSetup = True,(FastEMA > SlowEMA), so a trade is placed
}
if (LongSetup == True){
Comment ("Buy");
int OrderResultLong = OrderSend(Symbol(), OP_BUY, LotsToTrade, Ask, 0, 0, 0, "Buy Order", Magic, 0, clrGreen);
}
if (LongSetup == True && FastEMA < SlowEMA) CloseAllTrades(); //If LongSetup = True,(FastEMA > SlowEMA), so CloseAllTrades() will not be executed
LongSetup = False; //LongSetup = False so the next time the above if is called, CloseAllTrades() will not be executed
LastTradePlacedTimeStamp = TimeCurrent();
}
Look at the ema condition for LongSetup to be true
So here, if LongSetup is true the ema condition cannot be true so this if will always be false.
I did that on purpose since I want the trade to close when the EMA crosses in a long position. So in this case since it is already true I can get rid of the true statement
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
There is not even a single Print in your code!
They were not printing I took them out
They were not printing I took them out
So instead of investigating why they are not printing, you took the Prints out of the code??!!
That makes no sense at all!
You wrote the code so you should know what it is supposed to do.
When it doesn't execute as you expect, check your code carefully.
As I said before...
Then, as a coder you should be asking yourself "Why doesn't it print the error??"
The obvious answer is because there was no error!
If there was no error, then it can only be because there was no attempt to close any trade (or because a trade was closed).
What are the possible reasons for there being no attempt to close any trade?
Only possible answers.......
There was not a trade open with the symbol.
The OrderSelect() failed.
The function was not called.
Add prints in your code to find the correct answer.
Did you check all the above?
I have removed the actual code from the above and an error is obvious.
Now lets take a look at the first block...
You wrote the code so you should know what it is supposed to do.
When it doesn't execute as you expect, check your code carefully.
As I said before...
Did you check all the above?
I have removed the actual code from the above and an error is obvious.
Now lets take a look at the first block...
Im not sure what you mean with this comment
Look at the ema condition for LongSetup to be true
So here, if LongSetup is true the ema condition cannot be true so this if will always be false.
Look at the ema condition for LongSetup to be true
So here, if LongSetup is true the ema condition cannot be true so this if will always be false.
I did that on purpose since I want the trade to close when the EMA crosses in a long position. So in this case since it is already true I can get rid of the true statement
This is my code so far. But trades still do not close when the opposite signal occurs. What do you think the problem is?
In my post #43 I included
You have completely ignored it!!