|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
|
|
LinkBack (1) | Thread Tools |
|
|||
|
Recall result of last trade
is it possible to recall if the last trade hit TP or SL and make a trade according to that? thanks.
__________________
There is no candle. |
|
|
|||
|
|||
|
Quote:
PHP Code:
Last edited by Michel : 07-19-2007 at 06:06 PM. |
|
|
|||
|
|||
|
Quote:
|
|
|
|||
|
|||
|
ive changed the code according to the other thread i made, and all is well so thank you for that - btw very clean code i like it
ive compiled and no problems, however, no trades are made either heres my codeCode:
//+----------------------------START---------------------------------+
extern int TakeProfit = 90;
extern int StopLoss = 30;
int start()
{
double ma1, stop, profit, slippage;
ma1 = iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,0);
slippage = 1;
stop = StopLoss*Point;
profit = TakeProfit*Point;
if(OrdersTotal()<1) //max number of orders at a time
{
/*BUY*/ if(Close[1]<bbL && Open[1]<ma1 && Close[1]<ma1)
OrderSend(Symbol(),OP_BUY,lots(),Ask,slippage,Ask-stop,Ask+profit,0);
/*SELL*/if(Close[1]>bbU && Open[1]>ma1 && Close[1]>ma1)
OrderSend(Symbol(),OP_SELL,lots(),Bid,slippage,Bid+stop,Bid-profit,0);
}
}
int lots()
{
int i, lots,HstTotal=OrdersHistoryTotal();
datetime LastClose = 0;
int Magic = 2005;
for(i = HstTotal-1; i >= 0; i --)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
if(OrderSymbol() != Symbol()) continue;
if(OrderMagicNumber() != Magic) continue;
if(OrderCloseTime() <= LastClose) continue;
LastClose = OrderCloseTime();
lots = 0.1;
if(OrderClosePrice() == OrderStopLoss()) lots = 0.2;
if(OrderClosePrice() == OrderTakeProfit()) lots = 0.1;
}
return(lots);
}
//+-----------------------------END----------------------------------+
__________________
There is no candle. |
|
|
|||
|
|||
|
Quote:
- if there is no one order in the History, the func Lots() returns 0 as order size. - OrderSend() has more arguments, how did you compile that ? more precisely, the magic number must be set as a parameter, ortherwhize the Lots() func cannot recognize those orders. - Where are you computing bbL and bbU ? if this is done in the init() func, it's the wrong place because init() is called only once, not at every new bar. |
|
|
|||
|
|||
|
my mistake bbL and bbU shouldn't be there, should be
Code:
/*BUY*/ if(Open[1]<ma1 && Close[1]<ma1)
OrderSend(Symbol(),OP_BUY,lots(),Ask,slippage,Ask-stop,Ask+profit,0);
/*SELL*/if(Open[1]>ma1 && Close[1]>ma1)
OrderSend(Symbol(),OP_SELL,lots(),Bid,slippage,Bid+stop,Bid-profit,0);
__________________
There is no candle. |
|
|
|||
|
|||
|
Quote:
The use of OrderSend() I know is : Quote:
PHP Code:
Last edited by Michel : 07-19-2007 at 11:13 PM. |
|
|
|||
|
|||
|
ok ive made them changes but i dont get any trades still, though no errors either which is good i guess, heres my new code
Code:
//+----------------------------START---------------------------------+
extern int TakeProfit = 90;
extern int StopLoss = 30;
int start()
{
double ma1, stop, profit, slippage;
ma1 = iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,0);
slippage = 1;
stop = StopLoss*Point;
profit = TakeProfit*Point;
if(OrdersTotal()<1) //max number of orders at a time
{
/*BUY*/ if(Close[1]<bbL && Open[1]<ma1 && Close[1]<ma1)
OrderSend(Symbol(),OP_BUY,lots(),Ask,slippage,Ask-stop,Ask+profit,"My EA has open this order",0,Blue);
/*SELL*/if(Close[1]>bbU && Open[1]>ma1 && Close[1]>ma1)
OrderSend(Symbol(),OP_SELL,lots(),Bid,slippage,Bid+stop,Bid-profit,"My EA has open this order",0,Blue);
}
}
int lots()
{
int i, HstTotal=OrdersHistoryTotal();
int lots = 0.1;
datetime LastClose = 0;
int Magic = 2005;
for(i = HstTotal-1; i >= 0; i --)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
if(OrderSymbol() != Symbol()) continue;
if(OrderMagicNumber() != Magic) continue;
if(OrderCloseTime() <= LastClose) continue;
LastClose = OrderCloseTime();
if(OrderClosePrice() == OrderStopLoss()) lots = 0.2;
if(OrderClosePrice() == OrderTakeProfit()) lots = 0.1;
}
return(lots);
}
//+-----------------------------END----------------------------------+
__________________
There is no candle. |
|
|
|||
|
|||
|
Quote:
Another mistake is to declare the return value of the lots() func as int. First, OrderSend() needs a double value, and second, if you want to return 0.1, it's clearly a double value... Now, "My EA has open this order" as comment was a sample, if you do not use it, just put "" as comment argument for the OrderSend(). Last edited by Michel : 07-19-2007 at 11:11 PM. |
| Thread Tools | |
|
|
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-4/8542-recall-result-last-trade.html
|
|||
| Posted By | For | Type | Date |
| forex trading related resources | This thread | Refback | 07-10-2007 08:41 PM |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| various ea forward testing result | arui | Post and compare Trades | 13 | 05-06-2007 03:03 PM |
| Different backtesting result of same EA. | takechance | Metatrader 4 | 2 | 10-10-2006 04:00 AM |
| Profitable EA result in Backtest | trohoang | Expert Advisors - Metatrader 4 | 6 | 08-28-2006 09:10 AM |
| Use another Indicator Result | NoName | Questions | 0 | 04-09-2006 02:35 AM |