//+------------------------------------------------------------------+ //| Ikut Trend EA | //| Copyright © 2025, Dewa Trader | //+------------------------------------------------------------------+ //#property version "1.0" #property copyright "Copyright © 2025, Dewa Trader" #property link "https://dewatrader.biz" #property description "Versi Standard" //#property description "Fungsi anti rugi tertakluk kepada jumlah lot." //#property description "EA ini menggunakan OSMA indikator untuk menentukan Titik masuk dagangan." #property strict #define NL "\n" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum yes_no { yes=0, //yes no=1, //no }; enum mode_selection { mode_standard=0, //Standard mode_short=1, //Jangka pendek mode_long=2, // Jangka panjang mode_scalping=3, //Scalping mode_conservative=4, //Konservatif mode_followtrend=5, //Ikut trend mode_swing=6, //Swing trading mode_custom=7, //Custom }; input string Comment_EA = "== Tetapan EA =="; // Tetapan EA string ProductName="Ikut Trend EA"; extern string LicenseCode; // Kod Lesen input string User_Comment = ""; // Komen/Nota pengguna input color comment_color = clrDarkGray; // Warna Latar Panel Komen //input color comment_colorF= clrWhite; // Warna Tulisan input string Comment_1 = "== Sila Pilih Mod EA =="; // Pilih Mod EA extern mode_selection mode_input=0; //Standard string mode_selected="Standard"; input string Comment_2 = "== Untuk Mod Custom =="; // Untuk Mod Custom extern int fast_MA=13, //Jangka Pendek slow_MA=36, //Jangka Panjang signal_period = 9; //Jangkamasa Trend input string Comment_3 = "== Pengurusan Trade =="; // Pengurusan Trade extern int slip=2, //Gelincir ( Slippage in pips) max_deals=2, //Maksima Dagangan magic=1605; //Nombor kawalan extern yes_no losses=1; //Close losses extern double Lot=0.01; //Lot size string EAver="1"; //1=standard 2=pro string Licence_type="1 Akaun MT4"; int order_type=-1, ticket=-1; double osma0, osma1; double MarginPercent; bool isTrending; string MarketTrend; int OrdersBUY; int OrdersSELL; double BuyLots, SellLots, BuyProfit, SellProfit; int BarCount; int Current; bool EachTickMode = True; static uchar ExtBase64Encode[64]= { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', '0','1','2','3','4','5','6','7','8','9','+','/' }; static uchar ExtBase64Decode[256]= { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; int init() { string res_decrypt; //--- decode ---- string ProductCode;; string clientAccount; string EAexpire; string EAuserType; Base64Decode(LicenseCode,res_decrypt); string Reverse_license=decode_license(res_decrypt); string to_split=Reverse_license; // A string to split into substrings string sep="/"; // A separator as a character ushort u_sep; // The code of the separator character string result[]; //--- Get the separator code u_sep=StringGetCharacter(sep,0); //--- Split the string to substrings int k=StringSplit(to_split,u_sep,result); //--- Show a comment //PrintFormat("Strings obtained: %d. Used separator '%s' with the code %d",k,sep,u_sep); //--- Now output all obtained strings if(k>0) { for(int i=0;iStrToTime(EAexpire))//Has current date exceeded set date?If yes continue do alert, else skip and continue { MessageBox("License Expired" , ProductName, MB_OK | MB_ICONSTOP);// Alert user that license expired! ExpertRemove();//Remove adviser from chart return(INIT_FAILED);//Initiation failed due to exceeded date } //---Check Version Type and acc number if(EAuserType=="2" && EAver=="2")//is this pro account { return(INIT_SUCCEEDED);//Return successful initiation, continue using the adviser } //pro version check else { if(clientAccount!=IntegerToString(AccountNumber()))//check account number { MessageBox("Invalid User License!", ProductName, MB_OK | MB_ICONSTOP);// Alert user that license expired! ExpertRemove();//Remove adviser from chart return(INIT_FAILED);//Initiation failed due to exceeded date } } // standard account // end decode BarCount = Bars; if (EachTickMode) Current = 0; else Current = 1; return(0); } int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| OnTick function | //+------------------------------------------------------------------+ void OnTick() { if (EnumToString(mode_input)=="mode_standard") { fast_MA=12; //Jangka Pendek slow_MA=26; //Jangka Panjang signal_period = 9; //Jangkamasa Trend mode_selected="Standard"; } if (EnumToString(mode_input)=="mode_short") { fast_MA=5; //Jangka Pendek slow_MA=35; //Jangka Panjang signal_period = 5; //Jangkamasa Trend mode_selected="Janka Pendek"; } if (EnumToString(mode_input)=="mode_long") { fast_MA=19; //Jangka Pendek slow_MA=39; //Jangka Panjang signal_period = 9; //Jangkamasa Trend mode_selected="Janka Panjang"; } if (EnumToString(mode_input)=="mode_scalping") { fast_MA=3; //Jangka Pendek slow_MA=10; //Jangka Panjang signal_period = 16; //Jangkamasa Trend mode_selected="Scalping"; } if (EnumToString(mode_input)=="mode_conservative") { fast_MA=24; //Jangka Pendek slow_MA=52; //Jangka Panjang signal_period = 18; //Jangkamasa Trend mode_selected="Konservatif"; } if (EnumToString(mode_input)=="mode_followtrend") { fast_MA=7; //Jangka Pendek slow_MA=28; //Jangka Panjang signal_period = 7; //Jangkamasa Trend mode_selected="Ikut Trend"; } if (EnumToString(mode_input)=="mode_swing") { fast_MA=5; //Jangka Pendek slow_MA=15; //Jangka Panjang signal_period = 5; //Jangkamasa Trend mode_selected="Swing"; } if (EnumToString(mode_input)=="mode_custom") { mode_selected="Custom"; } osma0 = iOsMA(NULL, 0, fast_MA,slow_MA,signal_period,PRICE_CLOSE, Current + 0); osma1 = iOsMA(NULL, 0, fast_MA,slow_MA,signal_period,PRICE_CLOSE, Current + 1); isTrending=checkAtrStdTrending(NULL,0,21,21,0); if(ticket!=-1) CheckForCloseMA(); if(CountDeals()==0) CheckForOpen(); else { if(CountDeals() 0 && osma0 < 0 && order_type!=OP_SELL) { ticket=OrderSend(Symbol(),OP_SELL,Lot,Bid,slip,0,0,"",magic,0,Red); if(ticket==-1) return; if(!OrderSelect(ticket,SELECT_BY_TICKET)) {Print("Error during selection."); return;} else order_type=OrderType(); return; } //buy conditions if(osma1 < 0 && osma0 > 0 && order_type!=OP_BUY) { ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,slip,0,0,"",magic,0,Blue); if(ticket==-1) return; if(!OrderSelect(ticket,SELECT_BY_TICKET)) {Print("Error during selection."); return;} else order_type=OrderType(); return; } } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForCloseMA() { if(OrderSelect(ticket,SELECT_BY_TICKET)==false) return; if(OrderMagicNumber()!=magic || OrderSymbol()!=Symbol()) return; if(OrderType()==OP_BUY) { if(osma1 > 0 && osma0 < 0) { if(EnumToString(losses)=="yes") { if(!OrderClose(OrderTicket(),OrderLots(),Bid,slip,White)) Print("Error during order close."); } else { if(OrderProfit()>0) { if(!OrderClose(OrderTicket(),OrderLots(),Bid,slip,White)) Print("Error during order close."); } else { if(!OrderModify(ticket,OrderOpenPrice(),0,OrderOpenPrice()+MarketInfo(Symbol(),MODE_SPREAD)*Point,0)) Print("Error during order modify."); } } ticket=-1; } } if(OrderType()==OP_SELL) { if(osma1 < 0 && osma0 > 0) { if(EnumToString(losses)=="yes") { if(!OrderClose(OrderTicket(),OrderLots(),Ask,slip,White)) Print("Error during order close."); } else { if(OrderProfit()>0) { if(!OrderClose(OrderTicket(),OrderLots(),Ask,slip,White)) Print("Error during order close."); } else { if(!OrderModify(ticket,OrderOpenPrice(),0,OrderOpenPrice()-MarketInfo(Symbol(),MODE_SPREAD)*Point,0)) Print("Error during order modify."); } } ticket=-1; } } } //+------------------------------------------------------------------+ //| Count the deals | //+------------------------------------------------------------------+ int CountDeals() { int h=0; for(int i=0;i stdVal) return(false); //"RANGING"; else if (atrVal < stdVal) return(true); //"TRENDING"; else return(false); } //+------------------------------------------------------------------+ //| expert adxTrend function | //+------------------------------------------------------------------+ // function call: adxTrend(Symbol(),15,7,25) == "LONG"/"SHORT"/"FLAT" string adxTrend(string symbol, int tf, int adxPeriod, int adxTrigger) { string adxTrend = "RANGING"; double adxMain = iADX(symbol,tf,adxPeriod,PRICE_CLOSE,MODE_MAIN,0); double adxPlusDi = iADX(symbol,tf,adxPeriod,PRICE_CLOSE,MODE_PLUSDI,0); double adxMinusDi = iADX(symbol,tf,adxPeriod,PRICE_CLOSE,MODE_MINUSDI,0); if (adxMain > adxTrigger && adxPlusDi > adxMinusDi) adxTrend = "UP"; if (adxMain > adxTrigger && adxPlusDi < adxMinusDi) adxTrend = "DOWN"; return(adxTrend); } void drawFixedLbl(string objname, string s, int Corner, int DX, int DY, int FSize, string Font, color c, bool bg) { if (ObjectFind(objname) < 0) {ObjectCreate(objname, OBJ_LABEL, 0, 0, 0);} ObjectSet(objname, OBJPROP_CORNER, Corner); ObjectSet(objname, OBJPROP_XDISTANCE, DX); ObjectSet(objname, OBJPROP_YDISTANCE, DY); ObjectSet(objname,OBJPROP_BACK, bg); ObjectSetText(objname, s, FSize, Font, c); } void Base64Decode(string in,string &out) { int i=0,len=StringLen(in); int xshift=0,accum=0; while(i63) break; accum<<=6; xshift+=6; accum|=value; if(xshift>=8) { xshift-=8; value=accum>>xshift; out=out+CharToString((uchar)(value &0xFF)); } i++; } } string decode_license(string convert_this) { string new_code; //string symbol; string char_code; string this_char; for(int i = 0 ; i< StringLen(convert_this); i++){ this_char=StringSubstr(convert_this,i,1); char_code=get_strparam(this_char); //char_code=StringGetChar(get_ascparam(StringSubstr(convert_this,i,1)),0); new_code=new_code+char_code; } return(new_code); } string get_strparam(string this_character) { string new_character; //D'31.03.2025' if(this_character=="µ") { new_character="D"; } if(this_character=="é") { new_character="'"; } if(this_character=="~") { new_character="."; } if(this_character=="|") { new_character=" "; } if(this_character=="@") { new_character="/"; } if(this_character=="Y") { new_character="0"; } if(this_character=="£") { new_character="1"; } if(this_character=="s") { new_character="2"; } if(this_character=="}") { new_character="3"; } if(this_character=="©") { new_character="4"; } if(this_character=="R") { new_character="5"; } if(this_character=="G") { new_character="6"; } if(this_character=="o") { new_character="7"; } if(this_character=="=") { new_character="8"; } if(this_character=="N") { new_character="9"; } return(new_character); } void old_comment() { Comment( User_Comment, NL, " Market Trend: ",MarketTrend, NL, " Balance: ", AccountBalance(), NL, " Equity: ", AccountEquity(), NL, " Margin: ", NormalizeDouble(AccountMargin(),2), NL, " MarginPercent: ", MarginPercent, NL, // " Param: ", K_Period," ",D_Period," ",S_Period, NL, // " DEcode: ", LicenseCode, NL, " Current Time: ",TimeHour(CurTime()),":",TimeMinute(CurTime()),".",TimeSeconds(CurTime())); // Comment(" Last Update 09-Jan-2025 4:24pm", NL, // " Developed by: Dewa Trader", NL); }