Hmm...
Some very rough descriptions:
if ( OrderSelect( OrdersTotal(),SELECT_BY_POS,MODE_TRADES);//select last order in pool { if (OrderProfit() > X ) //if profit (without swaps or commissions) is larger than MyLimit { //Do Your Stuff } }
Hmm...
Some very rough descriptions:
Hi DayTrader, he is after closed position, so OrderHistoryTotal and MODE_HISTORY is probably right one. ie
if (OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)==true) //select last closed position
{
blah blah..
Yes you're right.
Hi folks!
Basically, I need to assign a 1 to my variable if the last closed trade was positive, and a 0 if it was negative. I'm sort of doing a martingale strategy with a positive expected profit.. Please give me suggestions and/or clues..
Whoever helps me out will receive prayers and positive energy and good karma!! ;) hehehe
Happy trading!
Heyarn
Regarding last closed trade - is it okay if that last closed trade was a few days old and on a different currency pair to the chart in which the EA is running?
Or does it need to be the current pair and/or originally opened in the same trading day/hour/half hour etc?
Regarding last closed trade - is it okay if that last closed trade was a few days old and on a different currency pair to the chart in which the EA is running?
Or does it need to be the current pair and/or originally opened in the same trading day/hour/half hour etc?
If you use MODE_HISTORY and SELECT_BY_POS then the search is done in the history loaded on your account terminal. All orders will be concerned, what ever is the currency pair. BUT FIRST YOU HAVE TO SORT YOUR HISTORY IN THE WAY YOU WANT YOUR PROGRAM TO FIND IT : if you select 3 days of history, then the program won't be able to find an order closed a week ago. If you select Last week, then be careful on monday: it won't retrieve the last closed order from the previous week. Pay also attention to the sort criteria, etc.
Regarding last closed trade - is it okay if that last closed trade was a few days old and on a different currency pair to the chart in which the EA is running?
Or does it need to be the current pair and/or originally opened in the same trading day/hour/half hour etc?
CB,
thanks so much for your help! Currently, the EA closes all trades at 0:00 hours every day regardless if its positive or negative profit. I would like for it to assess only the losing closed trades of the previous day (relevant to the magic number and the current currency pair of the chart..)
So far this is what I have placed in the script. Problem is that after it places a larger order to compensate the recent loss, all the successive trades are increased by that amount.. I'm trying to figure out what I'm missing.. Please help =)
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
if (OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)==true) //select last closed position
{Comment
if (OrderProfit() < -160 ) //if profit (without swaps or commissions) is larger than MyLimit
{
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.0005,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.0008,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.001,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.0005,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.0008,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.001,"",MAGICMA,0,Blue);
}
}
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
}
CB,
thanks so much for your help! Currently, the EA closes all trades at 0:00 hours every day regardless if its positive or negative profit. I would like for it to assess only the losing closed trades of the previous day (relevant to the magic number and the current currency pair of the chart..)
So far this is what I have placed in the script. Problem is that after it places a larger order to compensate the recent loss, all the successive trades are increased by that amount.. I'm trying to figure out what I'm missing.. Please help =)
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
if (OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)==true) //select last closed position
{Comment
if (OrderProfit() < -160 ) //if profit (without swaps or commissions) is larger than MyLimit
{
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.0005,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.0008,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.001,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.0005,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.0008,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.001,"",MAGICMA,0,Blue);
}
}
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
}
Hi Everyone!
Thanks for all your help, I was able to get it to work! Really appreciate your help. Wish you all the best and goodluck and happy trading!
heyarn
CB,
thanks so much for your help! Currently, the EA closes all trades at 0:00 hours every day regardless if its positive or negative profit. I would like for it to assess only the losing closed trades of the previous day (relevant to the magic number and the current currency pair of the chart..)
So far this is what I have placed in the script. Problem is that after it places a larger order to compensate the recent loss, all the successive trades are increased by that amount.. I'm trying to figure out what I'm missing.. Please help =)
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
if (OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)==true) //select last closed position
{Comment
if (OrderProfit() < -160 ) //if profit (without swaps or commissions) is larger than MyLimit
{
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.0005,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.0008,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_SELL,LotSize*10,Bid,3,Bid + SLShort,Bid - TPShort-0.001,"",MAGICMA,0,Red);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.0005,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.0008,"",MAGICMA,0,Blue);
OrderSend(Symbol(),OP_BUY,LotSize*10,Ask,3,Ask - SLLong,Ask + TPLong+0.001,"",MAGICMA,0,Blue);
}
}
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
}
Hi Everyone!
Thanks for all your help, I was able to get it to work! Really appreciate your help. Wish you all the best and goodluck and happy trading!
heyarn
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi folks!
Basically, I need to assign a 1 to my variable if the last closed trade was positive, and a 0 if it was negative. I'm sort of doing a martingale strategy with a positive expected profit.. Please give me suggestions and/or clues..
Whoever helps me out will receive prayers and positive energy and good karma!! ;) hehehe
Happy trading!
Heyarn