#property strict #include CAppDialog OurInterface; #include CEdit LotSize,TPBUY,SLBUY,TPSELL,SLSELL,STARTDIFF; #include CLabel LotLabel,TPBUYLabel,SLBUYLabel,TPSELLLabel,SLSELLLabel,STARTDIFFLabel; double TradeVolume = 1; double sls = 200; // 200 double tps = 50; // 50 best double slb = 300; // 300 best double tpb = 200; // 200 best double tsl= 0; double sd= 25; // 25 best int start_hour = 3; int start_min = 0; int end_hour = 4; int end_min = 05; int second_start_hour = 18; // 18 is best int second_start_min = 0; int second_end_hour = 22; // 22:30 is best int second_end_min = 30; string OK_TO_TRADE= "NG"; string SymbolOrder="CHINA50"; double MaxAccountBalance = AccountBalance(); double MinAccountBalance = 1000000; double InitialAccountBalance = AccountBalance(); const string LotName = "Lot_Volume"; const string TPBUY_Value = "TPBUY_Value"; const string SLBUY_Value = "SLBJY_Value"; const string TPSELL_Value = "TPSELL_Value"; const string SLSELL_Value = "SLSELL_Value"; const string STARTDIFF_Value = "STARTDIFF_Value"; int OnInit() { ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); OurInterface.Create(0,"China50 Trading v2.0",0,180,70,400,300); LotLabel.Create(0,"LotLabel",0,10,10,50,30); OurInterface.Add(LotLabel); LotLabel.Text("Lot Size:"); LotSize.Create(0,LotName,0,90,10,160,30); OurInterface.Add(LotSize); LotSize.Text(string(TradeVolume)); TPBUYLabel.Create(0,"TPBUYLabel",0,10,40,50,60); OurInterface.Add(TPBUYLabel); TPBUYLabel.Text("TP BUY:"); TPBUY.Create(0,TPBUY_Value,0,90,40,160,60); OurInterface.Add(TPBUY); TPBUY.Text(string(tpb)); SLBUYLabel.Create(0,"SLBUYLabel",0,10,70,50,90); OurInterface.Add(SLBUYLabel); SLBUYLabel.Text("SL BUY:"); SLBUY.Create(0,SLBUY_Value,0,90,70,160,90); OurInterface.Add(SLBUY); SLBUY.Text(string(slb)); TPSELLLabel.Create(0,"TPSELLLabel",0,10,100,50,120); OurInterface.Add(TPSELLLabel); TPSELLLabel.Text("TP SELL:"); TPSELL.Create(0,TPSELL_Value,0,90,100,160,120); OurInterface.Add(TPSELL); TPSELL.Text(string(tps)); SLSELLLabel.Create(0,"SLSELLLabel",0,10,130,50,150); OurInterface.Add(SLSELLLabel); SLSELLLabel.Text("SL SELL:"); SLSELL.Create(0,SLSELL_Value,0,90,130,160,150); OurInterface.Add(SLSELL); SLSELL.Text(string(sls)); STARTDIFFLabel.Create(0,"STARTDIFFLabel",0,10,160,50,180); OurInterface.Add(STARTDIFFLabel); STARTDIFFLabel.Text("ST_DIFF:"); STARTDIFF.Create(0,STARTDIFF_Value,0,90,160,160,180); OurInterface.Add(STARTDIFF); STARTDIFF.Text(string(sd)); OurInterface.Run(); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { EventKillTimer(); // Kill the timer OurInterface.Destroy(reason); } void OnTick() { int MagicBuy =1000; int MagicSell = 2000; int Date = Day(); MagicBuy = MagicBuy+Date; MagicSell = MagicSell+Date; datetime Today = StrToTime(StringConcatenate(Year(), ".", Month(), ".", Day())); datetime start_time = Today+start_hour*3600+start_min*60; datetime end_time = Today+end_hour*3600+end_min*60; datetime second_start_time = Today+second_start_hour*3600+second_start_min*60; datetime second_end_time = Today+second_end_hour*3600+second_end_min*60; if ((TimeCurrent()>start_time && TimeCurrent()second_start_time && TimeCurrent()sd) { double buy = price; double slbuy = buy-slb; //buy-previousclose; double tpbuy = buy+tpb; int orderbuy = OrderSend (SymbolOrder,OP_BUY,TradeVolume,buy,0,slbuy,tpbuy,NULL,MagicBuy,0,clrBlue); } } if (OK_TO_TRADE=="OK" && CheckSellOpenOrders(MagicSell)==false) { double price = NormalizeDouble(MarketInfo(SymbolOrder,MODE_BID),4); if (previousclose-previousopen>sd) { double sell = price; double slsell = sell+sls; // sell+previousclose; double tpsell = sell-tps; int ordersell = OrderSend (SymbolOrder,OP_SELL,TradeVolume,sell,0,slsell,tpsell,NULL,MagicSell,0,clrBlue); } } double CurrentAccountBalance = AccountBalance(); if (MaxAccountBalance < AccountBalance()) MaxAccountBalance = AccountBalance(); if (MinAccountBalance > AccountBalance()) MinAccountBalance = AccountBalance(); Comment ("Initial Account Balance was ",InitialAccountBalance,", Minimum Balance was ",MinAccountBalance,", Max Balance was ",MaxAccountBalance,", Current Balance is ",CurrentAccountBalance," and Current Equity is ",AccountEquity(), ""); } // End of On Tick // Start of Event Handling void OnChartEvent (const int id,const long &lparam,const double &dparam,const string &sparam) { OurInterface.OnEvent(id,lparam,dparam, sparam); if (id == CHARTEVENT_OBJECT_ENDEDIT){ if(sparam == LotName) { string volumeText = ObjectGetString(0, LotName, OBJPROP_TEXT); TradeVolume = StringToDouble(volumeText); ObjectSetString(0, LotName, OBJPROP_TEXT, string(TradeVolume)); return; } if(sparam == TPBUY_Value) { string volumeText = ObjectGetString(0, TPBUY_Value, OBJPROP_TEXT); tpb = StringToDouble(volumeText); ObjectSetString(0, TPBUY_Value, OBJPROP_TEXT, string(tpb)); return; } if(sparam == SLBUY_Value) { string volumeText = ObjectGetString(0, SLBUY_Value, OBJPROP_TEXT); slb = StringToDouble(volumeText); ObjectSetString(0, SLBUY_Value, OBJPROP_TEXT, string(slb)); return; } if(sparam == TPSELL_Value) { string volumeText = ObjectGetString(0, TPSELL_Value, OBJPROP_TEXT); tps = StringToDouble(volumeText); ObjectSetString(0, TPSELL_Value, OBJPROP_TEXT, string(tps)); return; } if(sparam == SLSELL_Value) { string volumeText = ObjectGetString(0, SLSELL_Value, OBJPROP_TEXT); sls = StringToDouble(volumeText); ObjectSetString(0, SLSELL_Value, OBJPROP_TEXT, string(sls)); return; } if(sparam == STARTDIFF_Value) { string volumeText = ObjectGetString(0, STARTDIFF_Value, OBJPROP_TEXT); sd = StringToDouble(volumeText); ObjectSetString(0, STARTDIFF_Value, OBJPROP_TEXT, string(sd)); return; } } // End of CHARTEVENT_OBJECT_ENDEDIT // if an object was clicked } // End of Event Handling bool CheckBuyOpenOrders(int MagicBuy){ // We need to scan all the open and pending orders to see if there are any. // OrdersTotal returns the total number of market and pending orders. // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running. for( int i = 0 ; i < OrdersTotal() ; i++ ) { // We select the order of index i selecting by position and from the pool of market/pending trades. int OrderBO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); // If the pair of the order is equal to the pair where the EA is running. if(OrderType()==OP_BUY && OrderMagicNumber()==MagicBuy) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); } bool CheckSellOpenOrders(int MagicSell){ // We need to scan all the open and pending orders to see if there are any. // OrdersTotal returns the total number of market and pending orders. // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running. for( int i = 0 ; i < OrdersTotal() ; i++ ) { // We select the order of index i selecting by position and from the pool of market/pending trades. int OrderSO = OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); // If the pair of the order is equal to the pair where the EA is running. if(OrderType()==OP_SELL && OrderMagicNumber()==MagicSell) return(true); } // If the loop finishes it mean there were no open orders for that pair. return(false); }