السلام عليكم
قومت بعمل التعديل هذا:
وهذا هو الكود كامل:
ولكنه لا يدخل صفقات!
قومت بعمل التعديل هذا:
كود HTML:
double InpOrderSizeBxx = (Amount_of_money/(((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*10000))/10; double InpOrderSizeSxx = (Amount_of_money/(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*10000))/10; double InpOrderSizeBx=InpOrderSizeBxx; Print("InpOrderSizeBx = ",DoubleToString(InpOrderSizeBx,16)); double InpOrderSizeB=NormalizeDouble(InpOrderSizeBxx,0); Print("NormalizeDouble(InpOrderSizeBx,0) = ",DoubleToString(InpOrderSizeB,16)); double InpOrderSizeSx=InpOrderSizeSxx; Print("InpOrderSizeSx = ",DoubleToString(InpOrderSizeSx,16)); double InpOrderSizeS=NormalizeDouble(InpOrderSizeSxx,0); Print("NormalizeDouble(InpOrderSizeSx,0) = ",DoubleToString(InpOrderSizeS,16)); Trade.PositionOpen(Symbol(), ORDER_TYPE_BUY, InpOrderSizeB, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment); Trade.PositionOpen(Symbol(), ORDER_TYPE_SELL, InpOrderSizeS, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment); return((int)Trade.ResultOrder()); }
كود HTML:
input int InpTakeProfitPts = 0; input int InpStopLossPts = 0; input double Amount_of_money = 100; // // Standard inputs // input string InpTradeComment = __FILE__; // Trade comment input int InpMagicNumber = 2000001; // Magic number input int Range=121; input double Goal=6; double TakeProfit; double StopLoss; bool CloseOpposite; const string IndicatorName="TEST"; const int Handle_Buy = 0; const int Handle_Sell = 1; int Handle; double BufferBuy[3]; double BufferSell[3]; datetime lastTime = 0; // // Use CTrade, easier than doing our own coding // #include <Trade\Trade.mqh> CTrade *Trade; int OnInit() { // // Create a pointer to a ctrade object // Trade = new CTrade(); Trade.SetExpertMagicNumber(InpMagicNumber); Handle=iCustom(Symbol(),Period(),IndicatorName); if(Handle==INVALID_HANDLE) { PrintFormat("Failed",GetLastError()); return(INIT_FAILED); } return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { IndicatorRelease(Handle); } void OnTick() { int cnt_B = CopyBuffer(Handle,Handle_Buy,0,3,BufferBuy); int cnt_S = CopyBuffer(Handle,Handle_Sell,0,3,BufferSell); double Previous_Candle_Buy = BufferBuy[1]; double Current_Candle_Buy = BufferBuy[0]; double Previous_Candle_Sell = BufferSell[1]; double Current_Candle_Sell = BufferSell[0]; bool buyCondition = false; bool sellCondition = false; if(lastTime != iTime(Symbol(), 0, 1)) { lastTime = iTime(Symbol(), 0, 1); } else { return; } if( Previous_Candle_Buy ==iLow(_Symbol, PERIOD_CURRENT,1)) { buyCondition = true;} if( Previous_Candle_Sell ==iHigh(_Symbol, PERIOD_CURRENT,1)) { sellCondition = true;} double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT); TakeProfit = InpTakeProfitPts * point; StopLoss = InpStopLossPts * point; CloseOpposite = false; if (buyCondition) { if (CloseOpposite) CloseAll(POSITION_TYPE_SELL); OrderOpen(ORDER_TYPE_BUY, StopLoss, TakeProfit); } else if (sellCondition) { if (CloseOpposite) CloseAll(POSITION_TYPE_BUY); OrderOpen(ORDER_TYPE_SELL, StopLoss, TakeProfit); } // // Save any information for next time // return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double Highest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0) { double highest=0; double High[]; ArraySetAsSeries(High,true); int copied=CopyHigh(symbol,timeframe,start,count,High) ; int index=ArrayMaximum(High,0,count)+start; if(copied>0 && index<copied) highest=High[index]; return(highest); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double Lowest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0) { double lowest=0; double Low[]; ArraySetAsSeries(Low,true); int copied=CopyLow(symbol,timeframe,start,count,Low); int index=ArrayMinimum(Low,0,count)+start; if(copied>0 && index<copied) lowest=Low[index]; return(lowest); } // // true/false has the bar changed // bool NewBar() { static datetime priorTime = 0; datetime currentTime = iTime(Symbol(), Period(), 0); bool result = (currentTime!=priorTime); priorTime = currentTime; return(result); } // // Close all trades of the specified type - for strategies that call for closing the opposite side // void CloseAll(ENUM_POSITION_TYPE positionType) { int cnt = PositionsTotal(); for (int i = cnt-1; i>=0; i--) { ulong ticket = PositionGetTicket(i); if (ticket>0) { if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==InpMagicNumber && PositionGetInteger(POSITION_TYPE)==positionType) { Trade.PositionClose(ticket); } } } } // // Simple function to open a new order // int OrderOpen(ENUM_ORDER_TYPE orderType, double stopLoss, double takeProfit) { double openPrice; double stopLossPrice; double takeProfitPrice; // // Calculate the open price, take profit and stop loss prices ****d on the order type // if (orderType==ORDER_TYPE_BUY) { openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_ASK), Digits()); stopLossPrice = ((Lowest(Symbol() , _Period, Range, 0))); takeProfitPrice =((((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*Goal)+(Lowest(Symbol() , _Period, Range, 0))); } else if (orderType==ORDER_TYPE_SELL) { openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_BID), Digits()); stopLossPrice = ((Highest(Symbol() , _Period, Range, 0))); takeProfitPrice =((Highest(Symbol() , _Period, Range, 0))-(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*Goal)); } else { // This function only works with type buy or sell return(-1); } double InpOrderSizeBxx = (Amount_of_money/(((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*10000))/10; double InpOrderSizeSxx = (Amount_of_money/(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*10000))/10; double InpOrderSizeBx=InpOrderSizeBxx; Print("InpOrderSizeBx = ",DoubleToString(InpOrderSizeBx,16)); double InpOrderSizeB=NormalizeDouble(InpOrderSizeBxx,0); Print("NormalizeDouble(InpOrderSizeBx,0) = ",DoubleToString(InpOrderSizeB,16)); double InpOrderSizeSx=InpOrderSizeSxx; Print("InpOrderSizeSx = ",DoubleToString(InpOrderSizeSx,16)); double InpOrderSizeS=NormalizeDouble(InpOrderSizeSxx,0); Print("NormalizeDouble(InpOrderSizeSx,0) = ",DoubleToString(InpOrderSizeS,16)); Trade.PositionOpen(Symbol(), ORDER_TYPE_BUY, InpOrderSizeB, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment); Trade.PositionOpen(Symbol(), ORDER_TYPE_SELL, InpOrderSizeS, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment); return((int)Trade.ResultOrder()); }
تعليق