Hmm, but it doesn't seem to do what I want the program to do.
Like I said last time, I need the PreviousValue to equal CurrentValue only if there are no trades placed. If there is an active trade, I want PreviousValue not to equal currentvalue but equal the last currentvalue before the trade was placed (thats why we made previousvalue static, remember?).
This code seems to set previousvalue equal to current value only when there is a trade active. It is an opposite of what i am trying to achieve.
Thank you.
If you need to store value only if there is no trade active, why don't you count the number of currently opened orders for a magic number and symbol and assign a value to previous value only if that number of currently opened orders is 0?
Something like this :
[PHP] int count=0;
for (int i=OrdersTotal()-1; i>=0; i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != SomeMagicNumber) continue;
if (OrderType()==OP_BUY || OrderType()==OP_SELL)
count++;
}
if (count==0) PreviousValue = CurrentValue;
That way it will not depend on any variable and can easily be run from multiple terminals and multiple EA instances without a possibility of error
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.
Thank you for answer mladen.
Hmm, but it doesn't seem to do what I want the program to do.
Like I said last time, I need the PreviousValue to equal CurrentValue only if there are no trades placed. If there is an active trade, I want PreviousValue not to equal currentvalue but equal the last currentvalue before the trade was placed (thats why we made previousvalue static, remember?).
bool IsTrade=False;
static double PreviousValue=-1;
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
IsTrade = True;
PreviousValue = CurrentValue;
} [/php]
This code seems to set previousvalue equal to current value only when there is a trade active. It is an opposite of what i am trying to achieve.
Thank you.If you need to store value only if there is no trade active, why don't you count the number of currently opened orders for a magic number and symbol and assign a value to previous value only if that number of currently opened orders is 0?
Something like this :
[PHP] int count=0;
for (int i=OrdersTotal()-1; i>=0; i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != SomeMagicNumber) continue;
if (OrderType()==OP_BUY || OrderType()==OP_SELL)
count++;
}
if (count==0) PreviousValue = CurrentValue;
That way it will not depend on any variable and can easily be run from multiple terminals and multiple EA instances without a possibility of error
Thanks a lot :-) works like a charm now :-) well, at least it does what its supposed to...