EA programming tutorial book of trading functions
read:2023/2/24 18:45:21

from the custom indicators can not call OrderSend (), OrderClose, OrderCloseBy, OrderDelete and OrderModify trading cashback forexs OrderClose OrderCloseBy OrderClosePrice OrderCloseTime OrderComment OrderCommforextradingaccountsregistersion OrderDelete OrderExpiration OrderLots OrderMagicNumforextradingaccountstyper OrderModify OrderOpenPrice OrderOpenTime OrderPrint OrderProfit nbsp;OrderSelect OrderSend OrdersHistoryTotal OrderStopLoss OrdersTotal OrderSwap OrderSymbol OrderTakeProfit OrderTicket OrderType boolOrderClose(intticket,doublelots,doubleprice,intslippage,voidColor) close the position on the forex trading accounts operation if the function succeeds, the value returned is true if the function fails, the value returned is false to get detailed error information, see GetLastError() function parameters: ticket - order number lots - number of lots price -& nbsp;closing price slippage - highest scratch point Color - chart marker color if the parameter is missing, CLR_NONE value will not be drawn in the chart example: if(iRSI(NULL ,0,14,PRICE_CLOSE,0)>75) { OrderClose(order_id,1,Ask,3,Red); return(0); ; } boolOrderCloseBy(intticket,intopposite,voidColor) closes the position with the opposite order to open the position if the function succeeds, the value returned is true if the function fails If the function fails, the returned value is false. To get detailed error information, see GetLastError() function parameters: ticket - order number composite - relative order number Color - chart marker color if the parameter is missing, the CLR_NONE value will not be drawn in the chart Example: if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75) { OrderCloseBy (order_id,composite_id); return(0); } doubleOrderClosePrice() for the currently selected order returns OrderClosePrice Note: Order must be selected in advance using the OrderSelect() function Example: if(OrderSelect(ticket,SELECT_BY_POS)==true) Print(for order, order number =, OrderClosePrice() the closing price); else Print(OrderSelect failure error code is,GetLastError()); datetimeOrderCloseTime() for the current selection of the order to return to close time if the order time is not 0, the selected order will retry to open and pending transactions from the account history close time must be equal to 0 Note: the order must be selected in advance with the OrderSelect () function Example: if(OrderSelect( 10,SELECT_BY_POS,MODE_HISTORY)==true) { datetimectm=OrderOpenTime(); if(ctm> 0)Print(order10OpenTime,ctm); ctm=OrderCloseTime(); if(ctm>0)Print(order10CloseTime,ctm); } else Print(OrderSelect failure error code is,GetLastError()); stringOrderComment() return order comment note: order must be used OrderSelect() function selected in advance Example: stringcomment; if(OrderSelect(10,SELECT_BY_TICKET)==false) {Print(OrderSelect failed error code is,GetLastError()); return(0); } comment=OrderComment(); //... doubleOrderCommission() returns the number of commissions on the order Note: The order must be selected in advance using the OrderSelect() function Example: if(OrderSelect(10,SELECT_BY_POS)==true) Print(order10 commission,OrderCommission()); else Print(OrderSelect failed error code is,GetLastError()); boolOrderDelete( intticket,voidColor)Delete previously opened pending ordersIf the function succeeds, the returned value is trueIf the function fails, the returned value is falseGet detailed error information, see GetLastError() function parameters:ticket - Order number Color -& nbsp;Chart marker color if the parameter is missing, CLR_NONE value will not be drawn in the chart Example: if(Ask>var1) { OrderDelete(order_ ticket); return(0); } datetimeOrderExpiration() returns the effective date of the pending orderNote: The order must be selected with the OrderSelect () function selected in advance example: if(OrderSelect(10,SELECT_BY_TICKET)==true) Print(order#10 valid date for,OrderExpiration()); else Print(OrderSelect returned,GetLastError() error); doubleOrderLots() returns the number of lots selected orderNote: order must be selected with OrderSelect () function selected in advance Example: if(OrderSelect(10,SELECT_BY_POS)==true) Print(order10 lots,OrderLots()); else Print(OrderSelect returned, GetLastError() error); intOrderMagicNumber() return to the selected order the specified number Note: the order must be selected in advance with the OrderSelect() function Example: ;if(OrderSelect(10,SELECT_BY_POS)==true) Print(order10 specified number,OrderMagicNumber()); else Print( OrderSelect returned,GetLastError() error); boolOrderModify(intticket,doubleprice,doublestoploss,doubletakeprofit, datetimeexpiration,voidarrow_color) for the previous open or pending order to modify the characteristics of the function if the function succeeds, the value returned is TRUE if the function fails, the value returned is FALSE to get detailed error information, see GetLastError() function Note: open price and effective time change only for pending orders If the unchanged value is passed as a function parameter, error 1 will be generated (ERR_NO_RESULT) in some servers the valid time of the pending order will be hidden in this case, when a non-zero value is specified in the valid parameter, error 147 will be generated (ERR_TRADE_EXPIRATION_DENIED) parameter: ticket& nbsp;- order number price - closing price stoploss - new stop loss level takeprofit - new profit level expiration nbsp;- pending order effective time arrow_color - in the chart to allow changes to the stop/win color if the parameter is missing or there is a CLR_NONE value, it will not be displayed in the chart example: if(TrailingStop >0) { OrderSelect(12345,SELECT_BY_TICKET); if(Bid-OrderOpenPrice()>Point* TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop ) { OrderModify( OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Blue); nbsp;return(0); } } } doubleOrderOpenPrice() for the current selection of the order to return to open the price order must be selected by the OrderSelect() function first example: if(OrderSelect(10,SELECT_BY_POS)==true) Print (for Order10OpenPrice()); else Print(OrderSelect return error,GetLastError()); datetimeOrderOpenTime() for the current selection of the order to return to buy time Note: order must be selected in advance with the OrderSelect () function Example: if(OrderSelect(10,SELECT_BY_POS)==true) Print(Order10 buy time,OrderOpenTime()); else Print(OrderSelect return error,GetLastError()); voidOrderPrint() in accordance with the following form to print the selected order information: order number; buy time; trading operations; total number of lots; opening price; stop loss; win; close time; closing price; commission; swap; profit; comments; specify the code; pending order effective date order must be selected in advance with OrderSelect() function example: if (OrderSelect(10,SELECT_BY_TICKET)==true) OrderPrint(); else Print(OrderSelect failure error code is,GetLastError());& nbsp; doubleOrderProfit() for the selection of the order to return to the net profit value (in addition to swaps and commissions) for the opening position is not currently true profit for the closing of the position for the fixed profit for the current selection of the order to return to profit Note: the order must be selected in advance with the OrderSelect () function Example: if( OrderSelect(10,SELECT_BY_POS)==true) Print(Order10 profit,OrderProfit()); else Print(OrderSelect returned error,GetLastError()); boolOrderSelect(intindex,intselect,voidpool) function to select the order if the function succeeds, the returned value is TRUE if the function fails, the returned value is FALSE get details For detailed error information, see the GetLastError() function If the order number is selected, this pool parameter is cognizant of this order number as a unique identifier Find the list of selected orders, its closing time must be analyzed If the order sell time is zero, open and pending orders will be opened from the list of terminal positions can be distinguished from the order type Open pending orders and open orders If the order sell time is not equal to If the sell time of the order is not equal to 0, the close and delete orders are selected in the terminal history and they can also be distinguished from the delete orders are selected in the terminal history and they can also be distinguished from the order type parameter:index - order index select - selected mode can be any of the following values:SELECT_BY_POS SELECT_BY_TICKET pool - selectable order index when SELECT_BY_POS parameter is selected can be any of the following values: MODE_TRADES(default)-orders from transactions (open and pending orders), MODE_HISTORY-orders from history (open and pending orders), MODE_TRADES(default), MODE_TRADES(default), MODE_TRADES(default), MODE_TRADES(default), MODE_TRADES(default), MODE_TRADES(default). HISTORY-from the history of the order (close and cancel the order) Example: if(OrderSelect(12470,SELECT_BY_TICKET)==true) { Print(Order#12470OpenPrice,OrderOpenPrice()); Print(Order#12470ClosePrice,OrderClosePrice()); } else & nbsp; Print(OrderSelect return error,GetLastError()); intOrderSend(stringsymbol,intcmd,doublevolume,doubleprice, intslippage,doublestoploss,doubletakeprofit,voidcomment,voidmagic,voidexpiration,voidarrow_color) This function is mainly applied to open positions and pending order transactions. By the transaction server to return the order number of the order or -1, indicating that it is wrong to get another error message, check GetLastError () function note: the market order opening (OP_SELLorOP_BUY), only the last selling price or buying price can be applied to the opening price. If the current operation with different securities is executed, the MarketInfo() function with the MODE_BID or MODE_ASK parameter must be used to obtain it. Predicted or non-standard prices are not available. Error 129 (ERR_INVALID_PRICE) will be generated if no re-opening of the price is requested or if it is not normalized by the number of decimal places. Error 138 (ERR_REQUOTE) will be generated if the date of the requested price is completely out of date. If the requested price is out of date, the position can only be opened at the current price level/only the current price level is within the price+-slippage range. Stop Loss and Take Profit levels cannot close the market. The MODE_STOPLEVEL parameter can be obtained using the MarketInfo() function in case of an error or an abnormal stop level, error 130 (ERR_INVALID_STOPS) will be generated. In the position of the pending order, the opening price cannot terminate the market activity. The minimum distance to the end of the level point can be obtained using the MarketInfo() function MODE_STOPLEVEL parameter in the case of an error or an abnormal level stop, error 130 (ERR_INVALID_STOPS) will be generated. The duration of pending trades is forbidden on some servers. In this case, a special non-zero value of the parameter will be generated and error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated On some servers, the total number of open and pending trades will be limited. If the limit is exceeded, then no new positions can be opened so that the trading server returns to error 148 (ERR_TRADE_TOO_MANY_ORDERS) parameter:symbol - transaction currency pair cmd - purchase method can be any value listed in the purchase method volume - purchase method can be any value listed in the purchase method. nbsp;- purchase lots price - closing price slippage - maximum allowed slippage stoploss - stop loss level takeprofit ;- win level comment - the last part of the comment text comment can be changed by the server magic - the order designation code can be used as the user designation identification code expiration - the order valid time (pending orders only) arrow_color - the color of the arrow on the chart if the parameter is missing or present CLR_NONE price value will not be drawn in the chart example: intticket; if(iRSI(NULL,0,14, PRICE_CLOSE,0)<25) { ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point, Myorder#2,16384,0,Green); if(ticket<0) { ;Print(OrderSend Failure Error#,GetLastError()); return(0); } nbsp; } intOrdersHistoryTotal() in the account history returns the number of closed orders loaded into the terminal history list depending on the current settings of the terminals account history form. Example: //recovery information from the transaction history inti,hstTotal=OrdersHistoryTotal(); for(i=0;i<hstTotal;i++) { nbsp;//---- check the selection results if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print(with(,GetLastError(),) error history failure channel); break; nbsp; } //some work on the order doubleOrderStopLoss() for the current selection of the order to return the stop-loss value Note: the order must be used OrderSelect() function selected in advance Example: if(OrderSelect(ticket,SELECT_BY_POS)==true) Print(for 10 stop loss value,OrderStopLoss()); else Print(OrderSelect failure error code is,GetLastError()); intOrdersTotal() returns the total number of markets and pending orders Example: inthandle= FileOpen(OrdersReport.csv,FILE_WRITE|FILE_CSV,/t); if(handle<0)return(0); //write the title FileWrite(handle,#,open price,buy time,currency pair, number of lots); inttotal=OrdersTotal(); //write order order for(intpos=0;pos<total;pos++) { if( OrderSelect(pos,SELECT_BY_POS)==false)continue; FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(), OrderSymbol(),OrderLots()); } FileClose(handle); doubleOrderSwap() for the current selection of the order to return to the swap value Note: The order must be selected in advance with the OrderSelect() function Example: if(OrderSelect(order_id,SELECT_BY_TICKET)==true) Print(for order # swap,order_id,, OrderSwap()); else Print(OrderSelect failed error code is,GetLastError()); stringOrderSymbol() For order selection return order currency pair value note: the order must be selected in advance using the OrderSelect() function example: if(OrderSelect(12,SELECT_BY_POS)==true) Print(order# currency pair,OrderTicket(),is, OrderSymbol()); else Print(OrderSelect failure error code is,GetLastError()); doubleOrderTakeProfit() for the current selection of the order to return to the winnings value Note: order must be used OrderSelect() function selected in advance Example: if(OrderSelect(12,SELECT_BY_POS)==true) Print(order#,OrderTicket(),profit:,OrderTakeProfit() ); else Print(OrderSelect() return error-,GetLastError()); intOrderTicket() for the current selection of the order to return the order No. Note: order must be selected in advance with the OrderSelect() function Example: if(OrderSelect(12,SELECT_BY_POS)==true) order=OrderTicket(); else Print(OrderSelect failure error code, GetLastError()); intOrderType() for the current selection of the order to return the order type can be any of the following values: OP_BUY - buy, OP_SELL - sell, OP_ BUYLIMIT-pending order buy limit, OP_BUYSTOP-pending order stop limit, OP_SELLLIMIT-pending order sell limit, OP_SELLSTOP-pending order stop limit Note: order must be selected by the OrderSelect() function Example: intorder_type; if( OrderSelect(12,SELECT_BY_POS)==true) { order_type=OrderType(); //... } else Print(OrderSelect() return error-,GetLastError());