MnQInvestmentDevelopment/MnQInvestment/00_StrategyswithSimon/2.ChinaWeekend.mq5

206 lines
6 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 15:08:44 +02:00
#include <trade/trade.mqh>
// DECLARE VARIABELES
input double Lots = 0.1;
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_on_targetprice_SLbuy = 0.01;
input double Difference_on_targetprice_SLsell = 0.01;
input double Difference_on_targetprice_TPbuy = 0.02;
input double Difference_on_targetprice_TPsell = 0.02;
input bool Spread_Average = true;
ulong posTicket;
ulong posTicketBuy;
ulong posTicketSell;
int countalltrades;
int countSStrades;
int countBStrades;
bool OrderdeletableBuy;
bool OrderdeletableSell;
double accountbalancebeginning;
datetime expirytime;
double pricebuy;
double pricesell;
double askit;
double bidit;
double valuespreadav;
ulong lastdeletedorderbuy;
ulong lastdeletedordersell;
datetime lastSignal;
CTrade trade;
bool Dayyycheck;
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
if(Spread_Average == true)
{
askit = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
bidit = SymbolInfoDouble(_Symbol,SYMBOL_BID);
valuespreadav = askit - ((askit - bidit)/2);
askit = valuespreadav;
bidit = valuespreadav;
}
else
{
askit = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
bidit = SymbolInfoDouble(_Symbol,SYMBOL_BID);
}
askit = NormalizeDouble(askit,_Digits);
bidit = NormalizeDouble(bidit,_Digits);
pricebuy = askit + Difference_buy;
pricebuy = NormalizeDouble(pricebuy,_Digits);
pricesell = bidit - Difference_sell;
pricesell = NormalizeDouble(pricesell,_Digits);
double stoplossbuy = askit + Difference_buy - Difference_on_targetprice_SLbuy;
stoplossbuy = NormalizeDouble(stoplossbuy,_Digits);
double stoplosssell = bidit - Difference_sell + Difference_on_targetprice_SLsell;
stoplosssell = NormalizeDouble(stoplosssell,_Digits);
double takepbuy = askit + Difference_buy + Difference_on_targetprice_TPbuy;
takepbuy = NormalizeDouble(takepbuy,_Digits);
double takepsell = bidit - Difference_sell - Difference_on_targetprice_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(ClosTime);
Print(expirytime);
Print("-----------------------------------------------------------------------------------"
"\nMoin Moin! Es ist Zeit Geld zu verdienen... Kurswert heute Abend:"
"\n ASK: ",askit,
"\n BID: ",bidit);
Print("BSTrades: ", countBStrades,
"\n SSTrades: ", countSStrades,
"\n Alltrades: ", countalltrades);
// 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;
countBStrades = countBStrades + 1;
countalltrades = countBStrades + countSStrades;
Print("BSTrades: ", countBStrades,
"\n SSTrades: ", countSStrades,
"\n Alltrades: ", countalltrades);
}
else if(ExecutedOrder == posTicketSell && posTicketBuy != lastdeletedorderbuy)
{
trade.OrderDelete(posTicketBuy);
lastdeletedorderbuy = posTicketBuy;
countSStrades = countSStrades+ 1;
countalltrades = countBStrades + countSStrades;
Print("BSTrades: ", countBStrades,
"\n SSTrades: ", countSStrades,
"\n Alltrades: ", countalltrades);
}
}
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);
}