
&nb HowForexRebatesWork;//+------------------------------------------------------------------+//|If the execution reaches th premiumrebateforex point,|//| it means there are no pending orders and open positions|//+--------- ---------------------------------------------------------+//---- places BuyStop and SellStop:double cashbackforexreviewOpenPriceLevel,_StopLossLevel,_ TakeProfitLevel;_OpenPriceLevel=NormalizeDouble(Ask+Luft*Point,Digits); bestforexrebaterates(StopLoss> How Forex Rebates Work){_StopLossLevel=NormalizeDouble(_ OpenPriceLevel-StopLoss*Point,Digits);}else{_StopLossLevel=0.0;}if(TakeProfit>0){_TakeProfitLevel=NormalizeDouble(_ OpenPriceLevel+ TakeProfit*Point,Digits);}else{_TakeProfitLevel=0.0;}if(OrderSend(Symbol(),OP_BUYSTOP,Lot,_OpenPriceLevel,5,_ StopLossLevel,_TakeProfitLevel,,_MagicNumber)<0){Alert(OrderSendError#,GetLastError());return(-1);}_OpenPriceLevel= NormalizeDouble(Bid-Luft*Point,Digits);if(StopLoss>0){_StopLossLevel=NormalizeDouble(_OpenPriceLevel+StopLoss*Point,Digits);} else{_StopLossLevel=0.0;}if(TakeProfit>0){_TakeProfitLevel=NormalizeDouble(_OpenPriceLevel- TakeProfit*Point,Digits);}else {_TakeProfitLevel=0.0;}if(OrderSend(Symbol(),OP_SELLSTOP,Lot,_OpenPriceLevel,5,_StopLossLevel,_TakeProfitLevel,,_MagicNumber)<0 ){Alert(OrderSendError#,GetLastError());return(-1);}return(0);}Now lets write the function that can simplify the control build code, it must search with each type of order and then store cashback forex information in a global variable, the program is as follows:// in the order characteristics of the The global variables will be stored:int_BuyTicket=0,_SellTicket=0,_BuyStopTicket=0;int_SellStopTicket=0,_BuyLimitTicket=0,_SellLimitTicket=0;double_BuyLots= 0.0,_SellLots=0.0,_BuyStopLots=0.0; double_SellStopLots=0.0,_BuyLimitLots=0.0, _SellLimitLots =0.0;double_ BuyOpenPrice=0.0,_SellOpenPrice=0.0, _BuyStopOpenPrice =0.0;double_SellStopOpenPrice=0.0,_BuyLimitOpenPrice=0.0,_ SellLimitOpenPrice=0.0;double_BuyStopLoss=0.0,_SellStopLoss=0.0,_BuyStopStopLoss=0.0;double_SellStopStopLoss=0.0,_BuyLimitStopLoss =0.0,_SellLimitStopLoss=0.0;double_BuyTakeProfit=0.0,_SellTakeProfit=0.0,_BuyStopTakeProfit=0.0;double_SellStopTakeProfit=0.0,_ BuyLimitTakeProfit=0.0,_SellLimitTakeProfit=0.0;datetime_BuyOpenTime=-1,_SellOpenTime=-1, _BuyStopOpenTime =-1;datetime_ SellStopOpenTime=-1,_BuyLimitOpenTime=-1,_SellLimitOpenTime=-1;double_BuyProfit=0.0,_SellProfit=0.0,_BuySwap=0.0, _SellSwap= 0.0;double_BuyCommission=0.0,_SellCommission=0.0;string_BuyComment=,_SellComment=,_BuyStopComment=; string_SellStopComment=,_ BuyLimitComment=, _SellLimitComment =;datetime_BuyStopExpiration=-1,_SellStopExpiration=-1;datetime_BuyLimitExpiration=- 1,_SellLimitExpiration=-1;voidOneTypeOrdersInit(intmagic){//variables to zero:_BuyTicket=0;_SellTicket=0;_BuyStopTicket=0;_SellStopTicket=0;_ BuyLimitTicket=0;_SellLimitTicket=0;_BuyLots=0.0;_SellLots=0.0;_BuyStopLots=0.0;_SellStopLots=0.0;_BuyLimitLots=0.0;_SellLimitLots =0.0;_BuyOpenPrice=0.0;_SellOpenPrice=0.0;_BuyStopOpenPrice=0.0;_SellStopOpenPrice=0.0;_BuyLimitOpenPrice=0.0; _ SellLimitOpenPrice=0.0;_BuyStopLoss=0.0;_SellStopLoss=0.0;_BuyStopStopLoss=0.0;_SellStopStopLoss=0.0;_BuyLimitStopLoss=0.0; _ SellLimitStopLoss =0.0;_BuyTakeProfit=0.0;_SellTakeProfit=0.0;_BuyStopTakeProfit=0.0;_SellStopTakeProfit=0.0;_ BuyLimitTakeProfit=0.0; _SellLimitTakeProfit=0.0;_BuyOpenTime=-1;_SellOpenTime=-1;_BuyStopOpenTime=-1;_SellStopOpenTime=-1;_ BuyLimitOpenTime=-1; _SellLimitOpenTime =-1;_BuyProfit=0.0;_SellProfit=0.0;_BuySwap=0.0; _SellSwap =0.0;_ BuyCommission=0.0;_SellCommission=0.0;_BuyComment=;_SellComment=;_BuyStopComment=;_SellStopComment=;_BuyLimitComment=; _ SellLimitComment =;_BuyStopExpiration=-1;_SellStopExpiration=-1;_BuyLimitExpiration=-1;_SellLimitExpiration=-1;int_ GetLastError=0,_OrdersTotal=OrdersTotal();for(intz=_OrdersTotal-1;z>=0;z--){if(!OrderSelect(z,SELECT_BY_POS)){_GetLastError= GetLastError();Print(OrderSelect(,z,,SELECT_BY_POS)-Error#, _GetLastError );continue;}if(OrderMagicNumber()==magic&& amp;OrderSymbol()== Symbol()){switch(OrderType()){caseOP_BUY:_BuyTicket=OrderTicket();_BuyLots=NormalizeDouble(OrderLots(),1) ;_BuyOpenPrice=NormalizeDouble(OrderOpenPrice(),Digits);_BuyStopLoss=NormalizeDouble(OrderStopLoss(),Digits);_BuyTakeProfit= NormalizeDouble(OrderTakeProfit(),Digits);_BuyOpenTime=OrderOpenTime();_BuyProfit=NormalizeDouble(OrderProfit(),2);_BuySwap= NormalizeDouble(OrderSwap(),2);_BuyCommission=NormalizeDouble(OrderCommission(),2);_BuyComment=OrderComment();break;caseOP_SELL:_ SellTicket=OrderTicket();_SellLots=NormalizeDouble(OrderLots(),1);_SellOpenPrice=NormalizeDouble(OrderOpenPrice(),Digits);_ SellStopLoss=NormalizeDouble(OrderStopLoss(),Digits);_SellTakeProfit=NormalizeDouble(OrderTakeProfit(),Digits);_SellOpenTime= OrderOpenTime();_SellProfit=NormalizeDouble(OrderProfit(),2);_SellSwap=NormalizeDouble(OrderSwap(),2);_SellCommission= NormalizeDouble(OrderCommission(),2);_SellComment=OrderComment();break;caseOP_BUYSTOP:_BuyStopTicket=OrderTicket();_BuyStopLots= NormalizeDouble(OrderLots(),1);_BuyStopOpenPrice=NormalizeDouble(OrderOpenPrice(),Digits);_BuyStopStopLoss=NormalizeDouble( OrderStopLoss(),Digits);_BuyStopTakeProfit=NormalizeDouble(OrderTakeProfit(),Digits);_BuyStopOpenTime=OrderOpenTime();_ BuyStopComment=OrderComment();_BuyStopExpiration=OrderExpiration();break;caseOP_SELLSTOP:_SellStopTicket=OrderTicket();_ SellStopLots=NormalizeDouble(OrderLots(),1);_SellStopOpenPrice=NormalizeDouble(OrderOpenPrice(),Digits);_SellStopStopLoss= NormalizeDouble(OrderStopLoss(),Digits);_SellStopTakeProfit=NormalizeDouble(OrderTakeProfit(),Digits);_SellStopOpenTime= OrderOpenTime();_SellStopComment=OrderComment();_SellStopExpiration=OrderExpiration();break;caseOP_BUYLIMIT:_BuyLimitTicket= OrderTicket();_BuyLimitLots=NormalizeDouble(OrderLots(),1);_BuyLimitOpenPrice=NormalizeDouble(OrderOpenPrice(),Digits);_ BuyLimitStopLoss=NormalizeDouble(OrderStopLoss(),Digits);_BuyLimitTakeProfit=NormalizeDouble(OrderTakeProfit(),Digits);_ BuyLimitOpenTime=OrderOpenTime();_BuyLimitComment=OrderComment();_BuyLimitExpiration=OrderExpiration();break;caseOP_SELLLIMIT:_ SellLimitTicket=OrderTicket();_SellLimitLots=NormalizeDouble(OrderLots(),1);_SellLimitOpenPrice=NormalizeDouble(OrderOpenPrice(), Digits);_SellLimitStopLoss=NormalizeDouble(OrderStopLoss(),Digits);_SellLimitTakeProfit=NormalizeDouble(OrderTakeProfit(),Digits); _SellLimitOpenTime=OrderOpenTime();_SellLimitComment=OrderComment();_SellLimitExpiration=OrderExpiration();break;}}}} Now we use the function to smart trading program:externint_MagicNumber=1123;externdoubleLot=0.1;externintStopLoss=60; //spacing of stop loss points (0-d none)externintTakeProfit=100; //spacing of win points (0-none)externintTrailingStop=50; //trailing stop (0-none)externintLuft=20; //spacing of pending trade placement levels#include<OneTypeOrdersControl.mq4> intstart(){int_GetLastError=0;//---- remember the parameters of the open position (if available) OneTypeOrdersInit(_MagicNumber);//---- if we are both pending order transactions, exit //---- wait for them to open if(_ BuyStopTicket>0&&_SellStopTicket>0)return(0);//---- if BUY position is open if(_BuyTicket>0){/---- if SellStop hasnt been deleted, delete it:if(_ SellStopTicket>0){if(!OrderDelete(_SellStopTicket)){Alert(OrderDelete error#,GetLastError());return(-1);}//---- detect stop loss is moved://---- if trailing stop loss is not very small,if(TrailingStop>MarketInfo(Symbol(), MODE_STOPLEVEL ){//---- if the winning position exceeds the trailing stop, if(NormalizeDouble(Bid-_ BuyOpenPrice,Digits)>NormalizeDouble(TrailingStop*Point,Digits)){//---- if the new stop level exceeds the current position//---- (or the current position has no stop),if(NormalizeDouble(Bid- TrailingStop*Point, Digits )>_BuyStopLoss|| _BuyStopLoss<=0.0){//---- modify the order if(!OrderModify(_BuyTicket,_ BuyOpenPrice,NormalizeDouble(Bid-TrailingStop*Point,Digits),_BuyTakeProfit,0)){Alert(OrderModify error#, GetLastError());return(- 1);}}}}//---- if there is no open position, exit, nothing to do return(0);}//---- this cell is similar to the cell of BUY position //---- this is the reason we can not do labeling . .if(_SellTicket>0){if(_BuyStopTicket>0){if(!OrderDelete(_BuyStopTicket)){Alert(OrderDelete error#,GetLastError());return(-1);}} if(TrailingStop>MarketInfo(Symbol(),MODE_STOPLEVEL)){if(NormalizeDouble(_SellOpenPrice-Ask,Digits)>NormalizeDouble( TrailingStop*Point,Digits)){if(NormalizeDouble(Ask+TrailingStop*Point, Digits )<_SellStopLoss|| _SellStopLoss< ;=0.0){if(!OrderModify(_SellTicket,_SellOpenPrice,NormalizeDouble(Ask+TrailingStop*Point, Digits ),_SellTakeProfit,0)){ Alert(OrderModifyError#, GetLastError());return(-1);}}}}return(0);}5. Summary Finally, I would like to compare the speed of using the function with or without in the search for orders For this reason, we use the same version to test the Everytick mode 10 times in a row The results of our own calculations when using the MetaTrader software to calculate the time and time are as follows: Smart Trading 10 tested times (mm:ss) CrossMACD_beta (without the function) 07:42CrossMACD11:37DoublePending_beta (without the function) 08:18 Contains function)08:18DoublePending09:42As you can see in your table, the smart trading program using functions is slightly slower, which should be reasonable as a price to pay for making the source code easy to understand anyway, everyone has the freedom to use functions or not