Library Coding
Kumpulan contoh script dan logika penulisan coding C++
Thursday, September 10, 2015
Kumpulan Contoh Logic
Contoh EA Close Open Posisi by Indikator MA
Keterangan
//+------------------------------------------------------------------+ //| EAServant1.1.mq4 | //| Dwi Malistyo ea@dwim.web.id | //| http://ea.dwim.web.id | //+------------------------------------------------------------------+ #property copyright "Dwi Malistyo ea@dwim.web.id" #property link "http://ea.dwim.web.id" #define CLOSEBUY 8 #define CLOSESELL 9 // EA Servant 1.0 // Running on all Pair and all Time Frame // - Put SL 50 pips and TP 100 pips automaticaly for every Manual Order // - Lock profit +1 at 25 pip. // EA Servant 1.1 // - Error Message // - Trailing Stop // - Ready for 5 Digits Broker extern int TakeProfit = 100; extern int StopLoss = 50; extern int LockProfit = 25; string Text[4]; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- // Check, if there is human error. When someone put StopLoss below than StopLevel. if (StopLoss
MA) signal=CLOSESELL; for(iTrade=0; iTrade
55) { Text[2]="Daily Trend : Uptrend";} else { Text[2]="Daily Trend : Sideways";} //Comment("StopLevel : ",MarketInfo(Symbol(),MODE_STOPLEVEL)); ObjectCreate("ObjLabel1", OBJ_LABEL, 0, 0, 0); ObjectSet("ObjLabel1", OBJPROP_CORNER, 1); ObjectSet("ObjLabel1", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel1", OBJPROP_YDISTANCE, 15); ObjectSetText("ObjLabel1", Text[0], 7, "Arial",SteelBlue); ObjectCreate("ObjLabel2", OBJ_LABEL, 0, 0, 0); ObjectSet("ObjLabel2", OBJPROP_CORNER, 1); ObjectSet("ObjLabel2", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel2", OBJPROP_YDISTANCE, 25); ObjectSetText("ObjLabel2", Text[1], 7, "Arial",SteelBlue); ObjectCreate("ObjLabel3", OBJ_LABEL, 0, 0, 0); ObjectSet("ObjLabel3", OBJPROP_CORNER, 1); ObjectSet("ObjLabel3", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel3", OBJPROP_YDISTANCE, 35); ObjectSetText("ObjLabel3", Text[2], 7, "Arial",Red); ObjectCreate("ObjLabel4", OBJ_LABEL, 0, 0, 0); ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); if (Digits==2 || Digits==4) // for broker 4 Digits { for(iTrade=0; iTrade
LockProfit*Point) { // Yes, move the SL. Lock the profit +1 if(OrderStopLoss()<=OrderOpenPrice()) { if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+1*Point,OrderTakeProfit(),0)==true) { Text[3]="Modify SL at trade BUY no: #"+OrderTicket(); } else { Text[3]="ERROR -- Modifying SL at trade BUY no: #"+OrderTicket(); } ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } else { // Trailing BUY if(Bid-OrderStopLoss()>LockProfit*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-LockProfit*Point,OrderTakeProfit(),0); //Alert(Bid-OrderStopLoss()," ",LockProfit*Point," ",Bid-LockProfit*Point); //Tambah fungsi GetLassError() } Text[3]="Trailing SL trade no: #"+OrderTicket(); ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } } } } else { // Coding for SELL condition if (OrderStopLoss()==0 && OrderTakeProfit()==0) { // If SL && TP ==0, Then Setup SL && TP now if(OrderModify(OrderTicket(),OrderOpenPrice(),Ask+StopLoss*Point,Bid-TakeProfit*Point,0)==true) { Text[3]="Put SL and TP at trade SELL no: #"+OrderTicket(); } else { Text[3]="ERROR -- Put SL and TP at trade SELL no: #"+OrderTicket(); } ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } else { // Check if profit ? Is it possible to move the Stop Loss ? if (OrderOpenPrice()-Ask>LockProfit*Point) { // Yes, move the SL. Lock the profit +1 if(OrderStopLoss()>=OrderOpenPrice()) { if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-1*Point,OrderTakeProfit(),0)==true) { Text[3]="Modify SL at trade SELL no: #"+OrderTicket(); } else { Text[3]="ERROR -- Modifying SL at trade SELL no: #"+OrderTicket(); } ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } else { // Trailing SELL if(OrderStopLoss()-Ask>LockProfit*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+LockProfit*Point,OrderTakeProfit(),0); //Alert(OrderStopLoss()-Ask," ",LockProfit*Point," ",Ask+LockProfit*Point); //Tambah fungsi GetLassError() } Text[3]="Trailing SL at trade no: #"+OrderTicket(); ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } } } } } } else if (Digits==3 || Digits==5) // for broker 5 Digits { for(iTrade=0; iTrade
LockProfit*Point*10) { // Yes, move the SL. Lock the profit +1 if(OrderStopLoss()<=OrderOpenPrice()) { if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+1*Point*10,OrderTakeProfit(),0)==true) { Text[3]="Modify SL at trade BUY no: #"+OrderTicket(); } else { Text[3]="ERROR -- Modifying SL at trade BUY no: #"+OrderTicket(); } ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } else { // Trailing BUY if(Bid-OrderStopLoss()>LockProfit*Point*10) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-LockProfit*Point*10,OrderTakeProfit(),0); //Alert(Bid-OrderStopLoss()," ",LockProfit*Point," ",Bid-LockProfit*Point); //Tambah fungsi GetLassError() } Text[3]="Trailing SL trade no: #"+OrderTicket(); ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } } } } else { // Coding for SELL condition if (OrderStopLoss()==0 && OrderTakeProfit()==0) { // If SL && TP ==0, Then Setup SL && TP now if(OrderModify(OrderTicket(),OrderOpenPrice(),Ask+StopLoss*Point*10,Bid-TakeProfit*Point*10,0)==true) { Text[3]="Put SL and TP at trade SELL no: #"+OrderTicket(); } else { Text[3]="ERROR -- Put SL and TP at trade SELL no: #"+OrderTicket(); } ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } else { // Check if profit ? Is it possible to move the Stop Loss ? if (OrderOpenPrice()-Ask>LockProfit*Point*10) { // Yes, move the SL. Lock the profit +1 if(OrderStopLoss()>=OrderOpenPrice()) { if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-1*Point*10,OrderTakeProfit(),0)==true) { Text[3]="Modify SL at trade SELL no: #"+OrderTicket(); } else { Text[3]="ERROR -- Modifying SL at trade SELL no: #"+OrderTicket(); } ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } else { // Trailing SELL if(OrderStopLoss()-Ask>LockProfit*Point*10) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+LockProfit*Point*10,OrderTakeProfit(),0); //Alert(OrderStopLoss()-Ask," ",LockProfit*Point," ",Ask+LockProfit*Point); //Tambah fungsi GetLassError() } Text[3]="Trailing SL at trade no: #"+OrderTicket(); ObjectSet("ObjLabel4", OBJPROP_CORNER, 1); ObjectSet("ObjLabel4", OBJPROP_XDISTANCE, 10); ObjectSet("ObjLabel4", OBJPROP_YDISTANCE, 45); ObjectSetText("ObjLabel4", Text[3], 7, "Arial",Yellow); } } } } } } //---- return(0); } //+------------------------------------------------------------------+
Catatan
0 comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
"Join Us on Facebook!
"Join Us on Facebook!
"Join Us on Facebook!
Contact
DAFTAR ISI :
Powered by
Blogger
.
Latest Tweets
;
0 comments:
Post a Comment