#property strict // sell and buy limit set #include CAppDialog OurInterface; #include CEdit LotSize,TP,SL; #include CLabel LotLabel,TPLabel,SLLabel; double TradeVolume = 1; double sl = 500; double tp = 100; double tsl= 0; double sd= 80; int start_hour = 11; int start_min = 44; int end_hour = 11; int end_min = 55; 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; int cocoa_min_price = 8200; int cocoa_max_price = 11000; string OK_TO_TRADE= "NG"; string SymbolOrder="Cocoa_K5"; double MaxAccountBalance = AccountBalance(); double MinAccountBalance = 1000000; double InitialAccountBalance = AccountBalance(); const string LotName = "Lot_Volume"; const string TP_Value = "TP_Value"; const string SL_Value = "SL_Value"; int OnInit() { ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); OurInterface.Create(0,"Cocoa Trading v5.0",0,180,70,400,200); 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)); TPLabel.Create(0,"TPLabel",0,10,40,50,60); OurInterface.Add(TPLabel); TPLabel.Text("TP:"); TP.Create(0,TP_Value,0,90,40,160,60); OurInterface.Add(TP); TP.Text(string(tp)); SLLabel.Create(0,"SLLabel",0,10,70,50,90); OurInterface.Add(SLLabel); SLLabel.Text("SL:"); SL.Create(0,SL_Value,0,90,70,160,90); OurInterface.Add(SL); SL.Text(string(sl)); OurInterface.Run(); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { EventKillTimer(); // Kill the timer OurInterface.Destroy(reason); } void OnTick() { int MagicBuy =100; int MagicSell = 200; 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 && pricesd && price>cocoa_min_price) { double sell = price; double slsell = sell+sl; // sell+previousclose; double tpsell = sell-tp; 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 == TP_Value) { string volumeText = ObjectGetString(0, TP_Value, OBJPROP_TEXT); tp = StringToDouble(volumeText); ObjectSetString(0, TP_Value, OBJPROP_TEXT, string(tp)); return; } if(sparam == SL_Value) { string volumeText = ObjectGetString(0, SL_Value, OBJPROP_TEXT); sl = StringToDouble(volumeText); ObjectSetString(0, SL_Value, OBJPROP_TEXT, string(sl)); 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); }