//+------------------------------------------------------------------+ //| RoNz Rapid-Fire EA.mq4| //| Copyright 2014, Rony Nofrianto | //| | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, Rony Nofrianto" #property link "" #property version "1.01" #property strict // v1.03 // + Fixed not closing order on trend close option // + Added Lot Risk Option // + Fixed Lot Minimum/Maximum/Step #define MAGICMA 19841129 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_LOTTYPE { LOTS_FIXED=0,//Fixed Lots LOTS_MAXRISK=1,//Risk Based Lots LOTS_DECREASE=2, //Decrease Lots When Loss LOTS_INCREASE=3, //Increase Lots When Loss }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_CLOSETYPE { SL_Close=0,TrendClose=1 }; input double inpLots=0.01;//Lots extern ENUM_LOTTYPE inpLotsMode=LOTS_MAXRISK;//Lots Type input double inpMaximumLotRisk =0.02; input double DecreaseFactor=1; input int StopLoss=150; input int TakeProfit=100; input int TrailingStop=0; input bool Averaging=false; //Use Averaging input int MAPeriod=60; input double PSARStep=0.02; input double PSARMax=0.2; input ENUM_CLOSETYPE CloseType=SL_Close; //Close Type sinput ENUM_APPLIED_PRICE AppliedPrice=PRICE_CLOSE; sinput ENUM_MA_METHOD Method=MODE_SMA; double InitialBalance=0; string LotType=""; int PipRisk=1000; int inpLotsFactor=1; //+------------------------------------------------------------------+ //| Hitung Posisi Buka | //+------------------------------------------------------------------+ int CalculateCurrentOrders() { int TotalOrder=0; //--- for(int i=0;i0) { for(int i=OrdersHistoryTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; } if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MAGICMA || OrderType()>OP_SELL) continue; if(OrderProfit()>0) break; if(OrderProfit()<0) losses++; } if(inpLotsMode==LOTS_DECREASE) { LotType="Dec. Loss"; if(losses>1) lot=NormalizeDouble(lot-(lot*losses/inpLotsFactor),2); } if(inpLotsMode==LOTS_INCREASE) { LotType="Inc. Loss"; if(losses>1) lot=NormalizeDouble(lot+(lot*losses/inpLotsFactor),2); } } lot=MathFloor(lot/LotStep)*MathMod(LotStep,lot); if(lotiMa) && SARClose[0]; bool iRZI_Sell=(Close[0]Close[0] && pSAR0) dStopLoss=NormalizeDouble(Bid-(minstoplevel+SL)*Point,Digits()); if(TP>0) dTakeProfit=NormalizeDouble(Bid+(minstoplevel+TP)*Point,Digits()); string PriceControlInfo=StringConcatenate("T/P = ",dTakeProfit," S/L = ",dStopLoss); comments=StringConcatenate("RZ: ",comments); Print("Mulai Beli : ",SymbolInfo()); if(!OrderSend(Symbol(),OP_BUY,lots,Ask,3,dStopLoss,dTakeProfit,comments,MAGICMA,0,Blue)) return 0; else { Print("Beli : Ask = ",Ask," ",PriceControlInfo); return 1; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool TrailStop(int TiketOrder,int JumlahPoin) { if(OrderSelect(TiketOrder,SELECT_BY_TICKET,MODE_TRADES)==false) return false; //Hindari Kekurangan Profit yang didapat if(JumlahPoin>0) { int minstoplevel=(int)MarketInfo(Symbol(),MODE_STOPLEVEL); JumlahPoin=JumlahPoin+minstoplevel; if((OrderType()==OP_BUY) && (Bid-OrderOpenPrice()>Point*JumlahPoin)) { if(OrderStopLoss()Point*JumlahPoin)) { if(OrderStopLoss()>Ask+Point*JumlahPoin) { Print("SellTrailingStop: ",NormalizeDouble(Ask+Point*JumlahPoin,Digits())); bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*JumlahPoin,Digits),OrderTakeProfit(),0,Blue); if(res == true) return true; else return false; } } } return false; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckForOpen() { RefreshRates(); int Trend=AnalisaTrend("Analisa Open",-1); if(Trend>=3) { Beli(OptimalLots(),StopLoss,TakeProfit,IntegerToString(Trend)); } else if(Trend<=-3) { Jual(OptimalLots(),StopLoss,TakeProfit,IntegerToString(Trend)); } //--- } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckForAveraging() { if(!Averaging) return; int Trend=AnalisaTrend("Analisa Open",-1); if(Trend>=2) { Beli(OptimalLots(),StopLoss,TakeProfit,IntegerToString(Trend)); } else if(Trend<=-2) { Jual(OptimalLots(),StopLoss,TakeProfit,IntegerToString(Trend)); } //--- } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { RefreshRates(); int Trend=0; //--- for(int i=0;i ",OrderClosePrice(), " Profit : ",OrderProfit()); Trend=AnalisaTrend("Analisa Close "+(string)OrderType(),OrderType()); if(OrderType()==OP_BUY && Trend==1) { Print(msgClose); if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue)) Print("Close Buy Error ",GetLastError()); } if(OrderType()==OP_SELL && Trend==-1) { Print(msgClose); if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Red)) Print("Sell Close Error ",GetLastError()); } TrailStop(i,TrailingStop); } //--- } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnInit() { InitialBalance=AccountBalance(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(Bars<100 || IsTradeAllowed()==false) return; if(CalculateCurrentOrders()==0) CheckForOpen(); CheckForAveraging(); if(CalculateCurrentOrders()!=0) CheckForClose(); //--- } //+------------------------------------------------------------------+