#include // DECLARE VARIABELES input double Lots = 0.1; input int TpPoints = 1000; input int SlPoints = 5000; input double Desired_Profit = 0.2; input string Opentime = "22:55:30"; input string ClosTime = "03:35"; input double Difference_buy = 0.01; input double Difference_sell = 0.01; input double Difference_SLbuy = 0.01; input double Difference_SLsell = 0.01; input double Difference_TPbuy = 0.02; input double Difference_TPsell = 0.02; ulong posTicket; ulong posTicketBuy; ulong posTicketSell; bool OrderdeletableBuy; bool OrderdeletableSell; double accountbalancebeginning; datetime expirytime; double pricebuy; double pricesell; double askit; double bidit; ulong lastdeletedorderbuy; ulong lastdeletedordersell; datetime lastSignal; CTrade trade; int OnInit(){ accountbalancebeginning = AccountInfoDouble(ACCOUNT_BALANCE); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } // IMPORTANT FUNCTION void OnTick(){ // CONVERT INPUT TIME, UPDATE IT TO CURRENT DAY datetime opentime = StringToTime(Opentime); datetime closetime = StringToTime(ClosTime); datetime expirytime = closetime + (24 * 60 * 60); double accountbalance = AccountInfoDouble(ACCOUNT_BALANCE); double accountprofit = AccountInfoDouble(ACCOUNT_PROFIT); double accountequity = AccountInfoDouble(ACCOUNT_EQUITY); // ---- EXECUTE TRADES --- OPENING TRADE ON TIME if(lastSignal != opentime && TimeCurrent() > opentime) { lastSignal = opentime; //CALCULATING TRADE ORDER VALUES askit = SymbolInfoDouble(_Symbol,SYMBOL_ASK); bidit = SymbolInfoDouble(_Symbol,SYMBOL_BID); askit = NormalizeDouble(askit,_Digits); pricebuy = askit + Difference_buy; pricebuy = NormalizeDouble(pricebuy,_Digits); pricesell = askit - Difference_sell; pricesell = NormalizeDouble(pricesell,_Digits); double stoplossbuy = askit + Difference_buy - Difference_SLbuy; stoplossbuy = NormalizeDouble(stoplossbuy,_Digits); double stoplosssell = bidit - Difference_sell + Difference_SLsell; stoplosssell = NormalizeDouble(stoplosssell,_Digits); double takepbuy = askit + Difference_buy + Difference_TPbuy; takepbuy = NormalizeDouble(takepbuy,_Digits); double takepsell = bidit - Difference_sell - Difference_TPsell; takepsell = NormalizeDouble(takepsell,_Digits); //DYNAMIC CALCULATION OF LOT SIZE //double lotsizebuy = (accountbalance * 0.2) / 146; //double lotsizesell = (accountbalance * 0.2) / 146; //DYNAMIC CALCULATION OF LOT SIZE V2 //double lotsizegeneral = (accountbalance * Desired_Profit) / 146; //lotsizegeneral = NormalizeDouble(lotsizegeneral,1); //CALCULATION OF EXPIREIY DATE datetime expirytime = closetime + (24 * 60 * 60); Print("-----------------------------------------------------------------------------------" "\nMoin Moin! Es ist Zeit Geld zu verdienen... Kurswert heute Abend:" "\n ASK: ",askit, "\n BID: ",bidit); // EXECUTE BUY if(trade.BuyStop(100.0,pricebuy,_Symbol,stoplossbuy,takepbuy,ORDER_TIME_SPECIFIED,expirytime,"Evening Buytrade")) { posTicketBuy = trade.ResultOrder(); OrderdeletableBuy = true; } // EXECUTE SELL if(trade.SellStop(100.0,pricesell,_Symbol,stoplosssell,takepsell,ORDER_TIME_SPECIFIED,expirytime,"Evening Selltrade")) { posTicketSell = trade.ResultOrder(); OrderdeletableSell = true; } } //--- CLOSING TRADES --- ON CONDITION if (PositionsTotal() > 0) { ulong ExecutedOrder = PositionGetTicket(0); if(ExecutedOrder == posTicketBuy && posTicketSell != lastdeletedordersell) { trade.OrderDelete(posTicketSell); lastdeletedordersell = posTicketSell; } else if(ExecutedOrder == posTicketSell && posTicketBuy != lastdeletedorderbuy) { trade.OrderDelete(posTicketBuy); lastdeletedorderbuy = posTicketBuy; } } accountprofit = accountequity - accountbalancebeginning; accountprofit = NormalizeDouble(accountprofit,2); // DISPLAY OF VALUES ON CHART Comment("\nServertime: ", TimeCurrent(), "\nOpentime: ", opentime, "\nClosetime: ", closetime, "\nCurrenttime: ",TimeCurrent(), "\nProfit: ",accountprofit, "\nEquity: ",accountequity); }