Created
October 30, 2021 04:49
-
-
Save zielu92/4fa8d5bd212767ec9891d3a85b7cedce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+------------------------------------------------------------------+ | |
//| LCD.mq5 | | |
//| Copyright 2021, mzielinski.pl | | |
//| https://www.mzielinski.pl | | |
//+------------------------------------------------------------------+ | |
#property copyright "Copyright 2021, mzielinski.pl" | |
#property link "https://www.mzielinski.pl" | |
#property version "1.00" | |
enum ENUM_LCD { | |
LCD2004,LCD1602 | |
}; | |
input int rsiPeriod = 10; | |
input int rsiMinimumValue = 50; | |
input int emaPeriod = 10; | |
input string espIP = "192.168.1.48"; | |
input ENUM_LCD lcdType=0; | |
input int refreshInMiliseconds = 2000; | |
//+------------------------------------------------------------------+ | |
//| Expert initialization function | | |
//+------------------------------------------------------------------+ | |
int OnInit() | |
{ | |
return(INIT_SUCCEEDED); | |
} | |
//+------------------------------------------------------------------+ | |
//| Expert deinitialization function | | |
//+------------------------------------------------------------------+ | |
void OnDeinit(const int reason) | |
{ | |
} | |
//+------------------------------------------------------------------+ | |
//| Expert tick function | | |
//+------------------------------------------------------------------+ | |
void OnTick() | |
{ | |
string comment = ""; | |
//RSI | |
double rsiArray[]; | |
int rsi = iRSI(_Symbol,_Period,rsiPeriod,PRICE_CLOSE); | |
ArraySetAsSeries(rsiArray,true); | |
CopyBuffer(rsi,0,0,3,rsiArray); | |
int rsiValue = rsiArray[0]; | |
string rsiCondition = CheckBelowOrAbove(rsiMinimumValue,rsiValue); | |
comment = "RSI: "+rsiValue+" "+rsiCondition; | |
// | |
double ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),Digits()); | |
//EMA | |
double emaArray[]; | |
double ema =iMA(_Symbol,_Period,emaPeriod,0,MODE_EMA,PRICE_CLOSE); | |
ArraySetAsSeries(emaArray,true); | |
CopyBuffer(ema,0,0,3,emaArray); | |
double emaValue = NormalizeDouble(emaArray[0],Digits()); | |
string emaCondition = CheckBelowOrAbove(ask,emaValue); | |
comment = comment + "\nEMA: "+emaValue+ " "+emaCondition; | |
Display(rsiValue,rsiCondition,emaCondition); | |
Comment(comment); | |
} | |
string CheckBelowOrAbove(double value, double indicator) { | |
string result = ""; | |
if(value<=indicator) { | |
result= "buy"; | |
} else { | |
result="sell"; | |
} | |
return result; | |
} | |
string TotalProfit() { | |
double profit = 0; | |
int i = PositionsTotal(); | |
while(i-->0) { | |
ulong position_ticket = PositionGetTicket(i); | |
PositionSelectByTicket(position_ticket); | |
profit = profit + PositionGetDouble(POSITION_PROFIT); | |
} | |
profit = NormalizeDouble(profit,2); | |
return DoubleToString(profit,2); | |
} | |
string HistoryTotalProfit() { | |
double profit = 0; | |
HistorySelect(TimeCurrent() - (TimeCurrent()%86400),TimeCurrent()); | |
int i = HistoryDealsTotal(); | |
while(i-->0) { | |
ulong ticket=HistoryDealGetTicket(i); | |
profit = profit + (HistoryDealGetDouble(ticket,DEAL_PROFIT)+HistoryDealGetDouble(ticket,DEAL_SWAP)); | |
} | |
profit = NormalizeDouble(profit,2); | |
return DoubleToString(profit,2); | |
} | |
void Display(int rsi, string rsiCondition, string emaCondition) { | |
Request(0,"RSI "+rsi+" "+rsiCondition); | |
Request(1,"EMA "+emaCondition); | |
if(lcdType==1) { | |
Sleep(refreshInMiliseconds); | |
Request(0,"Positions "+PositionsTotal()); | |
Request(1,"Profit "+TotalProfit()); | |
} else { | |
Request(2,"Today Profit "+HistoryTotalProfit()); | |
Request(3,"Profit "+TotalProfit()); | |
} | |
Sleep(refreshInMiliseconds); | |
} | |
void Request(int line, string text) { | |
string url = "http://"+espIP+"/line/"+line+"/text/"+text; | |
char post[], result[]; | |
string cookie=NULL,headers; | |
ResetLastError(); | |
int res = WebRequest("GET",url,NULL,NULL,500,post,0,result,headers); | |
if(res==-1) { | |
MessageBox("Add the address '"+url+"' to the list of allowed URLs","Error",MB_ICONINFORMATION); | |
} else { | |
if(res==200) { | |
Print("ok"); | |
} else { | |
PrintFormat("Error code: %d",url,res); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment