Kod: Zaznacz cały
//+------------------------------------------------------------------+
//| Ichimoku Marek.mq4 |
//| Marek
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Marek"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(60);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
bool checkTradeExited(int OrderTicketNumber){
for(int trade=OrdersHistoryTotal()-1;trade>=0;trade--)
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_HISTORY)){
if(OrderTicket()==OrderTicketNumber)
{
return true;
}
}
}
return false;
}
int ticket = 0;
int takeProfitValue = 100;
int stopLossValue = 50;
void OnTick()
{
RefreshRates();
double minstoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
double tenkan_sen = iIchimoku(NULL,0,9,26,52,MODE_TENKANSEN,0);
double kijun_sen = iIchimoku(NULL,0,9,26,52,MODE_KIJUNSEN,0);
if(kijun_sen == tenkan_sen){
int ticketNumber = MathRand();
double tenkan_sen_before = iIchimoku(NULL,0,9,26,52,MODE_TENKANSEN,2);
double kijun_sen_before = iIchimoku(NULL,0,9,26,52,MODE_KIJUNSEN,2);
if(tenkan_sen_before > kijun_sen_before){
double stoploss = NormalizeDouble(Bid-stopLossValue*Point,Digits);
double takeprofit = NormalizeDouble(Bid+takeProfitValue*Point,Digits);
if (stoploss < minstoplevel) stoploss = minstoplevel;
if (takeprofit < minstoplevel) takeprofit = minstoplevel;
if (AccountFreeMarginCheck(Symbol(), OP_BUY, 1) > 0){
if(!ticket){
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,stoploss,takeprofit,"My order",ticketNumber,0,clrGreen);
}else if(checkTradeExited(ticketNumber)){
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,stoploss,takeprofit,"My order",ticketNumber,0,clrGreen);
}
}
}else{
double stoploss = NormalizeDouble(Ask+stopLossValue*Point,Digits);
double takeprofit = NormalizeDouble(Ask-takeProfitValue*Point,Digits);
if (stoploss < minstoplevel) stoploss = minstoplevel;
if (takeprofit < minstoplevel) takeprofit = minstoplevel;
if (AccountFreeMarginCheck(Symbol(), OP_SELL, 1) > 0){
if(!ticket){
ticket=OrderSend(Symbol(),OP_SELL,1,Bid,3,stoploss,takeprofit,"My order",ticketNumber,0,clrGreen);
}else if(checkTradeExited(ticketNumber)){
ticket=OrderSend(Symbol(),OP_BUY,1,Bid,3,stoploss,takeprofit,"My order",ticketNumber,0,clrGreen);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
}
//+------------------------------------------------------------------+
//| Tester function |
//+------------------------------------------------------------------+
double OnTester()
{
//---
double ret=0.0;
//---
//---
return(ret);
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
}
//+------------------------------------------------------------------+