ใครมี Facebook ก็สามารถ add มาคุยกับ admin ได้แล้วนะครับ
extern double Pivot = 0;extern int Openrange = 50;extern int sl = 100;extern double Lots = 0.1;extern int TrailingStop = 0;extern int magicno = 1801; int LastBar,LastDay=0,MaxOrder=2;double Pivots,buystop,sellstop;bool buy,sell;//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init(){//---- start(); //---- return(0);}//+------------------------------------------------------------------+//| expert deinitialization function |//+------------------------------------------------------------------+int deinit() {//---- ObjectsDeleteAll(0,EMPTY);//---- return(0); } //+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start(){ int tp= OrdersHistoryTotal()*sl+20; int total; int ticket;int cBuy = CountOrder(OP_BUY),cBuys = CountOrder(OP_BUYSTOP),cSell = CountOrder(OP_SELL),cSells = CountOrder(OP_SELLSTOP);int AllBuy = cBuy+cBuys;int AllSell = cSell+cSells;int OpenAll = cBuy+cSell;int PandingAll = cBuys+cSells;int OrderAll = AllBuy+AllSell; if(OrderAll==0){ if(Pivot==0){ buystop=Ask+(Openrange*Point); sellstop=Bid-(Openrange*Point); Pivots = Bid; }else{ buystop=Pivot+(Openrange*Point); sellstop=Pivot-(Openrange*Point); Pivots = Pivot; } //Buy// if(Ask<buystop){ ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,buystop,3,buystop-Point*sl,buystop+Point*tp,"EABuy",magicno,0,Blue); OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); } //Sell// if(Bid>sellstop){ ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,sellstop,3,sellstop+Point*sl,sellstop-Point*tp,"EASell ",magicno,0,Red); OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); } }else{ if(OpenAll>=1){ if(TrailingStop>0)TrailingStop(); if(PandingAll<=1)CloseOrderAll(); } } return(0) ;}//+------------------------------------------------------------------+//| Calculate open positions |//+------------------------------------------------------------------+int CountOrder(int type){ int cn=0;//---- for(int i=0;i<OrdersTotal();i++){ if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; if((OrderSymbol()==Symbol()) && (OrderMagicNumber()==magicno)){ if(OrderType()==type) cn++; } }//---- return orders volume return(cn);}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////void TrailingStop(){ double Trailing,point=MarketInfo(Symbol(),MODE_POINT); int magic,i,OrdersTotals=OrdersTotal(); Trailing = TrailingStop * point;//(TrailingStop + Spread) * point; for(i = 0; i < OrdersTotals; i++){ if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(magicno==OrderMagicNumber()){ if(OrderType() == OP_BUY){ if((Bid - OrderOpenPrice()) > Trailing){ if(OrderStopLoss() < (Bid - Trailing) || (OrderStopLoss()==0)){ OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Trailing, OrderTakeProfit(), Yellow); } } }else if(OrderType() == OP_SELL){ if((OrderOpenPrice() - Ask) > Trailing){ if((OrderStopLoss() > (Ask + Trailing)) || (OrderStopLoss()==0)){ OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Trailing, OrderTakeProfit(), Yellow); } } } } } return(0);}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void CloseOrderAll(){ int i,type,OrdersTotals=OrdersTotal(); for(i=OrdersTotals;i>=0;i--){ if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if((OrderSymbol()==Symbol()) && (OrderMagicNumber()==magicno)){ type = OrderType(); //if(type==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Bid,3,Yellow); //if(type==OP_SELL)OrderClose(OrderTicket(),OrderLots(),Ask,3,Yellow); if(type!=OP_SELL && type!=OP_BUY)OrderDelete(OrderTicket()); } } return(0);}
ยิ่งเปิดปิดมากๆๆ TP จะไกลขึ้นอยู่แล้วครับมาจากตรงนี้int tp= OrdersHistoryTotal()*sl+20;จาก code มันคือการเอาจำนวน Order ที่ถูกปิดไปแล้วคุณค่า Sl + อีก 20ตัวอย่างถ้าไม่มี Order ที่ถูกปิดในบัญชีเลยค่า TP = 0*100+20 = 20ถ้าถูกปิดไป 1 Order จะเท่ากับTP = 1*100+20 =120ถ้าถูกปิดไป 2 Order จะเท่ากับTP = 2*100+20 =220
int temp=0; for(int x=OrdersHistoryTotal()-1,x>=0,x--) { OrderSelect(x,SELECT_BY_POS,MODE_HISTORY); if(OrderProfit()<0) temp++; if(OrderProfit>0) x=-1; }int tp= temp*5;