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
I can't use ticket1 as a global variable, because mt would open a new order every tick. I've tried this already.
That is because you are not applying logical steps
This is only intended as a basic outline
...
int start()
{
double fastMA = iMA(Symbol(), PERIOD_CURRENT, PeriodFastMA, 0, MODE_SMA, PRICE_CLOSE, 0);
double slowMA = iMA(Symbol(), PERIOD_CURRENT, PeriodSlowMA, 0, MODE_SMA, PRICE_CLOSE, 0);
int ticket1 = OrderSend(Symbol(), OP_BUY, lots, Ask, 0, 0, 0);
//Buy Condition:
if(fastMA > slowMA && fastMA > 0 && slowMA > 0 && OrdersTotal() == 0)
{
if(ticket1 > 0)
{
Alert("Order Sended Successfully. Order No.: ", ticket1);
}
else
{
Alert("Order Sending Error!");
}
....
exactly! but if I take my order into the //Buy Condition which starts if fastMA is greater then slowMa. I can't take my //Sell Condition into my //Buy Condition. I would like for mt to remembering my ticket1 in my sell condition. But the ticket1 variable is just a local variable. Is there something like:
I want to try the simplest of all strategies.
if Fast Moving Average is greater than the slow one.
->Buy order
if the fast moving average is lower than the slow one.
->close that position
What you want to achieve is quite easy actually.
The ticket1 is for what? If you need to close all, just use loop.
exactly! but if I take my order into the //Buy Condition which starts if fastMA is greater then slowMa. I can't take my //Sell Condition into my //Buy Condition. I would like for mt to remembering my ticket1 in my sell condition. But the ticket1 variable is just a local variable. Is there something like:
If you need to close all, just use loop to close when the condition to close is met such as signal is changing from buy to sell.
No need to use ticket number. We use ticket number if we want to find a specific trade.
Just use loop to close trade if you just want to close any open trades.