cape1354: However, this will result in error 4051.
ticket=OrderSend(NULL,OP_BUY,Calcul_Lot,Ask,3,0,0,"ma sample",MagicNo,0,Green);
-
- You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, MarketInfo does not. OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period.
- No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
- You assume history is ordered by date, it's not.
whroeder1:
-
- You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, MarketInfo does not. OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period.
- No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
- You assume history is ordered by date, it's not.
I tried to like this
ticket=OrderSend("EURUSD",OP_SELL,Calcul_Lot,Bid,3,0,0,"ma sample",MagicNo,0,Red);
but problem still exist and
2017.08.05 00:17:05.456 2016.08.09 09:00:00 Test 17.08.04-1 EURUSD,M30: invalid lots amount for OrderSend function
These problems occur as well.
Isn't there a problem with lot calculation?
I have deleted your other topic.
Please do not open new topics that are basically a duplication of this one. You will not get different answers by duplicating your posts. In fact you are more likely to annoy posters and they may elect to not help you at all!
I made the code different.
However, errors 4051 and " Initial Requirement for Functional Analysis " still occur.
Which is the problem?
extern double initial_Lots = 1.0; extern int MagicNo = 1234; extern double Martingale = 2.0; int start() { if(NewBar() ) { if(/*Buy Entry condition*/) { ticket=OrderSend(NULL,OP_BUY, LotCal(),Ask,3,0,0,"sample",MagicNo,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); Print("Buy SR : ",Success_Rate); } else Print("Error opening BUY order : ",GetLastError()); } } //+------------------------------------------------------------------+ //| Accompany only when new bar appears | //+------------------------------------------------------------------+ bool NewBar() { if(PreviousBar<Time[0]) { PreviousBar=Time[0]; return(true); } return(false); } //+------------------------------------------------------------------+ //| LOT calculation | //+------------------------------------------------------------------+ double LotCal() { double Calcul_Lot; double LotsVolume=0; for(i=OrdersHistoryTotal()-1;i>=0;i--) //Find Last Order { if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)) { LotsVolume=OrderLots(); // Save the last order to LotsVolume //for buy order } } if(OrderType()==OP_BUY && OrderProfit()<0) //As Buy In Losses {Calcul_Lot=LotsVolume*Martingale;} if(OrderType()==OP_SELL && OrderProfit()<0) //As Sell In Losses {Calcul_Lot=LotsVolume*Martingale;} if((OrderType()==OP_SELL && OrderProfit()>0)||(OrderType()==OP_BUY && OrderProfit()>0)) {Calcul_Lot=initial_Lots;} //As Buy In profit,as Sell In profit return(Calcul_Lot); // Finally, obtain a double value of CalCul_local in the LotCal () function }
whroeder1:
- You assume history is ordered by date, it's not.
Keith Watford:
Could you explain it to me based on the code?
cape1354:
You must find the last closed order as in the code below. (Not compiled or tested)Could you explain it to me based on the code?
//+------------------------------------------------------------------+ //| LOT calculation | //+------------------------------------------------------------------+ double LotCal() { double Calcul_Lot=initial_Lots; datetime order_close_time=0; for(int i=OrdersHistoryTotal()-1;i>=0;i--) //Find Last Order { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && (OrderType()==OP_BUY || OrderType()==OP_SELL)) { if(OrderCloseTime()>order_close_time) { order_close_time=OrderCloseTime(); if(OrderProfit()<0) Calcul_Lot=LotsVolume*Martingale; else Calcul_Lot=initial_Lots; } } } return(Calcul_Lot); } //+------------------------------------------------------------------+
Keith Watford:
You must find the last closed order as in the code below. (Not compiled or tested)
You must find the last closed order as in the code below. (Not compiled or tested)
I solved the problem with your help.
Thank you for your help.
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
Wait for your help.